gtpc1m4cTransmission Control Protocol/Internet Protocol

sendto -- Send Data on an Unconnected Socket

The sendto function sends data on unconnected sockets.

Format

#include    <socket.h>
int         sendto(int s,
                   char *msg,
                   int len,
                   int flags;
                   struct sockaddr *to,
                   int tolen);

s
The socket descriptor.

msg
Pointer to the buffer containing the message to transmit.

len
Length of the message pointed to by the msg parameter.

When using TCP/IP offload support:

When using TCP/IP native stack support:

flags
Set to 0 the following value:

MSG_DONTROUTE
The SO_DONTROUTE option is turned on for the duration of the operation. This is usually used only by diagnostic or routing programs.

to
Address of the target.

tolen
Size of the address pointed to by the to parameter.

Normal Return

If it succeeds, sendto returns the number of characters sent.

Error Return

A return code equal to -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors. The return value of this function when used with datagram sockets does not imply failure to deliver.

Note:
Unless otherwise stated in the description, the following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

SOCDESTADDRREQ
Destination address is required.

SOCFAULT
Using msg and len results in an attempt to copy the address into a protected address space. This error code is returned only for TCP/IP offload support.

SOCINVAL
The value of the tolen parameter is not the size of a valid address for the specified address family.

SOCMSGSIZE
The message was too large to be sent. This error code is returned only for TCP/IP native stack support.

SOCNOBUFS
There is no buffer space available to send the message.

SOCNOTCONN
A stream socket was used to issue the sendto function, and the socket was not connected.

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

SOCWOULDBLOCK
The s parameter is in nonblocking mode and no buffer space is available to hold the message to be sent.

EIBMIUCVERR
An error occurred while the message was sent to the offload device. This error code is returned only for TCP/IP offload support.

E1052STATE
The socket was closed because the system was in or cycling down to 1052 state.

EINACT
All offload devices associated with the socket descriptor have been disconnected. The socket is closed. This error code is returned only for TCP/IP offload support.

EINACTWS
An offload device associated with the socket descriptor has been disconnected. The socket is still available. This error code is returned only for TCP/IP offload support.

ESYSTEMERROR
A system error has occurred and closed the socket.

SOCTIMEDOUT
The operation timed out. The socket is still available. This error code is returned only for TCP/IP native stack support.

Programming Considerations

Examples

In the following example, 100 bytes are sent to an application with IP address 129.5.24.1 and port number 5001.

#include <socket.h>

·
·
·
int bytes_sent; int server_sock; char send_msg[100]; struct sockaddr_in to_addr;
·
·
·
to_addr.sin_family = AF_INET; to_addr.sin_port = 5001; to_addr.sin_addr.s_addr = inet_addr("129.5.24.1"); bytes_sent = sendto(server_sock, send_msg, sizeof(send_msg), 0, (struct sockaddr *)&to_addr, sizeof(to_addr));
·
·
·

Related Information