]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/recv.2
mmap.2: Don't mark MAP_ANON as deprecated
[thirdparty/man-pages.git] / man2 / recv.2
CommitLineData
fea681da
MK
1.\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
a9cd9cb7 4.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
fea681da
MK
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\" notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\" notice, this list of conditions and the following disclaimer in the
12.\" documentation and/or other materials provided with the distribution.
13.\" 3. All advertising materials mentioning features or use of this software
14.\" must display the following acknowledgement:
15.\" This product includes software developed by the University of
16.\" California, Berkeley and its contributors.
17.\" 4. Neither the name of the University nor the names of its contributors
18.\" may be used to endorse or promote products derived from this software
19.\" without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
8c9302dc 32.\" %%%LICENSE_END
fea681da
MK
33.\"
34.\" $Id: recv.2,v 1.3 1999/05/13 11:33:38 freitag Exp $
35.\"
36.\" Modified Sat Jul 24 00:22:20 1993 by Rik Faith <faith@cs.unc.edu>
37.\" Modified Tue Oct 22 17:45:19 1996 by Eric S. Raymond <esr@thyrsus.com>
38.\" Modified 1998,1999 by Andi Kleen
39.\" 2001-06-19 corrected SO_EE_OFFENDER, bug report by James Hawtin
40.\"
4b8c67d9 41.TH RECV 2 2017-09-15 "Linux" "Linux Programmer's Manual"
fea681da
MK
42.SH NAME
43recv, recvfrom, recvmsg \- receive a message from a socket
44.SH SYNOPSIS
45.\" .B #include <sys/uio.h>
46.\" .br
16c892d3 47.nf
fea681da
MK
48.B #include <sys/types.h>
49.br
50.B #include <sys/socket.h>
68e4db0a 51.PP
c4e7b714 52.BI "ssize_t recv(int " sockfd ", void *" buf ", size_t " len ", int " flags );
68e4db0a 53.PP
c4e7b714 54.BI "ssize_t recvfrom(int " sockfd ", void *" buf ", size_t " len ", int " flags ,
6926dbf5 55.BI " struct sockaddr *" src_addr ", socklen_t *" addrlen );
68e4db0a 56.PP
c4e7b714 57.BI "ssize_t recvmsg(int " sockfd ", struct msghdr *" msg ", int " flags );
16c892d3 58.fi
fea681da
MK
59.SH DESCRIPTION
60The
e39a21b5
MK
61.BR recv (),
62.BR recvfrom (),
fea681da 63and
e511ffb6 64.BR recvmsg ()
ea629944 65calls are used to receive messages from a socket.
e39a21b5
MK
66They may be used
67to receive data on both connectionless and connection-oriented sockets.
5f09a929
MK
68This page first describes common features of all three system calls,
69and then describes the differences between the calls.
fea681da 70.PP
90425b93
HS
71The only difference between
72.BR recv ()
73and
74.BR read (2)
75is the presence of
76.IR flags .
77With a zero
78.I flags
79argument,
80.BR recv ()
36c8e721
MK
81is generally equivalent to
82.BR read (2)
83(but see NOTES).
90425b93 84Also, the following call
efeece04 85.PP
90425b93 86 recv(sockfd, buf, len, flags);
efeece04 87.PP
90425b93 88is equivalent to
efeece04 89.PP
90425b93
HS
90 recvfrom(sockfd, buf, len, flags, NULL, NULL);
91.PP
ea629944 92All three calls return the length of the message on successful
c13182ef
MK
93completion.
94If a message is too long to fit in the supplied buffer, excess
fea681da 95bytes may be discarded depending on the type of socket the message is
7080c286 96received from.
fea681da
MK
97.PP
98If no messages are available at the socket, the receive calls wait for a
ff40dbb3 99message to arrive, unless the socket is nonblocking (see
62d4f1bd 100.BR fcntl (2)),
fea681da
MK
101in which case the value \-1 is returned and the external variable
102.I errno
86426e0b 103is set to