perl -- pack
PERL's pack function is frustrating the heck out of me.
I need to build a UDP packet from the ethernet layer on up. I've found examples online for the IP and UDP layers, even so it seems like voodoo (I'm clearly missing something).
what should I be using for my template string???
for example: 0x0800 is the protocol number for an ip packet.
my $proto = 0x0800;
#my $template = 'hh' #this is wrong and I have no idea what would be right.
$packed_proto = pack($template, $proto);
I know how many bytes each part of my header should be (this is well documented...) and I know what values I want for each part of the header, but I can't figure out a sane method to convert between the two. Its clearly choosing the right template for the pack function.
(Or if any one can suggest a perl module that *works* and can help me pack the ethernet layer I would appreciate it.)
|