I want to send a file on a socket, and need to pass its length in the first four bytes.
Here is what I want to do in C:
struct { int lenght; //four bytes char msg[40]; }dataBuf; write(fd, &databuf, sizeof(dataBuf)) How do I push an integer onto a socket, so it receives it as an integer at other end, not as an ASCII value?
I don't want to hardcode it like "\x04\X03" and I tried to do it with pack(L*). That only works with array and I don't have a way to break my four byte integer into a four byte array.