The recvfrom() call is used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented.
The recvfrom() call is used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented.
Synopsis
#include <sys/types.h>
#include <sys/socket.h>
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
Description
sockfd -- the socket file descriptor to read from
buf -- The pointer to the memory location where the data has to be stored
len -- The length of the data to be read
flags -- Various flags to modify the socket file descriptor
src_addr -- The memory location where the source address of the message will be filled
addrlen -- addrlen is a value-result argument, which the caller should initialize
before the call to the size of the buffer associated with src_addr, and modified on
return to indicate the actual size of the source address.
Return Value
recvfrom() return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown.
Errors
There are some standard errors generated by the socket layer. Additional errors may be generated and returned from the underlying protocol modules. For the complete list, see the manual pages.