Loading...
Searching...
No Matches
UDP sock API

Sock submodule for UDP. More...

Detailed Description

Sock submodule for UDP.

How To Use

First you need to include a module that implements this API in your application's Makefile. For example the implementation for GNRC is called gnrc_sock_udp.

A Simple UDP Echo Server

#include <stdio.h>
#include "net/sock/udp.h"
uint8_t buf[128];
int main(void)
{
sock_udp_t sock;
local.port = 12345;
if (sock_udp_create(&sock, &local, NULL, 0) < 0) {
puts("Error creating UDP sock");
return 1;
}
while (1) {
sock_udp_ep_t remote;
ssize_t res;
if ((res = sock_udp_recv(&sock, buf, sizeof(buf), SOCK_NO_TIMEOUT,
&remote)) >= 0) {
puts("Received a message");
if (sock_udp_send(&sock, buf, res, &remote) < 0) {
puts("Error sending reply");
}
}
}
return 0;
}
int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local, const sock_udp_ep_t *remote, uint16_t flags)
Creates a new UDP sock object.
static ssize_t sock_udp_send(sock_udp_t *sock, const void *data, size_t len, const sock_udp_ep_t *remote)
Sends a UDP message to remote end point.
Definition udp.h:754
static ssize_t sock_udp_recv(sock_udp_t *sock, void *data, size_t max_len, uint32_t timeout, sock_udp_ep_t *remote)
Receives a UDP message from a remote end point.
Definition udp.h:530
#define SOCK_IPV6_EP_ANY
Address to bind to any IPv6 address.
Definition sock.h:166
#define SOCK_NO_TIMEOUT
Special value meaning "wait forever" (don't timeout)
Definition sock.h:173
UDP sock definitions.
stdio wrapper to extend the C libs stdio
Common IP-based transport layer end point.
Definition sock.h:215
uint16_t port
transport layer port (in host byte order)
Definition sock.h:247
UDP sock type.
Definition sock_types.h:128

Above you see a simple UDP echo server. Don't forget to also include the IPv6 module of your networking implementation (e.g. gnrc_ipv6_default for Generic (GNRC) network stack GNRC) and at least one network device.

After including the header file for UDP sock, we create some buffer space buf to store the data received by the server:

#include "net/sock/udp.h"
uint8_t buf[128];

To be able to listen for incoming packets we bind the sock by setting a local end point with a port (12345 in this case).

We then proceed to create the sock. It is bound to local and thus listens for UDP packets with destination port 12345. Since we don't need any further configuration we set the flags to 0. In case of an error we stop the program:

local.port = 12345;
if (sock_udp_create(&sock, &local, NULL, 0) < 0) {
puts("Error creating UDP sock");
return 1;
}

The application then waits indefinitely for an incoming message in buf from remote. If we want to timeout this wait period we could alternatively set the timeout parameter of sock_udp_recv() to a value != SOCK_NO_TIMEOUT. If an error occurs on receive we just ignore it and continue looping.

If we receive a message we use its remote to reply. In case of an error on send we print an according message:

while (1) {
sock_udp_ep_t remote;
ssize_t res;
if ((res = sock_udp_recv(&sock, buf, sizeof(buf), SOCK_NO_TIMEOUT,
&remote)) >= 0) {
puts("Received a message");
if (sock_udp_send(&sock, buf, res, &remote) < 0) {
puts("Error sending reply");
}
}
}

A Simple UDP Echo Client

There are two kinds of clients. Those that do expect a reply and those who don't. A client that does not require a reply is very simple to implement in one line:

res = sock_udp_send(NULL, data, data_len, &remote);

With data being the data sent, data_len the length of data and remote the remote end point the packet that is is to be sent.

To see some other capabilities we look at a more complex example in form of the counter of the echo server above:

#include <stdio.h>
#include "net/af.h"
#include "net/protnum.h"
#include "net/ipv6/addr.h"
#include "net/sock/udp.h"
#include "xtimer.h"
uint8_t buf[7];
int main(void)
{
sock_udp_t sock;
local.port = 0xabcd;
if (sock_udp_create(&sock, &local, NULL, 0) < 0) {
puts("Error creating UDP sock");
return 1;
}
while (1) {
sock_udp_ep_t remote = { .family = AF_INET6 };
ssize_t res;
remote.port = 12345;
if (sock_udp_send(&sock, "Hello!", sizeof("Hello!"), &remote) < 0) {
puts("Error sending message");
return 1;
}
if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 1 * US_PER_SEC,
NULL)) < 0) {
if (res == -ETIMEDOUT) {
puts("Timed out");
}
else {
puts("Error receiving message");
}
}
else {
printf("Received message: \"");
for (int i = 0; i < res; i++) {
printf("%c", buf[i]);
}
printf("\"\n");
}
}
return 0;
}
Global UNIX address family definitions.
#define AF_INET6
internetwork address family with IPv6: UDP, TCP, etc.
Definition af.h:40
#define ETIMEDOUT
Connection timed out.
Definition errno.h:147
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
Definition stdio.h:60
#define IPV6_ADDR_MCAST_SCP_LINK_LOCAL
link-local scope
Definition addr.h:236
static void ipv6_addr_set_all_nodes_multicast(ipv6_addr_t *addr, unsigned int scope)
Sets addr dynamically to an all nodes multicast IPv6 address (ff0S::1, where S is the scope).
Definition addr.h:662
void sock_udp_close(sock_udp_t *sock)
Closes a UDP sock object.
#define US_PER_SEC
The number of microseconds per second.
Definition time_units.h:85
static void xtimer_sleep(uint32_t seconds)
Pause the execution of a thread for some seconds.
Definitions for IPv6 addresses.
Protocol number definitions.
int family
family of sock_ip_ep_t::addr
Definition sock.h:221
union _sock_tl_ep::@386 addr
address
uint8_t ipv6[16]
IPv6 address mode.
Definition sock.h:230
Data type to represent an IPv6 address.
Definition addr.h:72
xtimer interface definitions

Again: Don't forget to also include the IPv6 module of your networking implementation (e.g. gnrc_ipv6_default for GNRC) and at least one network device.

We first create again a sock with a local end point bound to any IPv6 address and some port. Note that we also could specify the remote here and not use it with sock_udp_send().

local.port = 0xabcd;
if (sock_udp_create(&sock, &local, NULL, 0) < 0) {
puts("Error creating UDP sock");
return 1;
}

We then create a remote end point with the link-local all nodes multicast address (ff02::1) and port 12345 and send a "Hello!" message to that end point.

sock_udp_ep_t remote = { .family = AF_INET6 };
ssize_t res;
remote.port = 12345;
if (sock_udp_send(&sock, "Hello!", sizeof("Hello!"), &remote) < 0) {
puts("Error sending message");
return 1;
}

We then wait a second for a reply and print it when it is received.

if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 1 * US_PER_SEC,
NULL)) < 0) {
if (res == -ETIMEDOUT) {
puts("Timed out");
}
else {
puts("Error receiving message");
}
}
else {
printf("Received message: \"");
for (int i = 0; i < res; i++) {
printf("%c", buf[i]);
}
printf("\"\n");
}

Finally, we wait a second before sending out the next "Hello!" with xtimer_sleep(1).

Files

file  udp.h
 UDP sock definitions.
 

Data Structures

struct  sock_udp_aux_rx_t
 Auxiliary data provided when receiving using an UDP sock object. More...
 
struct  sock_udp_aux_tx_t
 Auxiliary data provided when sending using an UDP sock object. More...
 

Typedefs

typedef struct _sock_tl_ep sock_udp_ep_t
 An end point for a UDP sock object.
 
typedef struct sock_udp sock_udp_t
 Type for a UDP sock object.
 

Functions

int sock_udp_create (sock_udp_t *sock, const sock_udp_ep_t *local, const sock_udp_ep_t *remote, uint16_t flags)
 Creates a new UDP sock object.
 
void sock_udp_close (sock_udp_t *sock)
 Closes a UDP sock object.
 
int sock_udp_get_local (sock_udp_t *sock, sock_udp_ep_t *ep)
 Gets the local end point of a UDP sock object.
 
int sock_udp_get_remote (sock_udp_t *sock, sock_udp_ep_t *ep)
 Gets the remote end point of a UDP sock object.
 
ssize_t sock_udp_recv_aux (sock_udp_t *sock, void *data, size_t max_len, uint32_t timeout, sock_udp_ep_t *remote, sock_udp_aux_rx_t *aux)
 Receives a UDP message from a remote end point.
 
static ssize_t sock_udp_recv (sock_udp_t *sock, void *data, size_t max_len, uint32_t timeout, sock_udp_ep_t *remote)
 Receives a UDP message from a remote end point.
 
ssize_t sock_udp_recv_buf_aux (sock_udp_t *sock, void **data, void **buf_ctx, uint32_t timeout, sock_udp_ep_t *remote, sock_udp_aux_rx_t *aux)
 Provides stack-internal buffer space containing a UDP message from a remote end point.
 
static ssize_t sock_udp_recv_buf (sock_udp_t *sock, void **data, void **buf_ctx, uint32_t timeout, sock_udp_ep_t *remote)
 Provides stack-internal buffer space containing a UDP message from a remote end point.
 
ssize_t sock_udp_sendv_aux (sock_udp_t *sock, const iolist_t *snips, const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux)
 Sends a UDP message to remote end point with non-continous payload.
 
static ssize_t sock_udp_send_aux (sock_udp_t *sock, const void *data, size_t len, const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux)
 Sends a UDP message to remote end point.
 
static ssize_t sock_udp_send (sock_udp_t *sock, const void *data, size_t len, const sock_udp_ep_t *remote)
 Sends a UDP message to remote end point.
 
static ssize_t sock_udp_sendv (sock_udp_t *sock, const iolist_t *snips, const sock_udp_ep_t *remote)
 Sends a UDP message to remote end point with non-continous payload.
 
static bool sock_udp_ep_is_multicast (const sock_udp_ep_t *ep)
 Checks if the IP address of an endpoint is multicast.
 
static bool sock_udp_ep_is_v6 (const sock_udp_ep_t *ep)
 Checks if the IP address of an endpoint is an IPv6 address.
 

Typedef Documentation

◆ sock_udp_ep_t

typedef struct _sock_tl_ep sock_udp_ep_t

An end point for a UDP sock object.

Definition at line 293 of file udp.h.

◆ sock_udp_t

typedef struct sock_udp sock_udp_t

Type for a UDP sock object.

Note
API implementers: struct sock_udp needs to be defined by implementation-specific sock_types.h.

Definition at line 301 of file udp.h.

Function Documentation

◆ sock_udp_close()

void sock_udp_close ( sock_udp_t sock)

Closes a UDP sock object.

Precondition
(sock != NULL)
Parameters
[in]sockA UDP sock object.

◆ sock_udp_create()

int sock_udp_create ( sock_udp_t sock,
const sock_udp_ep_t local,
const sock_udp_ep_t remote,
uint16_t  flags 
)

Creates a new UDP sock object.

Precondition
(sock != NULL)
(remote == NULL) || (remote->port != 0)
Warning
If you create a socket you are responsible for receiving messages sent to it by calling sock_udp_recv. Otherwise, the packet queue of the sock may congest until the socket is closed. If you only want to send without receiving, use sock_udp_send instead with sock set to NULL.
Parameters
[out]sockThe resulting sock object.
[in]localLocal end point for the sock object. May be NULL. sock_udp_ep_t::netif must either be SOCK_ADDR_ANY_NETIF or equal to sock_udp_ep_t::netif of remote if remote != NULL. If NULL sock_udp_send() may bind implicitly. sock_udp_ep_t::port may also be 0 to bind the sock to an ephemeral port.
[in]remoteRemote end point for the sock object. May be NULL but then the remote parameter of sock_udp_send() may not be NULL or it will always error with return value -ENOTCONN. sock_udp_ep_t::port must not be 0 if remote != NULL. sock_udp_ep_t::netif must either be SOCK_ADDR_ANY_NETIF or equal to sock_udp_ep_t::netif of local if local != NULL.
[in]flagsFlags for the sock object. See also sock flags. May be 0.
Returns
0 on success.
-EADDRINUSE, if local != NULL and local is already used elsewhere or if local->port == 0 but the pool of ephemeral ports is depleted
-EAFNOSUPPORT, if local != NULL or remote != NULL and sock_udp_ep_t::family of local or remote is not supported.
-EINVAL, if sock_udp_ep_t::addr of remote is an invalid address.
-EINVAL, if sock_udp_ep_t::netif of local or remote are not a valid interfaces or contradict each other (i.e. (local->netif != remote->netif) && ((local->netif != SOCK_ADDR_ANY_NETIF) || (remote->netif != SOCK_ADDR_ANY_NETIF)) if neither is NULL).
-ENOMEM, if not enough resources can be provided for sock to be created.

◆ sock_udp_ep_is_multicast()

static bool sock_udp_ep_is_multicast ( const sock_udp_ep_t ep)
inlinestatic

Checks if the IP address of an endpoint is multicast.

Parameters
[in]epend point to check
Returns
true if end point is multicast

Definition at line 807 of file udp.h.

◆ sock_udp_ep_is_v6()

static bool sock_udp_ep_is_v6 ( const sock_udp_ep_t ep)
inlinestatic

Checks if the IP address of an endpoint is an IPv6 address.

Parameters
[in]epend point to check
Returns
true if end point is IPv6

Definition at line 832 of file udp.h.

◆ sock_udp_get_local()

int sock_udp_get_local ( sock_udp_t sock,
sock_udp_ep_t ep 
)

Gets the local end point of a UDP sock object.

Precondition
(sock != NULL) && (ep != NULL)
Parameters
[in]sockA UDP sock object.
[out]epThe local end point.
Returns
0 on success.
-EADDRNOTAVAIL, when sock has no local end point.

◆ sock_udp_get_remote()

int sock_udp_get_remote ( sock_udp_t sock,
sock_udp_ep_t ep 
)

Gets the remote end point of a UDP sock object.

Precondition
(sock != NULL) && (ep != NULL)
Parameters
[in]sockA UDP sock object.
[out]epThe remote end point.
Returns
0 on success.
-ENOTCONN, when sock has no remote end point bound to it.

◆ sock_udp_recv()

static ssize_t sock_udp_recv ( sock_udp_t sock,
void *  data,
size_t  max_len,
uint32_t  timeout,
sock_udp_ep_t remote 
)
inlinestatic

Receives a UDP message from a remote end point.

Precondition
(sock != NULL) && (data != NULL) && (max_len > 0)
Parameters
[in]sockA UDP sock object.
[out]dataPointer where the received data should be stored.
[in]max_lenMaximum space available at data.
[in]timeoutTimeout for receive in microseconds. If 0 and no data is available, the function returns immediately. May be SOCK_NO_TIMEOUT for no timeout (wait until data is available).
[out]remoteRemote end point of the received data. May be NULL, if it is not required by the application.
Note
Function blocks if no packet is currently waiting.
Returns
The number of bytes received on success.
0, if no received data is available, but everything is in order.
-EADDRNOTAVAIL, if local of sock is not given.
-EAGAIN, if timeout is 0 and no data is available.
-EINVAL, if remote is invalid or sock is not properly initialized (or closed while sock_udp_recv() blocks).
-ENOBUFS, if buffer space is not large enough to store received data.
-ENOMEM, if no memory was available to receive data.
-EPROTO, if source address of received packet did not equal the remote of sock.
-ETIMEDOUT, if timeout expired.

Definition at line 530 of file udp.h.

◆ sock_udp_recv_aux()

ssize_t sock_udp_recv_aux ( sock_udp_t sock,
void *  data,
size_t  max_len,
uint32_t  timeout,
sock_udp_ep_t remote,
sock_udp_aux_rx_t aux 
)

Receives a UDP message from a remote end point.

Precondition
(sock != NULL) && (data != NULL) && (max_len > 0)
Parameters
[in]sockA UDP sock object.
[out]dataPointer where the received data should be stored.
[in]max_lenMaximum space available at data.
[in]timeoutTimeout for receive in microseconds. If 0 and no data is available, the function returns immediately. May be SOCK_NO_TIMEOUT for no timeout (wait until data is available).
[out]remoteRemote end point of the received data. May be NULL, if it is not required by the application.
[out]auxAuxiliary data about the received datagram. May be NULL, if it is not required by the application.
Note
Function blocks if no packet is currently waiting.
Returns
The number of bytes received on success.
0, if no received data is available, but everything is in order.
-EADDRNOTAVAIL, if local of sock is not given.
-EAGAIN, if timeout is 0 and no data is available.
-EINVAL, if remote is invalid or sock is not properly initialized (or closed while sock_udp_recv() blocks).
-ENOBUFS, if buffer space is not large enough to store received data.
-ENOMEM, if no memory was available to receive data.
-EPROTO, if source address of received packet did not equal the remote of sock.
-ETIMEDOUT, if timeout expired.

◆ sock_udp_recv_buf()

static ssize_t sock_udp_recv_buf ( sock_udp_t sock,
void **  data,
void **  buf_ctx,
uint32_t  timeout,
sock_udp_ep_t remote 
)
inlinestatic

Provides stack-internal buffer space containing a UDP message from a remote end point.

Precondition
(sock != NULL) && (data != NULL) && (buf_ctx != NULL)
Parameters
[in]sockA UDP sock object.
[out]dataPointer to a stack-internal buffer space containing the received data.
[in,out]buf_ctxStack-internal buffer context. If it points to a NULL pointer, the stack returns a new buffer space for a new packet. If it does not point to a NULL pointer, an existing context is assumed to get a next segment in a buffer.
[in]timeoutTimeout for receive in microseconds. If 0 and no data is available, the function returns immediately. May be SOCK_NO_TIMEOUT for no timeout (wait until data is available).
[out]remoteRemote end point of the received data. May be NULL, if it is not required by the application.
Warning
This feature is experimental!
This function is quite new, not implemented for all stacks yet, and may be subject to sudden API changes. Do not use in production if this is unacceptable.
Note
Function blocks if no packet is currently waiting.
Returns
The number of bytes received on success. May not be the complete payload. Continue calling with the returned buf_ctx to get more buffers until result is 0 or an error.
0, if no received data is available, but everything is in order. If buf_ctx was provided, it was released.
-EADDRNOTAVAIL, if local of sock is not given.
-EAGAIN, if timeout is 0 and no data is available.
-EINVAL, if remote is invalid or sock is not properly initialized (or closed while sock_udp_recv() blocks).
-ENOMEM, if no memory was available to receive data.
-EPROTO, if source address of received packet did not equal the remote of sock.
-ETIMEDOUT, if timeout expired.

Definition at line 627 of file udp.h.

◆ sock_udp_recv_buf_aux()

ssize_t sock_udp_recv_buf_aux ( sock_udp_t sock,
void **  data,
void **  buf_ctx,
uint32_t  timeout,
sock_udp_ep_t remote,
sock_udp_aux_rx_t aux 
)

Provides stack-internal buffer space containing a UDP message from a remote end point.

Precondition
(sock != NULL) && (data != NULL) && (buf_ctx != NULL)
Parameters
[in]sockA UDP sock object.
[out]dataPointer to a stack-internal buffer space containing the received data.
[in,out]buf_ctxStack-internal buffer context. If it points to a NULL pointer, the stack returns a new buffer space for a new packet. If it does not point to a NULL pointer, an existing context is assumed to get a next segment in a buffer.
[in]timeoutTimeout for receive in microseconds. If 0 and no data is available, the function returns immediately. May be SOCK_NO_TIMEOUT for no timeout (wait until data is available).
[out]remoteRemote end point of the received data. May be NULL, if it is not required by the application.
[out]auxAuxiliary data about the received datagram. May be NULL, if it is not required by the application.
Warning
This feature is experimental!
This function is quite new, not implemented for all stacks yet, and may be subject to sudden API changes. Do not use in production if this is unacceptable.
Note
Function blocks if no packet is currently waiting.
Returns
The number of bytes received on success. May not be the complete payload. Continue calling with the returned buf_ctx to get more buffers until result is 0 or an error.
0, if no received data is available, but everything is in order. If buf_ctx was provided, it was released.
-EADDRNOTAVAIL, if local of sock is not given.
-EAGAIN, if timeout is 0 and no data is available.
-EINVAL, if remote is invalid or sock is not properly initialized (or closed while sock_udp_recv() blocks).
-ENOMEM, if no memory was available to receive data.
-EPROTO, if source address of received packet did not equal the remote of sock.
-ETIMEDOUT, if timeout expired.

◆ sock_udp_send()

static ssize_t sock_udp_send ( sock_udp_t sock,
const void *  data,
size_t  len,
const sock_udp_ep_t remote 
)
inlinestatic

Sends a UDP message to remote end point.

Precondition
((sock != NULL || remote != NULL)) && (if (len != 0): (data != NULL))
Parameters
[in]sockA UDP sock object. May be NULL. A sensible local end point should be selected by the implementation in that case.
[in]dataPointer where the received data should be stored. May be NULL if len == 0.
[in]lenMaximum space available at data.
[in]remoteRemote end point for the sent data. May be NULL, if sock has a remote end point. sock_udp_ep_t::family may be AF_UNSPEC, if local end point of sock provides this information. sock_udp_ep_t::port may not be 0.
Returns
The number of bytes sent on success.
-EADDRINUSE, if sock has no local end-point or was NULL and the pool of available ephemeral ports is depleted.
-EAFNOSUPPORT, if remote != NULL and sock_udp_ep_t::family of remote is != AF_UNSPEC and not supported.
-EHOSTUNREACH, if remote or remote end point of sock is not reachable.
-EINVAL, if sock_udp_ep_t::addr of remote is an invalid address.
-EINVAL, if sock_udp_ep_t::netif of remote is not a valid interface or contradicts the given local interface (i.e. neither the local end point of sock nor remote are assigned to SOCK_ADDR_ANY_NETIF but are nevertheless different.
-EINVAL, if sock_udp_ep_t::port of remote is 0.
-ENOMEM, if no memory was available to send data.
-ENOTCONN, if remote == NULL, but sock has no remote end point.

Definition at line 754 of file udp.h.

◆ sock_udp_send_aux()

static ssize_t sock_udp_send_aux ( sock_udp_t sock,
const void *  data,
size_t  len,
const sock_udp_ep_t remote,
sock_udp_aux_tx_t aux 
)
inlinestatic

Sends a UDP message to remote end point.

Precondition
((sock != NULL || remote != NULL)) && (if (len != 0): (data != NULL))
Parameters
[in]sockA UDP sock object. May be NULL. A sensible local end point should be selected by the implementation in that case.
[in]dataPointer where the received data should be stored. May be NULL if len == 0.
[in]lenMaximum space available at data.
[in]remoteRemote end point for the sent data. May be NULL, if sock has a remote end point. sock_udp_ep_t::family may be AF_UNSPEC, if local end point of sock provides this information. sock_udp_ep_t::port may not be 0.
[out]auxAuxiliary data about the transmission. May be NULL, if it is not required by the application.
Returns
The number of bytes sent on success.
-EADDRINUSE, if sock has no local end-point or was NULL and the pool of available ephemeral ports is depleted.
-EAFNOSUPPORT, if remote != NULL and sock_udp_ep_t::family of remote is != AF_UNSPEC and not supported.
-EHOSTUNREACH, if remote or remote end point of sock is not reachable.
-EINVAL, if sock_udp_ep_t::addr of remote is an invalid address.
-EINVAL, if sock_udp_ep_t::netif of remote is not a valid interface or contradicts the given local interface (i.e. neither the local end point of sock nor remote are assigned to SOCK_ADDR_ANY_NETIF but are nevertheless different.
-EINVAL, if sock_udp_ep_t::port of remote is 0.
-ENOMEM, if no memory was available to send data.
-ENOTCONN, if remote == NULL, but sock has no remote end point.

Definition at line 707 of file udp.h.

◆ sock_udp_sendv()

static ssize_t sock_udp_sendv ( sock_udp_t sock,
const iolist_t snips,
const sock_udp_ep_t remote 
)
inlinestatic

Sends a UDP message to remote end point with non-continous payload.

Precondition
((sock != NULL || remote != NULL))
Parameters
[in]sockA UDP sock object. May be NULL. A sensible local end point should be selected by the implementation in that case.
[in]snipsList of payload chunks, will be processed in order. May be NULL.
[in]remoteRemote end point for the sent data. May be NULL, if sock has a remote end point. sock_udp_ep_t::family may be AF_UNSPEC, if local end point of sock provides this information. sock_udp_ep_t::port may not be 0.
Returns
The number of bytes sent on success.
-EADDRINUSE, if sock has no local end-point or was NULL and the pool of available ephemeral ports is depleted.
-EAFNOSUPPORT, if remote != NULL and sock_udp_ep_t::family of remote is != AF_UNSPEC and not supported.
-EHOSTUNREACH, if remote or remote end point of sock is not reachable.
-EINVAL, if sock_udp_ep_t::addr of remote is an invalid address.
-EINVAL, if sock_udp_ep_t::netif of remote is not a valid interface or contradicts the given local interface (i.e. neither the local end point of sock nor remote are assigned to SOCK_ADDR_ANY_NETIF but are nevertheless different.
-EINVAL, if sock_udp_ep_t::port of remote is 0.
-ENOMEM, if no memory was available to send data.
-ENOTCONN, if remote == NULL, but sock has no remote end point.

Definition at line 793 of file udp.h.

◆ sock_udp_sendv_aux()

ssize_t sock_udp_sendv_aux ( sock_udp_t sock,
const iolist_t snips,
const sock_udp_ep_t remote,
sock_udp_aux_tx_t aux 
)

Sends a UDP message to remote end point with non-continous payload.

Precondition
((sock != NULL || remote != NULL))
Parameters
[in]sockA UDP sock object. May be NULL. A sensible local end point should be selected by the implementation in that case.
[in]snipsList of payload chunks, will be processed in order. May be NULL.
[in]remoteRemote end point for the sent data. May be NULL, if sock has a remote end point. sock_udp_ep_t::family may be AF_UNSPEC, if local end point of sock provides this information. sock_udp_ep_t::port may not be 0.
[out]auxAuxiliary data about the transmission. May be NULL, if it is not required by the application.
Returns
The number of bytes sent on success.
-EADDRINUSE, if sock has no local end-point or was NULL and the pool of available ephemeral ports is depleted.
-EAFNOSUPPORT, if remote != NULL and sock_udp_ep_t::family of remote is != AF_UNSPEC and not supported.
-EHOSTUNREACH, if remote or remote end point of sock is not reachable.
-EINVAL, if sock_udp_ep_t::addr of remote is an invalid address.
-EINVAL, if sock_udp_ep_t::netif of remote is not a valid interface or contradicts the given local interface (i.e. neither the local end point of sock nor remote are assigned to SOCK_ADDR_ANY_NETIF but are nevertheless different.
-EINVAL, if sock_udp_ep_t::port of remote is 0.
-ENOMEM, if no memory was available to send data.
-ENOTCONN, if remote == NULL, but sock has no remote end point.