improved english
[unix-history] / usr / src / lib / libc / sys / recv.2
CommitLineData
03e70dcd
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
a9e7c426 5.\" @(#)recv.2 6.1 (Berkeley) %G%
03e70dcd 6.\"
a9e7c426 7.TH RECV 2 ""
03e70dcd
KM
8.UC 5
9.SH NAME
10recv, recvfrom, recvmsg \- receive a message from a socket
11.SH SYNOPSIS
12.nf
13.ft B
14#include <sys/types.h>
15#include <sys/socket.h>
16.PP
17.ft B
18cc = recv(s, buf, len, flags)
19int cc, s;
20char *buf;
21int len, flags;
22.PP
23.ft B
24cc = recvfrom(s, buf, len, flags, from, fromlen)
25int cc, s;
26char *buf;
27int len, flags;
28struct sockaddr *from;
29int *fromlen;
30.PP
31.ft B
32cc = recvmsg(s, msg, flags)
33int cc, s;
34struct msghdr msg[];
35int flags;
36.ft R
37.SH DESCRIPTION
38.IR Recv ,
39.IR recvfrom ,
40and
41.IR recvmsg
42are used to receive messages from a socket.
43.PP
44The
45.I recv
46call may be used only on a
47.I connected
48socket (see
49.IR connect (2)),
50while
51.I recvfrom
52and
53.I recvmsg
54may be used to receive data on a socket whether
55it is in a connected state or not.
56.PP
57If
58.I from
59is non-zero, the source address of the message is filled in.
60.I Fromlen
61is a value-result parameter, initialized to the size of
62the buffer associated with
63.IR from ,
64and modified on return to indicate the actual size of the
65address stored there.
66The length of the message is returned in
67.IR cc .
68If a message is too long to fit in the supplied buffer,
69excess bytes may be discarded depending on the type of socket
70the message is received from; see
71.IR socket (2).
72.PP
73If no messages are available at the socket, the
74receive call waits for a message to arrive, unless
75the socket is nonblocking (see
76.IR ioctl (2))
77in which case a
78.I cc
79of \-1 is returned with the external variable errno
80set to EWOULDBLOCK.
81.PP
82The
83.IR select (2)
84call may be used to determine when more data arrives.
85.PP
86The
87.I flags
88argument to a send call is formed by
89.IR or 'ing
90one or more of the values,
91.PP
92.nf
93.RS
94.DT
a9e7c426
KM
95#define MSG_OOB 0x1 /* process out-of-band data */
96#define MSG_PEEK 0x2 /* peek at incoming message */
03e70dcd
KM
97.RE
98.fi
99.PP
100The
101.I recvmsg
102call uses a
103.I msghdr
104structure to minimize the number of directly supplied parameters.
105This structure has the following form, as defined in
106.IR <sys/socket.h> :
107.PP
108.nf
109.RS
110.DT
111struct msghdr {
112 caddr_t msg_name; /* optional address */
113 int msg_namelen; /* size of address */
a9e7c426 114 struct iovec *msg_iov; /* scatter/gather array */
03e70dcd
KM
115 int msg_iovlen; /* # elements in msg_iov */
116 caddr_t msg_accrights; /* access rights sent/received */
117 int msg_accrightslen;
118};
119.RE
120.fi
121.PP
122Here
123.I msg_name
124and
125.I msg_namelen
126specify the destination address if the socket is unconnected;
127.I msg_name
128may be given as a null pointer if no names are desired or required.
129The
130.I msg_iov
131and
132.I msg_iovlen
133describe the scatter gather locations, as described in
134.IR read (2).
135Access rights to be sent along with the message are specified
136in
137.IR msg_accrights ,
138which has length
139.IR msg_accrightslen .
140.SH "RETURN VALUE
141These calls return the number of bytes received, or \-1
142if an error occurred.
143.SH ERRORS
144The calls fail if:
145.TP 20
146[EBADF]
147The argument \fIs\fP is an invalid descriptor.
148.TP 20
149[ENOTSOCK]
150The argument \fIs\fP is not a socket.
151.TP 20
152[EWOULDBLOCK]
153The socket is marked non-blocking and the receive operation
154would block.
155.TP 20
156[EINTR]
157The receive was interrupted by delivery of a signal before
158any data was available for the receive.
159.TP 20
160[EFAULT]
161The data was specified to be received into a non-existent
162or protected part of the process address space.
163.SH SEE ALSO
164read(2), send(2), socket(2)