So I am trying to send a message to a client using the sendto() function.
The sendto() function's prototype is this:
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen);
But I would like to send a structure as the second argument. Is it possible for me to do that? Or does buf have to be a string?
EDIT: You see, I have to be able to send this:
"A message consists of "HEADER" followed by "PAYLOAD".
Your message header should consist of the following:
uint8_t version; /* must be 1. If you receive anything else, discard*/
uint8_t ttl; /* must be 1. If you receive anything else, discard*/
uint16_t payload_length; /* bytes following the header */
uint32_t account_identifier; /* digits of your account name */
uint32_t source_address; /* unused for now, set to 0 and ignore. */
uint32_t destination_address; /* unused for now, set to 0 and ignore. */
uint16_t checksum; /* unused for now, set to 0 and ignore. */
uint16_t protocol; /* must be 1. If you receive anything else, discard*/"
And payload is a text string like "Hello" or something.
I feel like the only way for me to send the header would be to send a struct of all that info. Right?