Just to throw a wrench in the works ;-)
The binary data is packed in Network bit order, won't pulling it out using C2 not respect that?
So i tried this:
my ($data) = unpack "N", $foo;
my ($ver, $hlen) = (vec($data,0,4), vec($data,1,4));
my $tos = vec($data, 1, 8);
my $len = vec($data, 1, 16);
Which returned completely un-expected results. Is it not possible to use vec on data pulled using "N"? (yes, i know it can be more compact, split up for readability.) | [reply] [d/l] |
| [reply] |
My understanding of the way IP headers are formed is that $ver should equal 4 when all is said and done. So, while grabbing it all in one swoop solves the repeating data I am still not obtaining the expected results.
If you have 4 bits that represent, say, an integer how do you unpack to a usable value? | [reply] |
| [reply] [d/l] [select] |
Thank you for your help thus far. I am now getting the expected results for $tos and $len, however, $ver and $hlen are still not right.
first, your "vec($ver_hlen, 4, 0)" brings up "illegal number of bits", due to 0 but being a power of 2 between 1 and 32 (from perldoc -f vec).
I am having trouble understanding exactly what the bits field is. Is that the number of bits that you want to read in? if so, wouldn't:
my ($ver, $hlen) = (vec($ver_hlen, 0, 4), vec($ver_hlen, 4, 4));
be better? Using the the changes i made above, I get unexpected results for the values for $ver and $hlen, which leads me to believe I am wrong. | [reply] [d/l] |