From 683f302ed9c45e862b73af10560ef82a6b9b43b5 Mon Sep 17 00:00:00 2001 From: claudio Date: Tue, 2 Apr 2024 14:23:15 +0000 Subject: [PATCH] Implement SO_ACCEPTCONN in getsockopt(2) Requested by robert@ OK mvs@ millert@ deraadt@ --- lib/libc/sys/getsockopt.2 | 12 ++++++++++-- sys/kern/uipc_socket.c | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 index f078525f13e..eb9c89e447a 100644 --- a/lib/libc/sys/getsockopt.2 +++ b/lib/libc/sys/getsockopt.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: getsockopt.2,v 1.61 2023/02/22 06:31:51 guenther Exp $ +.\" $OpenBSD: getsockopt.2,v 1.62 2024/04/02 14:23:15 claudio Exp $ .\" $NetBSD: getsockopt.2,v 1.7 1995/02/27 12:33:29 cgd Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94 .\" -.Dd $Mdocdate: February 22 2023 $ +.Dd $Mdocdate: April 2 2024 $ .Dt GETSOCKOPT 2 .Os .Sh NAME @@ -176,6 +176,8 @@ get and clear error on the socket (get only) get the domain of the socket (get only) .It Dv SO_PROTOCOL get the protocol of the socket (get only) +.It Dv SO_ACCEPTCONN +get listening status of the socket (get only) .It Dv SO_PEERCRED get the credentials from other side of connection (get only) .El @@ -447,6 +449,7 @@ Finally, .Dv SO_DOMAIN , .Dv SO_PROTOCOL , .Dv SO_ERROR , +.Dv SO_ACCEPTCONN , and .Dv SO_PEERCRED are options used only with @@ -465,6 +468,11 @@ returns the protocol of the socket such as returns any pending error on the socket and clears the error status. It may be used to check for asynchronous errors on connected datagram sockets or for other asynchronous errors. +.Dv SO_ACCEPTCONN +returns whether the socket is currently accepting connections, that is, +whether or not +.Xr listen 2 +was called. .Dv SO_PEERCRED fetches the .Va struct sockpeercred diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 97f53cff0c9..8c33b9defd6 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.326 2024/04/02 12:21:39 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.327 2024/04/02 14:23:15 claudio Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -2050,6 +2050,7 @@ sogetopt(struct socket *so, int level, int optname, struct mbuf *m) case SO_REUSEPORT: case SO_BROADCAST: case SO_OOBINLINE: + case SO_ACCEPTCONN: case SO_TIMESTAMP: case SO_ZEROIZE: *mtod(m, int *) = so->so_options & optname; -- 2.20.1