At Fri, 30 Sep 2005 07:58:22 +1000, Telford Tendys wrote:
> How about writing a network protocol stack. You get a packet and all
> you know about it is that here is a block of memory. You then have
> to figure out what sort of packet it is, how long it is and what
> structure to give it. C handles this very nicely with pointers to
> structures that can be cast into whatever you need.

Since you dared me, here's some (untested) perl5 code that will parse
a TCP header, including network byte order conversions and bitfields:

 my ($source, $dest, $seq, $ack_seq,
     $off, undef, undef, $urg, $ack, $psh, $rst, $syn, $fin,
     $window, $check, $urg_ptr) = unpack 'n2 N2 C B8 n3', $tcpdata;

 $off &= 0x0F;


(this is fun ;)

-- 
 - Gus
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to