sendto

sendto transmits a message on a socket. This function may be used on connected or unconnected sockets.

Syntax

int sendto(
    __in SOCKET s,
    __in const char *buf,
    __in int len,
    __in int flags,
    __in const struct sockaddr *to,
    __in int tolen
);

Parameters

s

Socket descriptor for a connected socket.

buf

A pointer to a character buffer that holds the data to send.

len

An integer containing the size, in bytes, of the character buffer buf.

flags

A set of flags arguments that is logical OR of one or more of the following.

Flag

Description

MSG_DONTROUTE

Send without using routing tables.

MSG_OOB

Process urgent data, SOCK_STREAM only.

MSG_FDBROADCAST*

Send a full duplex broadcast. This flag causes a broadcast packet to be received by this node also. The default is not to receive your own broadcasts.


to

Pointer to the sockaddr structure of the target host.

tolen

Size of the sockaddr structure associated with to.

Return Values

The number of bytes sent if the function succeeds, SOCKET_ERROR if the function fails

Use WSAGetLastError to retrieve a specific error code.

Remarks

The send and sendto functions are used to transmit a message to another socket. The send function can only be used when the socket is in a connected state. The sendto function can be used at any time, and includes the additional parameters to, which specifies a target address and tolen, which specifies the address size.

The Windows implementation of sendto will ignore the to and tolen parameters when the socket is in a connected state, making it equivalent to the send function. The RTX implementation is more similar to the BSD standard functionality of sendto, which requires to and tolen parameters to be null when the socket is in a connected state.

IntervalZero.com | Support | Give Feedback