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
order".

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).

Ben

.



Relevant Pages

  • Re: Two 3825s wont talk to each other
    ... DDR TXCRC Int Mask 1 DDR TXClk Loss Int Mask 1 ... Network Interrupt Enable: ... Last clearing of "show interface" counters never ... input packets with dribble condition detected ...
    (comp.dcom.sys.cisco)
  • Strange Characters during recv()
    ... #ifdef DEBUG ... "The CodeGurus network was not becoming what I wanted it to be, ... and people who have hosting with the network will continue to keep that ...
    (comp.os.linux.development.apps)
  • Strange Characters during recv()
    ... #ifdef DEBUG ... "The CodeGurus network was not becoming what I wanted it to be, ... and people who have hosting with the network will continue to keep that ...
    (comp.unix.programmer)
  • Re: Difficulties with endianness
    ... > I'm trying to write a network device driver, ... does the same to a 4 byte int. ... you could, using bitfields is quite touchy, because the compiler doesn't ... unsigned int count: 14; ...
    (comp.os.linux.development.system)
  • Re: Long integer to bytes?
    ... I'm attempting to implement a well defined protocol which has been ... output the data you mask the low order 4 bytes into an int. ... directly to the network using DataOutputStream.writeInt. ...
    (comp.lang.java.help)