gtpc1m47Transmission Control Protocol/Internet Protocol

recvfrom -- Receive Data on Connected/Unconnected Socket

The recvfrom function receives data on a socket with descriptor s and stores it in a buffer.

Format

#include  <socket.h>
int       recvfrom(int s,
                   char *buf,
                   int len,
                   int flags,
                   struct sockaddr *name,
                   int *namelen);

s
The socket descriptor.

buf
Pointer to the buffer that receives the data.

len
Length, in bytes, of the buffer pointed to by the buf parameter. The maximum number of bytes that can be received is 32 768.

flags
Must be set to 0 or one or more of the following flags. If you specify more than one flag, use the logical OR operator (|) to separate them:

MSG_OOB
Reads any out-of-band data on the socket.

MSG_PEEK
Peeks at the data present on the socket; the data is returned but not consumed so a later receive operation sees the same data.

name
This is a pointer to a socket address from which data is received.

namelen
Pointer to the size of name in bytes.

Normal Return

If successful, the function returns the length, in bytes, of the message or datagram.

If an end-of-file condition is received or the connection is closed, 0 is returned.

Error Return

A return code equal to -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.

Note:
Unless otherwise stated in the description, the following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

SOCFAULT
Using buf and len would result in an attempt to access a protected address space.

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

SOCWOULDBLOCK
The s parameter is in nonblocking mode and no data is available to read.

SOCNOBUFS
There is not enough space available to process the function call. This error code is returned only for TCP/IP offload support.

SOCNOTCONN
A stream socket was used to issue the recvfrom function, and the socket was not connected.

EIBMIUCVERR
An error occurred while the function call was sent to the offload device. This error code is returned only for TCP/IP offload support.

E1052STATE
The socket was closed because the system was in or cycling down to 1052 state.

EINACT
All offload devices associated with the socket descriptor have been disconnected. The socket is closed. This error code is returned only for TCP/IP offload support.

EINACTWS
An offload device associated with the socket descriptor has been disconnected. The socket is still available. This error code is returned only for TCP/IP offload support.

ESYSTEMERROR
A system error has occurred and closed the socket.

SOCTIMEDOUT
The operation timed out. The socket is still available. This error code is returned only for TCP/IP native stack support.

SOCINVAL
The value of the namelen parameter is not valid, the MSG_OOB option was specified for a socket that is not a stream socket, or the MSG_OOB option was specified, but out-of-band data is queued inline for this socket. This error code is returned only for TCP/IP native stack support.

Programming Considerations

Examples

In the following example, the application issues a recvfrom to receive a message but does not request the address of the source of the message.

int bytes_recv;
int server_sock;
char data_recv[256];

·
·
·
bytes_recv = recvfrom(server_sock, data_recv, sizeof(data_recv), 0, (struct sockaddr *) 0, (int *) 0);

Related Information