Jump to main content

##

# 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

Parameters | Description
--- | ---
s | Socket descriptor returned from previous call to socket().
buf | Application data buffer containing data to transmit.
len | Length of data in bytes.
flags | Message flags (currently this is not supported).
to | Optional pointer to the sockaddr structure containing the destination address. If NULL, the currently bound remote port and IP address are used as the destination.
tolen | Length 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.