Skip to content

Commit

Permalink
implement SO_DOMAIN and SO_PROTOCOL so that the domain and the protocol
Browse files Browse the repository at this point in the history
can also be retrieved with getsockopt(3)
it looks like these will also be in the next issue of posix:
http://austingroupbugs.net/view.php?id=840#c2263

ok claudio@, sthen@
  • Loading branch information
rnagy committed Jul 22, 2019
1 parent d03221a commit 15b62b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
18 changes: 15 additions & 3 deletions lib/libc/sys/getsockopt.2
@@ -1,4 +1,4 @@
.\" $OpenBSD: getsockopt.2,v 1.55 2019/02/13 11:55:21 martijn Exp $
.\" $OpenBSD: getsockopt.2,v 1.56 2019/07/22 15:34:07 robert Exp $
.\" $NetBSD: getsockopt.2,v 1.7 1995/02/27 12:33:29 cgd Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
Expand Down Expand Up @@ -30,7 +30,7 @@
.\"
.\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94
.\"
.Dd $Mdocdate: February 13 2019 $
.Dd $Mdocdate: July 22 2019 $
.Dt GETSOCKOPT 2
.Os
.Sh NAME
Expand Down Expand Up @@ -174,6 +174,10 @@ clear all memory containing user supplied data
get the type of the socket (get only)
.It Dv SO_ERROR
get and clear error on the socket (get only)
.It Dv SO_DOMAIN
get the domain of the socket (get only)
.It Dv SO_PROTOCOL
get the protocol of the socket (get only)
.El
.Pp
.Dv SO_DEBUG
Expand Down Expand Up @@ -451,7 +455,9 @@ If
is set, overwrite kernel memory after sending data.
.Pp
Finally,
.Dv SO_TYPE
.Dv SO_TYPE ,
.Dv SO_DOMAIN ,
.Dv SO_PROTOCOL
and
.Dv SO_ERROR
are options used only with
Expand All @@ -460,6 +466,12 @@ are options used only with
returns the type of the socket, such as
.Dv SOCK_STREAM ;
it is useful for servers that inherit sockets on startup.
.Dv SO_DOMAIN
returns the domain of the socket, such as
.Dv AF_INET .
.Dv SO_PROTOCOL
returns the protocol of the socket such as
.Dv IPPROTO_TCP .
.Dv SO_ERROR
returns any pending error on the socket and clears the error status.
It may be used to check for asynchronous errors on connected
Expand Down
10 changes: 9 additions & 1 deletion sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
/* $OpenBSD: uipc_socket.c,v 1.233 2019/07/11 11:57:35 bluhm Exp $ */
/* $OpenBSD: uipc_socket.c,v 1.234 2019/07/22 15:34:07 robert Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */

/*
Expand Down Expand Up @@ -1868,6 +1868,14 @@ sogetopt(struct socket *so, int level, int optname, struct mbuf *m)
so->so_error = 0;
break;

case SO_DOMAIN:
*mtod(m, int *) = so->so_proto->pr_domain->dom_family;
break;

case SO_PROTOCOL:
*mtod(m, int *) = so->so_proto->pr_protocol;
break;

case SO_SNDBUF:
*mtod(m, int *) = so->so_snd.sb_hiwat;
break;
Expand Down
4 changes: 3 additions & 1 deletion sys/sys/socket.h
@@ -1,4 +1,4 @@
/* $OpenBSD: socket.h,v 1.97 2019/07/03 10:08:10 dlg Exp $ */
/* $OpenBSD: socket.h,v 1.98 2019/07/22 15:34:07 robert Exp $ */
/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */

/*
Expand Down Expand Up @@ -113,6 +113,8 @@ typedef __sa_family_t sa_family_t; /* sockaddr address family type */
#define SO_RTABLE 0x1021 /* routing table to be used */
#define SO_PEERCRED 0x1022 /* get connect-time credentials */
#define SO_SPLICE 0x1023 /* splice data to other socket */
#define SO_DOMAIN 0x1024 /* get socket domain */
#define SO_PROTOCOL 0x1025 /* get socket protocol */

/*
* Structure used for manipulating linger option.
Expand Down

0 comments on commit 15b62b7

Please sign in to comment.