From 3e0ad7d79480a094c94213f0f8b94253918edc55 Mon Sep 17 00:00:00 2001 From: tuexen Date: Tue, 21 Aug 2018 14:04:30 +0000 Subject: [PATCH] Add SOL_SOCKET level socket option with name SO_DOMAIN to get the domain of a socket. This is helpful when testing and Solaris and Linux have the same socket option using the same name. Reviewed by: bcr@, rrs@ Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D16791 --- lib/libc/sys/getsockopt.2 | 3 ++- sys/kern/uipc_socket.c | 4 ++++ sys/sys/socket.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 index 389ccce0443..5dae6a6833d 100644 --- a/lib/libc/sys/getsockopt.2 +++ b/lib/libc/sys/getsockopt.2 @@ -28,7 +28,7 @@ .\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95 .\" $FreeBSD$ .\" -.Dd May 9, 2018 +.Dd August 21, 2018 .Dt GETSOCKOPT 2 .Os .Sh NAME @@ -172,6 +172,7 @@ for the socket .It Dv SO_TIMESTAMP Ta "enables reception of a timestamp with datagrams" .It Dv SO_BINTIME Ta "enables reception of a timestamp with datagrams" .It Dv SO_ACCEPTCONN Ta "get listening status of the socket (get only)" +.It Dv SO_DOMAIN Ta "get the domain of the socket (get only)" .It Dv SO_TYPE Ta "get the type of the socket (get only)" .It Dv SO_PROTOCOL Ta "get the protocol number for the socket (get only)" .It Dv SO_PROTOTYPE Ta "SunOS alias for the Linux SO_PROTOCOL (get only)" diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 8952b1a4fdd..18a4c6c9e83 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -3008,6 +3008,10 @@ sogetopt(struct socket *so, struct sockopt *sopt) error = sooptcopyout(sopt, &optval, sizeof optval); break; + case SO_DOMAIN: + optval = so->so_proto->pr_domain->dom_family; + goto integer; + case SO_TYPE: optval = so->so_type; goto integer; diff --git a/sys/sys/socket.h b/sys/sys/socket.h index e1bc51f41d0..eaad9b1bacd 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -171,6 +171,7 @@ typedef __uintptr_t uintptr_t; #define SO_PROTOTYPE SO_PROTOCOL /* alias for SO_PROTOCOL (SunOS name) */ #define SO_TS_CLOCK 0x1017 /* clock type used for SO_TIMESTAMP */ #define SO_MAX_PACING_RATE 0x1018 /* socket's max TX pacing rate (Linux name) */ +#define SO_DOMAIN 0x1019 /* get socket domain */ #endif #if __BSD_VISIBLE -- 2.45.0