Add copyright
[unix-history] / usr / src / lib / libc / sys / getsockopt.2
CommitLineData
efbcfcab
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
a66e777a 5.\" @(#)getsockopt.2 6.1 (Berkeley) %G%
efbcfcab 6.\"
a66e777a 7.TH GETSOCKOPT 2 ""
efbcfcab
KM
8.UC 5
9.SH NAME
10getsockopt, setsockopt \- get and set options on sockets
11.SH SYNOPSIS
12.nf
13.ft B
14#include <sys/types.h>
15#include <sys/socket.h>
16.PP
17.ft B
18getsockopt(s, level, optname, optval, optlen)
19int s, level, optname;
20char *optval;
21int *optlen;
22.sp
23setsockopt(s, level, optname, optval, optlen)
24int s, level, optname;
25char *optval;
26int optlen;
27.fi
28.SH DESCRIPTION
29.I Getsockopt
30and
31.I setsockopt
32manipulate
33.I options
34associated with a socket. Options may exist at multiple
35protocol levels; they are always present at the uppermost
36``socket'' level.
37.PP
38When manipulating socket options the level at which the
39option resides and the name of the option must be specified.
40To manipulate options at the ``socket'' level,
41.I level
42is specified as SOL_SOCKET. To manipulate options at any
43other level the protocol number of the appropriate protocol
44controlling the option is supplied. For example,
45to indicate an option is to be interpreted by the TCP protocol,
46.I level
47should be set to the protocol number of TCP; see
48.IR getprotoent (3N).
49.PP
50The parameters
51.I optval
52and
53.I optlen
54are used to access option values for
55.IR setsockopt .
56For
57.I getsockopt
58they identify a buffer in which the value for the
59requested option(s) are to be returned. For
60.IR getsockopt ,
61.I optlen
62is a value-result parameter, initially containing the
63size of the buffer pointed to by
64.IR optval ,
65and modified on return to indicate the actual size of
66the value returned. If no option value is
67to be supplied or returned,
68.I optval
69may be supplied as 0.
70.PP
71.I Optname
72and any specified options are passed uninterpreted to the appropriate
73protocol module for interpretation.
74The include file
75.RI < sys/socket.h >
76contains definitions for ``socket'' level options; see
77.IR socket (2).
78Options at other protocol levels vary in format and
79name, consult the appropriate entries in (4P).
80.SH "RETURN VALUE"
81A 0 is returned if the call succeeds, \-1 if it fails.
82.SH ERRORS
83The call succeeds unless:
84.TP 20
85[EBADF]
86The argument \fIs\fP is not a valid descriptor.
87.TP 20
88[ENOTSOCK]
89The argument \fIs\fP is a file, not a socket.
90.TP 20
91[ENOPROTOOPT]
92The option is unknown.
93.TP 20
94[EFAULT]
95The options are not in a valid part of the
96process address space.
97.SH "SEE ALSO"
98socket(2), getprotoent(3N)