Packing/unpacking binary data in C - doubles, 64 bits

Bruce Labitt bruce.labitt at myfairpoint.net
Tue Sep 8 20:16:55 EDT 2009


The task: Port a server app to C. 

Since the app is both a consumer and producer of binary data, the app 
needs to be able to pack and unpack the binary data.  The server is a 
big-endian machine and the client a little-endian machine, so one can't 
just sleaze out and directly send binary data on the network. 

I wrote both the client and server in python and the app works as 
expected using python's pack and unpack. 

Scouring about the internet, I found a program on:

http://www.beej.us/guide/bgnet/examples/pack2.c

Except it doesn't quite work all the way.  Especially on a 64 bit 
machine.  (Both machines run 64 bit linices.)  My app needs to be able 
to send and receive 32 bit integers, 16 bit integers, and doubles.  It 
would be very nice, but not required to be able to transfer 64 bit integers.

If anyone could try it and offer a suggestion, I'd appreciate it.

Thanks,
Bruce



More information about the gnhlug-discuss mailing list