[ragel-users] Decoding DNS protocol

Adrian Thurston thurston at complang.org
Fri Jul 16 06:10:33 UTC 2010


I typically don't recommend Ragel for DNS due to it being a binary 
protocol, but it can be done.

With Ragel there are two ways to count things. You can use conditions to 
check for the counters getting down to zero. The advantage of conditions 
is that you can more freely use machines with with embedded conditions 
in the construction of other machines.

The other approach is the one you're taking, which is to count and 
call/return in actions. This is generally easier to program, because it 
more closely resembles standard programming practice. The downside is 
that you lose the ability freely union and you have to be more careful 
with the other operations. The call/return statements are best for high 
level flow control and can get you into a bind when used for the inner 
definitions of a grammar.

All in all, you may find that a hand-written parser for DNS is faster 
and simpler due to all the counting.

-Adrian

Pete Gervais wrote:
> I’m using ragel to decode protocols as a test of its capabilities.
> 
> One of the protocols is DNS.
> 
> This protocol has a fixed set of fields followed by one or more optional 
> fields. The count  of these optional fields are encoded within the fixed 
> data field.
> 
>  
> 
> Would the code below be the best way to do this ?Initial the dnsAnswer 
> section called via fcall dnsAnswer.   It then sequentially processes all 
> fields in the order given. In the last field, 
> dnsAnswerResourceDataField  , it gets the count of the number of answer 
> fields included in the protocol, then perform a series of fgoto’s until 
> the dnsRecordCount is 0 at which time it returns.
> 
>  
> 
>  
> 
> dnsAnswer := (
> 
>                                 dnsAnswerNameField .
> 
>                                 dnsAnswerTypeField .
> 
>                                 dnsAnswerClassField .
> 
>                                 dnsAnswerTimeToLiveField .
> 
>                                 dnsAnswerResourceDataLengthField .
> 
>                                 dnsAnswerResourceDataField  @{ cout << 
> "In dnsAnswer processing" << endl; if (fsm->getdnsAnswerRecordCount() > 
> 0 ) {
> 
>                                                 fsm->dnsAnswerRecordCount--;
> 
>                                                 fgoto dnsAnswer; } else {
> 
>                                                 fret; }
> 
>                 }
> 
>                 );
> 
>  
> 
>  
> 
>  
> 
> Regards,
> 
>  
> 
> Peter J. Gervais
> 
> President, Simtree Information Systems
> 
> 17621 Island Rd,
> 
> RR#2 , Martintown,
> 
> Martintown,Ont
> 
> K0C 1S0
> 
>  
> 
> Business: 613-938-6549
> 
> Cell: 613-864-7370
> 
> E-mail: pgervais at xplornet.com
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> ragel-users mailing list
> ragel-users at complang.org
> http://www.complang.org/mailman/listinfo/ragel-users

_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users



More information about the ragel-users mailing list