#include <cafe.h>
#include <cafe/network.h>

typedef u8* amsg;

int SORecvFromEx(int              fd,
                 void            *buffer,
                 int              len,
                 int              flags,
                 struct sockaddr *from,
                 int             *fromlen,
                 amsg             msg,
                 int              msglen


fd Descriptor of socket from which to receive.
buffer Destination buffer.
len Length of the buffer, in bytes. For UDP sockets, len greater than 1478 will cause SO_EMSGSIZE error.
flags Can be ORed from the following values:
  • MSG_OOB........Request out of band data.
  • MSG_PEEK.......Receive without dequeuing the data.
  • MSG_DONTWAIT...Enable non-blocking operation.
  • MSG_IP_RECVTTL.Retrieve received packet's TTL stored in msg. UDP only.
from Source address.
fromlen Initialized to the size of the buffer associated with from; modified with the actual length of the address upon return.
msg Optional destination buffer for ancillary data requested by flags.
msglen Length of msg in bytes. Minimum is sizeof(u8). Maximum is 64.

Return Values

int, returns the number of bytes received. Upon an error, returns -1 and errno is set to the correct value. Returns a 0 when the peer has performed an orderly shutdown.


These are errors generated by the socket layer; additional errors may be generated by the underlying protocol modules. See SOLastError.

SO_ELIBNOTREADY Socket library is not initialized.
SO_ENOMEM Insufficient memory in the stack.
SO_EINVAL Specified argument is invalid.
SO_ENOTCONN The socket is associated with a connection-oriented protocol and has not been connected (see SOConnect and SOAccept ).
SO_ENOTSOCK The argument fd does not refer to a socket.
SO_EWOULDBLOCK The socket is marked non-blocking, and the receive operation would block, or a receive timeout was set, and the timeout expired before data was received.
SO_EMSGSIZE The socket requires that message be received atomically, and len made this impossible. For UDP sockets, len greater than 1478 will cause this error.
SO_EABORTED The operation was aborted. When a socket is closed, operations that are blocked on the socket are aborted.
SO_ENOBUFS Insufficient resources in the stack.
SO_EBUSY Socket resource manager busy processing requests.
SO_EABORTED Indicates the operation was aborted. For example, this error can be returned for calls blocked on a socket after the socket is closed by another thread.
SO_EUNKNOWN Unknown error.
SO_ERANGEINVALID Internal API error, invalid error code.
SO_EAPIERROR Internal API error.
SO_ECONNRESET Connection reset.


SORecvFromEx is identical to SORecvFrom in operation except that SORecvFromEx can return ancillary data via the msg parameter. For example: passing MSG_IP_RECVTTL in the flags parameter will pass back the TTL of the packet received.

SORecvFromEx can return the address from which the message was sent. For connected datagram sockets, SORecvFromEx returns the same address as SOGetPeerName; for stream sockets it does not return the socket address of the sender.

If a RST packet is received on an open connection, SORecvFromEx returns 0.

Do Not Call From

Callbacks Do not call this function from any callback function.
Interrupt handler Do not call this function from any interrupt handler.
Exception handler Do not call this function from any exception handler.

Revision History

2013/12/19 Initial version.