I'm not sure longs are necessarily all 4 bytes... however, I managed to make this work:
Code:
#include <stdio.h>
#include <string.h>
int main(void) {
unsigned __int32 foo;
unsigned char bar[4] = { 0xFF, 0x00, 0x00, 0x00 };
memcpy(&foo,bar,4);
printf("%u",foo);
return 0;
}
The output for me was 255... the first thing you should notice about that is the bytes are(or may be) in the reverse order than you might expect. I'd suppose this has to do with the endian of my computer. You can probably fix this by making sure you convert the byte order with one of the socket functions like htonl(). Other than that, it seems to work fine. I wouldn't be surprised if there were some other quirks I don't notice here... I also wouldn't be surprised if the output was different on your computer. Someone will be able to enlighten you further.