sendto Function

C

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

Description

This function is used to send outgoing data on a socket. The destination address is given by to and tolen. Both datagram and stream sockets are supported.

Preconditions

The socket() function should be called.

Parameters

ParametersDescription
sSocket descriptor returned from previous call to socket().
bufApplication data buffer containing data to transmit.
lenLength of data in bytes.
flagsMessage flags (currently this is not supported).
toOptional pointer to the sockaddr structure containing the destination address. If NULL, the currently bound remote port and IP address are used as the destination.
tolenLength of the sockaddr structure.

Returns

  • If the function is successful, the number of bytes sent is returned.

  • A return value of SOCKET_ERROR (-1) indicates an error and errno is set accordingly.

Remarks

None.