Copyright 1989 AT&T
Copyright (C) 2002, Sun Microsystems, Inc. All Rights Reserved
Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
Copyright 2024 Oxide Computer Company
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
cc [ flag ... ] file ... -lsocket -lnsl [ library ... ] #include <sys/types.h> #include <sys/socket.h> int accept(int s, struct sockaddr *addr, socklen_t *addrlen); int accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags);
The argument addr is a result parameter that is filled in with the address of the connecting entity as it is known to the communications layer. The exact format of the addr parameter is determined by the domain in which the communication occurs.
The argument addrlen is a value-result parameter. Initially, it contains the amount of space pointed to by addr; on return it contains the length in bytes of the address returned.
The accept() function is used with connection-based socket types, currently with SOCK_STREAM.
The accept4() function allows flags that control the behavior of a successfully accepted socket. If flags is 0, accept4() acts identically to accept(). Values for flags are constructed by a bitwise-inclusive-OR of flags from the following list, defined in <sys/socket.h>. SOCK_CLOEXEC
The accepted socket will have the FD_CLOEXEC flag set as if fcntl() was called on it. This flag is set before the socket is passed to the caller thus avoiding the race condition between accept() and fcntl(). See, O_CLOEXEC in open(2) for more details.
The accepted socket will have the FD_CLOFORK flag set as if fcntl() was called on it. This flag is set before the socket is passed to the caller thus avoiding the race condition between accept() and fcntl(). See, O_CLOFORK in open(2) for more details.
The accepted socket will have the O_NDELAY flag set as if fcntl() was called on it. This sets the socket into non-blocking mode. See O_NDELAY in fcntl.h(3HEAD) for more details.
The accepted socket will have the O_NONBLOCK flag set as if fcntl() was called on it. This sets the socket into non-blocking mode (POSIX; see standards(7)). See O_NONBLOCK in fcntl.h(3HEAD) for more details.
It is possible to select(3C) or poll(2) a socket for the purpose of an accept() by selecting or polling it for a read. However, this will only indicate when a connect indication is pending; it is still necessary to call accept().
The descriptor is invalid.
The remote side aborted the connection before the accept() operation completed.
The addr parameter or the addrlen parameter is invalid.
The accept() attempt was interrupted by the delivery of a signal.
The per-process descriptor table is full.
The protocol family and type corresponding to s could not be found in the netconfig file.
There was insufficient user memory available to complete the operation.
There were insufficient STREAMS resources available to complete the operation.
The descriptor does not reference a socket.
The referenced socket is not of type SOCK_STREAM.
A protocol error has occurred; for example, the STREAMS protocol stack has not been initialized or the connection has already been released.
The socket is marked as non-blocking and no connections are present to be accepted.
Additionally, accept4() will fail if: EINVAL
The flags value is invalid. The flags argument can only be the bitwise inclusive-OR of SOCK_CLOEXEC, SOCK_CLOFORK, SOCK_NONBLOCK, and SOCK_NDELAY.
ATTRIBUTE TYPE ATTRIBUTE VALUE |
MT-Level Safe |