P
Peter Wyzl
I have binary data representing an IP address (among other things) in $data.
(part of a libpcap file, read in binary mode)
The 4 bytes of $data repreenting the IP address start at offset 26. I am
looking for a good solution to represent this in dotted quad. Since there
are many repetitions of this manipulation, efficiency is important.
What I have so far is:
(assume $sourceip has been pre-declared and $data contains binary data)
$sourceip = join '.', map {ord}(split '', substr $data,26,4,);
Shorter solutions are also of interest to me.
BTW, this is on a windows platform so the data is in little endian order in
the headers, and network order in the raw IP packet (no reason to make life
simple...) This IP is therefore stored in network order. I am
contemplating a solution using unpack, but am still learing all the
different templates, and am unsure whether it is more efficient than substr
(or enough so to be worth trying). I have not yet benchmarked a regex
solution, having a hunch that it would be less efficient.
(part of a libpcap file, read in binary mode)
The 4 bytes of $data repreenting the IP address start at offset 26. I am
looking for a good solution to represent this in dotted quad. Since there
are many repetitions of this manipulation, efficiency is important.
What I have so far is:
(assume $sourceip has been pre-declared and $data contains binary data)
$sourceip = join '.', map {ord}(split '', substr $data,26,4,);
Shorter solutions are also of interest to me.
BTW, this is on a windows platform so the data is in little endian order in
the headers, and network order in the raw IP packet (no reason to make life
simple...) This IP is therefore stored in network order. I am
contemplating a solution using unpack, but am still learing all the
different templates, and am unsure whether it is more efficient than substr
(or enough so to be worth trying). I have not yet benchmarked a regex
solution, having a hunch that it would be less efficient.