I'd like to send some double precision floating point numbers over the network. (standard C, standard sockets) There is no htond or ntohd to convert the data to and from network byte order. What should I do? I have a couple solutions in my head but I'd like to know what the common practice is.
(I'd also like to know what is the common practice for sending 64bit ints, like gint64 values used by gstreamer)
edit: This is one solution I thought of. I presume it works for any size integers, but is it correct for doubles?
void swap_if_necessary (void* buff, int buff_len)
{
uint32_t foo = 1;
if ( htonl(foo) != foo )
{
char* to_swap = (char*)buff;
int i;
for (i = 0; i < buff_len/2; i++)
{
char swap_buff = to_swap[i];
to_swap[i] = to_swap[buff_len -1 -i];
to_swap[buff_len -1 -i] = swap_buff;
}
}
}