sock/udp.h¶
UDP sock definitions.
-
struct _sock_tl_ep
sock_udp_ep_t¶ An end point for a UDP sock object.
-
struct sock_udp
sock_udp_t¶ Type for a UDP sock object.
Note
API implementors:
struct sock_udpneeds to be defined by implementation-specificsock_types.h.
-
int
sock_udp_create(sock/udp.h::sock_udp_t* sock, constsock/udp.h::sock_udp_ep_t* local, constsock/udp.h::sock_udp_ep_t* remote, uint16_t flags)¶ Creates a new UDP sock object.
Parameters
sock: The resulting sock object. local: Local end point for the sock object. May be NULL. sock.h::_sock_tl_ep::netifmust either besock.h::SOCK_ADDR_ANY_NETIFor equal tosock.h::_sock_tl_ep::netifofremoteifremote != NULL. If NULLsock/udp.h::sock_udp_send()may bind implicitly.sock.h::_sock_tl_ep::portmay also be 0 to bind thesockto an ephemeral port.remote: Remote end point for the sock object. May be NULLbut then theremoteparameter ofsock/udp.h::sock_udp_send()may not beNULLor it will always error with return value -ENOTCONN.sock.h::_sock_tl_ep::portmust not be 0 ifremote != NULL.sock.h::_sock_tl_ep::netifmust either besock.h::SOCK_ADDR_ANY_NETIFor equal tosock.h::_sock_tl_ep::netifoflocaliflocal != NULL.flags: Flags for the sock object. See also . May be 0. Return values
- 0 on success.
- -EADDRINUSE, if
local != NULLandlocalis already used elsewhere or iflocal->port == 0but the pool of ephemeral ports is depleted - -EAFNOSUPPORT, if
local != NULLorremote != NULLandsock.h::_sock_tl_ep::familyoflocalorremoteis not supported. - -EINVAL, if
sock.h::_sock_tl_ep::addrofremoteis an invalid address. - -EINVAL, if
sock.h::_sock_tl_ep::netifoflocalorremoteare 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 isNULL). @return -ENOMEM, if not enough resources can be provided forsock` to be created.
-
void
sock_udp_close(sock/udp.h::sock_udp_t* sock)¶ Closes a UDP sock object.
Parameters
sock: A UDP sock object.
-
int
sock_udp_get_local(sock/udp.h::sock_udp_t* sock,sock/udp.h::sock_udp_ep_t* ep)¶ Gets the local end point of a UDP sock object.
Parameters
sock: A UDP sock object. ep: The local end point. Return values
- 0 on success.
- -EADDRNOTAVAIL, when
sockhas no local end point.
-
int
sock_udp_get_remote(sock/udp.h::sock_udp_t* sock,sock/udp.h::sock_udp_ep_t* ep)¶ Gets the remote end point of a UDP sock object.
Parameters
sock: A UDP sock object. ep: The remote end point. Return values
- 0 on success.
- -ENOTCONN, when
sockhas no remote end point bound to it.
-
msp430_types.h::ssize_tsock_udp_recv(sock/udp.h::sock_udp_t* sock, void * data,msp430_types.h::size_tmax_len, uint32_t timeout,sock/udp.h::sock_udp_ep_t* remote)¶ Receives a UDP message from a remote end point.
Parameters
sock: A raw IPv4/IPv6 sock object. data: Pointer where the received data should be stored. max_len: Maximum space available at data.timeout: Timeout for receive in microseconds. If 0 and no data is available, the function returns immediately. May be sock.h::SOCK_NO_TIMEOUTfor no timeout (wait until data is available).remote: Remote 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.
Return values
- The number of bytes received on success.
- 0, if no received data is available, but everything is in order.
- -EADDRNOTAVAIL, if local of
sockis not given. - -EAGAIN, if
timeoutis0and no data is available. - -EINVAL, if
remoteis invalid orsockis not properly initialized (or closed whilesock/udp.h::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
timeoutexpired.
-
msp430_types.h::ssize_tsock_udp_send(sock/udp.h::sock_udp_t* sock, const void * data,msp430_types.h::size_tlen, constsock/udp.h::sock_udp_ep_t* remote)¶ Sends a UDP message to remote end point.
Parameters
sock: A raw IPv4/IPv6 sock object. May be NULL. A sensible local end point should be selected by the implementation in that case.data: Pointer where the received data should be stored. May be NULLiflen == 0.len: Maximum space available at data.remote: Remote end point for the sent data. May be NULL, ifsockhas a remote end point.sock.h::_sock_tl_ep::familymay be AF_UNSPEC, if local end point ofsockprovides this information.sock.h::_sock_tl_ep::portmay not be 0.Return values
- The number of bytes sent on success.
- -EADDRINUSE, if
sockhas no local end-point or wasNULLand the pool of available ephemeral ports is depleted. - -EAFNOSUPPORT, if
remote != NULLandsock.h::_sock_tl_ep::familyofremoteis != AF_UNSPEC and not supported. - -EHOSTUNREACH, if
remoteor remote end point ofsockis not reachable. - -EINVAL, if
sock.h::_sock_tl_ep::addrofremoteis an invalid address. - -EINVAL, if
sock.h::_sock_tl_ep::netifofremoteis not a valid interface or contradicts the given local interface (i.e. neither the local end point ofsocknor remote are assigned toSOCK_ADDR_ANY_NETIFbut are nevertheless different. - -EINVAL, if
sock.h::_sock_tl_ep::portofremoteis 0. - -ENOMEM, if no memory was available to send
data. - -ENOTCONN, if
remote == NULL, butsockhas no remote end point.