NAME
recvfrom - Receives messages from sockets
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
int recvfrom(
int socket,
char *buffer,
int length,
int flags,
struct sockaddr *address,
int *address_len) ;
PARAMETERS
socket
Specifies the socket file descriptor.
buffer
Specifies a pointer to the buffer to which the message
should be written.
length
Specifies the length in bytes of the buffer pointed to
by the buffer parameter.
flags
Points to a value that controls message reception. The
parameter to control message reception is formed by the
logical OR of one or more of the following values:
MSG_PEEK Peeks at the incoming message.
MSG_OOB Processes out-of-band data.
address
Points to a sockaddr structure, the format of which is
determined by the domain and by the behavior requested
for the socket. The sockaddr structure is an overlay
for a sockaddr_in, sockaddr_un, or sockaddr_ns struc-
ture, depending on which of the supported address fami-
lies is active. If the compile-time option
_SOCKADDR_LEN is defined before the sys/socket.h header
file is included, the sockaddr structure takes 4.4BSD
behavior, with a field for specifying the length of the
socket address. Otherwise, the default 4.3BSD sockaddr
structure is used, with the length of the socket
address assumed to be 14 bytes or less.
If _SOCKADDR_LEN is defined, the 4.3BSD sockaddr
structure is defined with the name osockaddr.
address_len
Specifies the length of the sockaddr structure pointed
to by the address parameter.
DESCRIPTION
The recvfrom() function permits an application program to
receive messages from unconnected sockets. It is normally
applied to unconnected sockets because it includes parame-
ters that permit a calling program to retrieve the source
endpoint of received data.
To obtain the source address of the message, specify a
nonzero value for the address parameter. The recvfrom()
function is called with the address_len parameter set to the
size of the buffer specified by the address parameter. On
return, this function modifies the address_len parameter to
the actual size in bytes of the address specified by the
address parameter. The recvfrom() function returns the
length of the message written to the buffer pointed to by
the buffer parameter. When a message is too long for the
specified buffer, excess bytes may be truncated depending on
the type of socket that issued the message, and depending on
which flags are set with the flags parameter.
When no message is available at the socket specified by the
socket parameter, the recvfrom() function waits for a mes-
sage to arrive, unless the socket is nonblocking. When the
socket is nonblocking, errno is set to [EWOULDBLOCK].
RETURN VALUES
Upon successful completion, the byte length of the written
message is returned. Otherwise, a value of -1 is returned
and errno is set to indicate the error.
ERRORS
If the recvfrom() function fails, errno may be set to one of
the following values:
[EBADF] The socket parameter is not a valid file descrip-
tor.
[ENOTSOCK]
The socket parameter refers to a file, not a
socket.
[EWOULDBLOCK]
The socket is nonblocking; no data is ready to be
received.
[EFAULT] A valid message buffer was not specified.
Nonexistent or protected address space is speci-
fied for the message buffer.
RELATED INFORMATION
Functions: recv(2), recvmsg(2), send(2), sendmsg(2),
sendto(2), select(2), shutdown(2), socket(2), read(2),
write(2)
Acknowledgement and Disclaimer