sendto | |
Prototype: |
#include <sys/socket.h> #include <resolv.h> int sendto(int sockfd, char* msg, int len, int options, struct sockaddr *addr, int addr_len); |
General Description: | Send a message to a specific destination without connecting. Typically, you use this system call for UDP and raw sockets. Using this call for TCP sockets is Transaction TCP (T/TCP). (Linux, however, does not yet support T/TCP.) |
Return Value: | Returns the number of bytes sent or -1 if an error occurred. |
Parameters | |
sockfd | The socket descriptor. |
msg | The data to send. |
len | The number of bytes to send. |
options | Message-controlling flags (same as send()). |
addr | The address of the destination. |
addr_len | The size of the destination data body. |
Possible Errors | (same as send()) |
Examples | |
int sockfd; struct sockaddr_in addr; if ( (sd = socket(PF_INET, SOCK_DGRAM, 0)) < 0 ) perror("socket"); bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(DEST_PORT); inet_aton(DEST_ADDR, &addr.sin_addr); if ( send(sockfd, buffer, msg_len, 0, &addr, sizeof(addr)) < 0 ) perror("sendto"); |