[BACK]Return to sockopt.9 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / share / man / man9

File: [cvs.NetBSD.org] / src / share / man / man9 / sockopt.9 (download)

Revision 1.5, Tue Oct 28 18:42:54 2008 UTC (15 years, 5 months ago) by wiz
Branch: MAIN
CVS Tags: netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend
Changes since 1.4: +4 -4 lines

Use .Er for error codes.

.\"	$NetBSD: sockopt.9,v 1.5 2008/10/28 18:42:54 wiz Exp $
.\"
.\" Copyright (c) 2008 Iain Hibbert
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd October 28, 2008
.Dt SOCKOPT 9
.Os
.Sh NAME
.Nm sockopt_init ,
.Nm sockopt_destroy ,
.Nm sockopt_get ,
.Nm sockopt_getint
.Nm sockopt_set ,
.Nm sockopt_setint ,
.Nd socket options handling
.Sh SYNOPSIS
.In sys/socketvar.h
.Ft void
.Fn sockopt_init "struct sockopt *sopt" "int level" "int name" "size_t size"
.Ft void
.Fn sockopt_destroy "struct sockopt *sopt"
.Ft int
.Fn sockopt_get "struct sockopt *sopt" "void *value" "size_t size"
.Ft int
.Fn sockopt_getint "struct sockopt *sopt" "int *value"
.Ft int
.Fn sockopt_set "struct sockopt *sopt" "const void *value" "size_t size"
.Ft int
.Fn sockopt_setint "struct sockopt *sopt" "int value"
.Sh DESCRIPTION
The sockopt structure is used to pass a socket option and associated
value:
.Bd -literal -offset indent
struct sockopt {
	int		sopt_level;		/* option level */
	int		sopt_name;		/* option name */
	size_t		sopt_size;		/* data length */
	void *		sopt_data;		/* data pointer */
	uint8_t		sopt_buf[sizeof(int)];	/* internal storage */
};
.Ed
.Pp
The internal storage is used for the common case of values up to integer
size so that memory allocation is not required and sopt_data will point
to this in that case.
.Pp
Note: a sockopt structure may only be used for a single level/name/size
combination.
If the structure is to be re-used, it must be destroyed and re-initialized
with the new values.
.Sh OPTIONS
.Bl -tag -width xxxx
.It Cd "options DIAGNOSTIC"
Kernels compiled with the
.Dv DIAGNOSTIC
option will perform basic sanity checks on socket options operations.
.El
.Sh FUNCTIONS
.Bl -tag -width xxxx
.It Fn sockopt_init "sopt" "level" "name" "size"
Initialise sockopt storage.
If
.Ar size
is given,
.Fn sockopt_init
will arrange for sopt_data to point to a buffer of
.Ar size
bytes for the sockopt value.
Where memory needs to be allocated to satisfy this,
.Fn sockopt_init
may sleep.
.It Fn sockopt_destroy "sopt"
Destroy sockopt storage, releasing any allocated memory.
.It Fn sockopt_get "sopt" "value" "size"
Copy out sockopt value.
Will return
.Er EINVAL
if an incorrect data size is given.
.It Fn sockopt_getint "sopt" "value"
Common case of get sockopt integer value.
Will return
.Er EINVAL
if sockopt does not contain an integer sized value.
.It Fn sockopt_set "sopt" "value" "size"
Copy in sockopt value.
The sockopt structure must contain a data field of
.Ar size
bytes or be previously unset, in which case a data buffer may be
allocated using
.Xr kmem_alloc 9
with the
.Dv KM_NOSLEEP
flag which may cause
.Fn sockopt_set
to return
.Er ENOMEM .
.Pp
Note: If you need to use
.Fn sockopt_set
in a context where memory allocation may be required and you do not wish to
contemplate failure, the sockopt structure can be initialised in a more suitable
context using
.Fn sockopt_init
which will not fail.
.It Fn sockopt_setint "sopt" "value"
Common case of set sockopt integer value.
The sockpt structure must contain an int sized data field or be previously
unset, in which case the data pointer will be set to the internal storage.
.El
.Sh CODE REFERENCES
This section describes places within the
.Nx
source tree where code implementing socket options can be found.
All pathnames are relative to
.Pa /usr/src .
.Pp
The function prototypes and sockopt structure are defined in the
.Pa sys/sys/socketvar.h
header file, and the socket options implementation is in
.Pa sys/kern/uipc_socket.c .
.Sh SEE ALSO
.Xr errno 2 ,
.Xr kmem_alloc 9
.Sh HISTORY
The socket options KPI was inspired by a similar KPI in
.Fx
and
first appeared in
.Nx 5.0 .