Search code examples
csocketssendto

why the sendto function needs the third parameter, in socket programming


I was new to socket program. When learning the sendto function, as the prototype:

ssize_t sendto(int socket, const void *message, size_t length,
                int flags, const struct sockaddr *dest_addr,
                socklen_t dest_len);

I get to know that the "message" has contain the target IP, and the dest_addr argument also specifies the target IP address. Is there other usage of the dest_addr argument?


Solution

  • The message does not contain the destination address, only the payload bytes.

    Unless you are using raw sockets... And you should not do that if you are new to socket programming.