Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: Need help with (un)pack templates

by gmargo (Hermit)
on Dec 20, 2009 at 14:39 UTC ( [id://813629]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Need help with (un)pack templates
in thread Need help with (un)pack templates

It's pretty well spelled out in the pack documentation. C for unsigned char (byte), n for unsigned 16-bit short in network order, N for 32-bit long in network order, a for "arbitrary binary data".

Don't be confused by the 32-bit CCCC's, since an IP address is 4 8-bit numbers, not a 32-bit number.

  • Comment on Re^5: Need help with (un)pack templates

Replies are listed 'Best First'.
Re^6: Need help with (un)pack templates
by ikegami (Patriarch) on Dec 20, 2009 at 17:25 UTC

    Don't be confused by the 32-bit CCCC's, since an IP address is 4 8-bit numbers, not a 32-bit number.

    It's actually 32 opaque bits. The dotted form is just a representation. The separation into bytes in completely arbitrary. But if you're going to display in that form, it might be useful to extract the IP as 4 bytes.

Re^6: Need help with (un)pack templates
by keszler (Priest) on Dec 20, 2009 at 15:06 UTC
    an IP address is 4 8-bit numbers, not a 32-bit number
    s/is/is normally represented as/;

    $ host perlmonks.org perlmonks.org has address 66.39.54.27 $ perl -le 'print ((66 * 256**3)+(39 * 256**2)+(54 * 256)+27);' 1109866011 $ perl -le 'print unpack('N',(gethostbyname("perlmonks.org"))[4]);' 1109866011
    Many web browsers accept the decimal value of the IP address: http://1109866011/

      s/is normally represented as/is encoded in an IP header as/; # :-)

Re^6: Need help with (un)pack templates
by Subop (Acolyte) on Dec 20, 2009 at 15:47 UTC
    Now it's making more sense... Thanks for the help, gmargo!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://813629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found