1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" and Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" All rights reserved.
5 .\" SPDX-License-Identifier: BSD-4-Clause-UC
7 .\" $Id: listen.2,v 1.6 1999/05/18 14:10:32 freitag Exp $
9 .\" Modified Fri Jul 23 22:07:54 1993 by Rik Faith <faith@cs.unc.edu>
10 .\" Modified 950727 by aeb, following a suggestion by Urs Thuermann
11 .\" <urs@isnogud.escape.de>
12 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
13 .\" Modified 1998 by Andi Kleen
14 .\" Modified 11 May 2001 by Sam Varshavchik <mrsam@courier-mta.com>
17 .TH LISTEN 2 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
19 listen \- listen for connections on a socket
22 .RI ( libc ", " \-lc )
25 .B #include <sys/socket.h>
27 .BI "int listen(int " sockfd ", int " backlog );
31 marks the socket referred to by
33 as a passive socket, that is, as a socket that will
34 be used to accept incoming connection requests using
39 argument is a file descriptor that refers to a socket of type
46 argument defines the maximum length
47 to which the queue of pending connections for
50 If a connection request arrives when the queue is full, the client
51 may receive an error with an indication of
53 or, if the underlying protocol supports retransmission, the request may be
54 ignored so that a later reattempt at connection succeeds.
56 On success, zero is returned.
57 On error, \-1 is returned, and
59 is set to indicate the error.
63 Another socket is already listening on the same port.
66 (Internet domain sockets)
67 The socket referred to by
69 had not previously been bound to an address and,
70 upon attempting to bind it to an ephemeral port,
71 it was determined that all port numbers in the ephemeral port range
74 .I /proc/sys/net/ipv4/ip_local_port_range
81 is not a valid file descriptor.
86 does not refer to a socket.
89 The socket is not of a type that supports the
93 POSIX.1-2001, POSIX.1-2008, 4.4BSD
95 first appeared in 4.2BSD).
97 To accept connections, the following steps are performed:
100 A socket is created with
103 The socket is bound to a local address using
105 so that other sockets may be
109 A willingness to accept incoming connections and a queue limit for incoming
110 connections are specified with
113 Connections are accepted with
119 argument on TCP sockets changed with Linux 2.2.
120 Now it specifies the queue length for
122 established sockets waiting to be accepted,
123 instead of the number of incomplete connection requests.
124 The maximum length of the queue for incomplete sockets
126 .IR /proc/sys/net/ipv4/tcp_max_syn_backlog .
127 When syncookies are enabled there is no logical maximum
128 length and this setting is ignored.
131 for more information.
135 argument is greater than the value in
136 .IR /proc/sys/net/core/somaxconn ,
137 then it is silently capped to that value.
138 Since Linux 5.4, the default in this file is 4096;
139 in earlier kernels, the default value is 128.
140 In kernels before 2.4.25, this limit was a hard coded value,
143 .\" The following is now rather historic information (MTK, Jun 05)
144 .\" Don't rely on this value in portable applications since BSD
145 .\" (and some BSD-derived systems) limit the backlog to 5.