BSD Sockets Interface Programmer's Guide
Chapter 7 157
Using UNIX Domain Datagram Sockets
Sending and Receiving Messages
Function result: number of bytes actually received if recvfrom succeeds,
-1 if recvfrom call fails.
Example: struct sockaddr_un fromaddr;
int fromlen;
...
count = recvfrom(s, msg, sizeof(msg), 0,
&fromaddr, &fromlen);
recvfrom blocks until there is a message to be received.
No more than len bytes of data are returned. The entire message is read
in one recvfrom, recvmsg, recv, or read operation. If the message is
too long for the receive buffer, the excess data are discarded. Because
only one message can be returned in a recvfrom call, if a second
Parameter Contents INPUT Value
OUTPUT
Value
s socket
descriptor of
local socket
socket descriptor
of socket receiving
the message
unchanged
msg pointer to data
buffer
pointer to buffer
that is to receive
data
pointer to
received data
len maximum
number of
bytes that
should be
received
size of data buffer unchanged
flags settings for
optional flags
0 (no options are
supported
unchanged
from address of
socket that
sent message
pointer to address
structure, not used
for input
pointer to
socket address
of socket that
sent the
message
fromlen pointer to the
size of from
pointer to size of
from
pointer to the
actual size of
address
returned