pub unsafe extern "C" fn sock_udp_create(
sock: *mut sock_udp_t,
local: *const sock_udp_ep_t,
remote: *const sock_udp_ep_t,
flags: u16,
) -> c_int
Expand description
@brief Creates a new UDP sock object
@pre (sock != NULL)
@pre (remote == NULL) || (remote->port != 0)
@warning If you create a socket you are responsible for receiving messages
sent to it by calling @ref sock_udp_recv.
Otherwise, the packet queue of the @p sock may congest until the
socket is closed.
If you only want to send without receiving, use @ref sock_udp_send
instead with sock
set to NULL.
@param[out] sock The resulting sock object.
@param[in] local Local end point for the sock object.
May be NULL.
sock_udp_ep_t::netif must either be
@ref SOCK_ADDR_ANY_NETIF or equal to
sock_udp_ep_t::netif of @p remote if remote != NULL
.
If NULL @ref sock_udp_send() may bind implicitly.
sock_udp_ep_t::port may also be 0 to bind the sock
to
an ephemeral port.
@param[in] remote Remote end point for the sock object.
May be NULL
but then the remote
parameter of
@ref 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
@ref SOCK_ADDR_ANY_NETIF or equal to sock_udp_ep_t::netif
of @p local if local != NULL
.
@param[in] flags Flags for the sock object. See also
[sock flags](@ref net_sock_flags).
May be 0.
@return 0 on success.
@return -EADDRINUSE, if local != NULL
and @p local is already used
elsewhere or if local->port == 0
but the pool of ephemeral ports
is depleted
@return -EAFNOSUPPORT, if local != NULL
or remote != NULL
and
sock_udp_ep_t::family of @p local or @p remote is not supported.
@return -EINVAL, if sock_udp_ep_t::addr of @p remote is an invalid address.
@return -EINVAL, if sock_udp_ep_t::netif of @p local or @p 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
).
@return -ENOMEM, if not enough resources can be provided for sock
to be
created.