Re: packing a C structure

Quoth bgeer <bgeer@xxxxxxxxxxxx>:

Check out "man perlfunc", then use "/" to search followed by " pack "
with the spaces & without the ".

Or use perldoc -f pack .

Note especially that if you want to put the resulting binary structure
on a network, that you should consider the difference between I (32
bit int) & N (unsigned long in network order).

On a 32-bit Intel, a long & int are the same size - I don't know why
there isn't a specific template character for "unsigned int in network

n and N are 'unsigned 16-bit in network order' and 'unsigned 32-bit in
network order' respectively. Since they're meant for operations where
you are trying to be portable, a format for 'native int in network
order, whatever size it may be' is not likely to be useful. If you care,
$Config{intsize} will tell you the size of C's 'int' and $Config{ivsize}
will tell you the size of perl's integer variables (which will be
different if your perl was built to use 64 bits on a 32bit arch).