]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
47009d5e | 4 | .\" SPDX-License-Identifier: BSD-4-Clause-UC |
fea681da MK |
5 | .\" |
6 | .\" $Id: recv.2,v 1.3 1999/05/13 11:33:38 freitag Exp $ | |
7 | .\" | |
8 | .\" Modified Sat Jul 24 00:22:20 1993 by Rik Faith <faith@cs.unc.edu> | |
9 | .\" Modified Tue Oct 22 17:45:19 1996 by Eric S. Raymond <esr@thyrsus.com> | |
10 | .\" Modified 1998,1999 by Andi Kleen | |
11 | .\" 2001-06-19 corrected SO_EE_OFFENDER, bug report by James Hawtin | |
12 | .\" | |
1d767b55 | 13 | .TH RECV 2 2021-03-22 "Linux" "Linux Programmer's Manual" |
fea681da MK |
14 | .SH NAME |
15 | recv, recvfrom, recvmsg \- receive a message from a socket | |
16 | .SH SYNOPSIS | |
16c892d3 | 17 | .nf |
fea681da | 18 | .B #include <sys/socket.h> |
68e4db0a | 19 | .PP |
c4e7b714 | 20 | .BI "ssize_t recv(int " sockfd ", void *" buf ", size_t " len ", int " flags ); |
04dc013d AC |
21 | .BI "ssize_t recvfrom(int " sockfd ", void *restrict " buf ", size_t " len \ |
22 | ", int " flags , | |
23 | .BI " struct sockaddr *restrict " src_addr , | |
24 | .BI " socklen_t *restrict " addrlen ); | |
c4e7b714 | 25 | .BI "ssize_t recvmsg(int " sockfd ", struct msghdr *" msg ", int " flags ); |
16c892d3 | 26 | .fi |
fea681da MK |
27 | .SH DESCRIPTION |
28 | The | |
e39a21b5 MK |
29 | .BR recv (), |
30 | .BR recvfrom (), | |
fea681da | 31 | and |
e511ffb6 | 32 | .BR recvmsg () |
ea629944 | 33 | calls are used to receive messages from a socket. |
e39a21b5 MK |
34 | They may be used |
35 | to receive data on both connectionless and connection-oriented sockets. | |
5f09a929 MK |
36 | This page first describes common features of all three system calls, |
37 | and then describes the differences between the calls. | |
fea681da | 38 | .PP |
90425b93 HS |
39 | The only difference between |
40 | .BR recv () | |
41 | and | |
42 | .BR read (2) | |
43 | is the presence of | |
44 | .IR flags . | |
45 | With a zero | |
46 | .I flags | |
47 | argument, | |
48 | .BR recv () | |
36c8e721 MK |
49 | is generally equivalent to |
50 | .BR read (2) | |
51 | (but see NOTES). | |
90425b93 | 52 | Also, the following call |
efeece04 | 53 | .PP |
90425b93 | 54 | recv(sockfd, buf, len, flags); |
efeece04 | 55 | .PP |
90425b93 | 56 | is equivalent to |
efeece04 | 57 | .PP |
90425b93 HS |
58 | recvfrom(sockfd, buf, len, flags, NULL, NULL); |
59 | .PP | |
ea629944 | 60 | All three calls return the length of the message on successful |
c13182ef MK |
61 | completion. |
62 | If a message is too long to fit in the supplied buffer, excess | |
fea681da | 63 | bytes may be discarded depending on the type of socket the message is |
7080c286 | 64 | received from. |
fea681da MK |
65 | .PP |
66 | If no messages are available at the socket, the receive calls wait for a | |
ff40dbb3 | 67 | message to arrive, unless the socket is nonblocking (see |
62d4f1bd | 68 | .BR fcntl (2)), |
ba50f49c | 69 | in which case the value \-1 is returned and |
fea681da | 70 | .I errno |
86426e0b | 71 | is set to |