TCP/IP Programming Manual

from_ptr
input and return value;points, on return, to the remote address and port number (based on the
structure sockaddr_in or sockaddr_in6) from which the data is received.
from_length
input and return value; maintained only for compatibility and should point to a value indicating
the size in bytes of the structure (the remote address and port number) pointed to by from_ptr.
Errors
If an error occurs, the return value is set to -1 and the external variable errno is set to one of the
following values:
The specified socket was connected.EISCONN
The specified socket was shut down.ESHUTDOWN
An invalid argument was specified.EINVAL
Usage Guidelines
This is a waited call; your program pause until the operation completes. Refer to Usage
Guidelines (page 155) in the recv, recv_nw function description for more information.
You can perform a nowait call to receive data on an unconnected UDP socket or raw socket
using recvfrom_nw, described later in this section.
Declare the from_ptr variable as struct sockaddr_in6 * for IPv6 use or as struct
sockaddr_storage * for protocol-independent use. In C, when you make the call, cast
the variable to sockaddr. (See the IPv6 example.)
Example
INET: the following programming example calls the recvfrom function. In this example, rsock
is a socket created by a previous call to socket and fhost is a structure that receives the address
of the host from which the data is received. The data is received in buffer:
#include <socket.h>
#include <in.h>
#include <netdb.h>
...
struct sockaddr_in fhost;
int status, tosend, len;
char buffer [8*1024];
...
tosend = sizeof(buffer);
status = recvfrom(rsock, buffer, tosend,
0, (struct sockaddr *)&fhost, &len);
INET6: the following programming example calls the recvfrom function. In this example, rsock
is a socket created by a previous call to socket and fhost is a structure that receives the address
of the host from which the data is received. The data is received in buffer:
#include <socket.h>
#include <in.h>
#include <in6.h>
#include <netdb.h>
...
struct sockaddr_in6 fhost;
int status, tosend, len;
char buffer [8*1024];
...
tosend = sizeof(buffer);
recvfrom 159