ip.h¶
Raw IPv4/IPv6 sock definitions.
-
struct sock_ip
sock_ip_t¶ Type for a raw IPv4/IPv6 sock object.
Note
API implementors:
struct sock_ipneeds to be defined by implementation-specificsock_types.h.
-
int
sock_ip_create(ip.h::sock_ip_t* sock, const sock_ip_ep_t * local, const sock_ip_ep_t * remote, uint8_t proto, uint16_t flags)¶ Creates a new raw IPv4/IPv6 sock object.
Parameters
sock: The resulting sock object. local: Local end point for the sock object. May be NULL. sock.h::sock_ip_ep_t::netifmust either besock.h::SOCK_ADDR_ANY_NETIFor equal tosock.h::sock_ip_ep_t::netifofremoteifremote != NULL. If NULLip.h::sock_ip_send()may bind implicitly.remote: Remote end point for the sock object. May be NULLbut then theremoteparameter ofip.h::sock_ip_send()may not beNULLor it will always error with return value -ENOTCONN. sock_ip_ep_t::port may not be 0 ifremote != NULL.sock.h::sock_ip_ep_t::netifmust either besock.h::SOCK_ADDR_ANY_NETIFor equal tosock.h::sock_ip_ep_t::netifoflocaliflocal != NULL.proto: Protocol to use in the raw IPv4/IPv6 sock object (the protocolheader field in IPv4 and thenext_headerfield in IPv6).flags: Flags for the sock object. See also [sock flags](net_sock_flags). May be 0. Return values
- 0 on success.
- -EADDRINUSE, if
local != NULLandlocalis already used elsewhere - -EAFNOSUPPORT, if
local != NULLorremote != NULLandsock.h::sock_ip_ep_t::familyoflocalorremoteis not supported. - -EINVAL, if
sock.h::sock_ip_ep_t::addrofremoteis an invalid address. - -EINVAL, if
sock.h::sock_ip_ep_t::netifoflocalorremoteare not 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. - -EPROTONOSUPPORT, if
local != NULLorremote != NULLand proto is not supported bysock.h::sock_ip_ep_t::familyoflocalorremote.
-
void
sock_ip_close(ip.h::sock_ip_t* sock)¶ Closes a raw IPv4/IPv6 sock object.
Parameters
sock: A raw IPv4/IPv6 sock object.
-
int
sock_ip_get_local(ip.h::sock_ip_t* sock, sock_ip_ep_t * ep)¶ Gets the local end point of a raw IPv4/IPv6 sock object.
This gets the local end point of a raw IPv4/IPv6 sock object. Note that this might not be the same end point you added in
ip.h::sock_ip_create(), but an end point more suitable for the implementation. Examples for this might be that ifsock.h::sock_ip_ep_t::netifis given inip.h::sock_ip_create(), the implementation might choose to return the address on this interface thesockis bound to inep'ssock.h::sock_ip_ep_t::addr.Parameters
sock: A raw IPv4/IPv6 sock object. ep: The local end point. Return values
- 0 on success.
- -EADDRNOTAVAIL, when
sockhas no end point bound to it.
-
int
sock_ip_get_remote(ip.h::sock_ip_t* sock, sock_ip_ep_t * ep)¶ Gets the remote end point of a UDP sock object.
This gets the remote end point of a raw IPv4/IPv6 sock object. Note that this might not be the same end point you added in
ip.h::sock_ip_create(), but an end point more suitable for the implementation. Examples for this might be that ifsock.h::sock_ip_ep_t::netifis given inip.h::sock_ip_create(), the implementation might choose to return the address on this interface thesockis bound to inep'ssock.h::sock_ip_ep_t::addr.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_ip_recv(ip.h::sock_ip_t* sock, void * data,msp430_types.h::size_tmax_len, uint32_t timeout, sock_ip_ep_t * remote)¶ Receives a message over IPv4/IPv6 from 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 whileip.h::sock_ip_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_ip_send(ip.h::sock_ip_t* sock, const void * data,msp430_types.h::size_tlen, uint8_t proto, const sock_ip_ep_t * remote)¶ Sends a message over IPv4/IPv6 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.proto: Protocol to use in the packet sent, in case sock == NULL. Ifsock != NULLthis parameter will be ignored.remote: Remote end point for the sent data. May be NULL, ifsockhas a remote end point.sock.h::sock_ip_ep_t::familymay be AF_UNSPEC, if local end point ofsockprovides this information.Return values
- The number of bytes sent on success.
- -EAFNOSUPPORT, if
remote != NULLandsock.h::sock_ip_ep_t::familyofremoteis != AF_UNSPEC and not supported. - -EINVAL, if
sock.h::sock_ip_ep_t::addrofremoteis an invalid address. - -EINVAL, if
sock.h::sock_ip_ep_t::netifofremoteis not a valid interface or contradicts the local interface ofsock. - -EHOSTUNREACH, if
remoteor remote end point ofsockis not reachable. - -ENOMEM, if no memory was available to send
data. - -ENOTCONN, if
remote == NULL, butsockhas no remote end point. - -EPROTOTYPE, if
sock == NULLandprotois not bysock.h::sock_ip_ep_t::familyofremote.