2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
|
|
|
|
.\" 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.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
.\"
|
|
|
|
.\" $Id: getsockopt.2,v 1.1 1999/05/24 14:57:04 freitag Exp $
|
|
|
|
.\"
|
|
|
|
.\" Modified Sat Jul 24 16:19:32 1993 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Modified Mon Apr 22 02:29:06 1996 by Martin Schulze (joey@infodrom.north.de)
|
|
|
|
.\" Modified Tue Aug 27 10:52:51 1996 by Andries Brouwer (aeb@cwi.nl)
|
|
|
|
.\" Modified Thu Jan 23 13:29:34 1997 by Andries Brouwer (aeb@cwi.nl)
|
|
|
|
.\" Modified Sun Mar 28 21:26:46 1999 by Andries Brouwer (aeb@cwi.nl)
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" Modified 1999 by Andi Kleen <ak@muc.de>.
|
2006-12-27 03:54:41 +00:00
|
|
|
.\" Removed most stuff because it is in socket.7 now.
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
2008-12-03 18:56:22 +00:00
|
|
|
.TH GETSOCKOPT 2 2008-12-03 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
getsockopt, setsockopt \- get and set options on sockets
|
|
|
|
.SH SYNOPSIS
|
2007-04-03 14:04:54 +00:00
|
|
|
.nf
|
2007-06-10 18:08:27 +00:00
|
|
|
.BR "#include <sys/types.h>" " /* See NOTES */"
|
2004-11-03 13:51:07 +00:00
|
|
|
.br
|
|
|
|
.B #include <sys/socket.h>
|
2007-04-03 14:04:54 +00:00
|
|
|
.sp
|
2008-12-03 18:56:22 +00:00
|
|
|
.BI "int getsockopt(int " sockfd ", int " level ", int " optname ,
|
2007-04-03 14:04:54 +00:00
|
|
|
.BI " void *" optval ", socklen_t *" optlen );
|
2008-12-03 18:56:22 +00:00
|
|
|
.BI "int setsockopt(int " sockfd ", int " level ", int " optname ,
|
2007-04-03 14:04:54 +00:00
|
|
|
.BI " const void *" optval ", socklen_t " optlen );
|
|
|
|
.fi
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
2006-06-03 01:26:30 +00:00
|
|
|
.BR getsockopt ()
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR setsockopt ()
|
2008-12-03 19:29:52 +00:00
|
|
|
manipulate options for the socket referred to by the file descriptor
|
|
|
|
.IR sockfd .
|
2007-04-12 22:42:49 +00:00
|
|
|
Options may exist at multiple
|
2004-11-03 13:51:07 +00:00
|
|
|
protocol levels; they are always present at the uppermost
|
2008-12-03 19:29:52 +00:00
|
|
|
socket level.
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2008-12-03 19:29:52 +00:00
|
|
|
When manipulating socket options, the level at which the
|
2004-11-03 13:51:07 +00:00
|
|
|
option resides and the name of the option must be specified.
|
2008-12-03 19:29:52 +00:00
|
|
|
To manipulate options at the sockets API level,
|
2004-11-03 13:51:07 +00:00
|
|
|
.I level
|
|
|
|
is specified as
|
|
|
|
.BR SOL_SOCKET .
|
|
|
|
To manipulate options at any
|
|
|
|
other level the protocol number of the appropriate protocol
|
2007-04-12 22:42:49 +00:00
|
|
|
controlling the option is supplied.
|
|
|
|
For example,
|
2004-11-03 13:51:07 +00:00
|
|
|
to indicate that an option is to be interpreted by the
|
|
|
|
.B TCP
|
|
|
|
protocol,
|
|
|
|
.I level
|
|
|
|
should be set to the protocol number of
|
|
|
|
.BR TCP ;
|
|
|
|
see
|
|
|
|
.BR getprotoent (3).
|
|
|
|
|
2008-07-10 20:53:08 +00:00
|
|
|
The arguments
|
2004-11-03 13:51:07 +00:00
|
|
|
.I optval
|
|
|
|
and
|
|
|
|
.I optlen
|
|
|
|
are used to access option values for
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR setsockopt ().
|
2004-11-03 13:51:07 +00:00
|
|
|
For
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR getsockopt ()
|
2004-11-03 13:51:07 +00:00
|
|
|
they identify a buffer in which the value for the
|
2007-04-12 22:42:49 +00:00
|
|
|
requested option(s) are to be returned.
|
|
|
|
For
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR getsockopt (),
|
2004-11-03 13:51:07 +00:00
|
|
|
.I optlen
|
2008-07-10 20:53:08 +00:00
|
|
|
is a value-result argument, initially containing the
|
2004-11-03 13:51:07 +00:00
|
|
|
size of the buffer pointed to by
|
|
|
|
.IR optval ,
|
|
|
|
and modified on return to indicate the actual size of
|
2007-04-12 22:42:49 +00:00
|
|
|
the value returned.
|
|
|
|
If no option value is to be supplied or returned,
|
2004-11-03 13:51:07 +00:00
|
|
|
.I optval
|
|
|
|
may be NULL.
|
|
|
|
|
|
|
|
.I Optname
|
|
|
|
and any specified options are passed uninterpreted to the appropriate
|
2007-04-12 22:42:49 +00:00
|
|
|
protocol module for interpretation.
|
|
|
|
The include file
|
2004-11-03 13:51:07 +00:00
|
|
|
.I <sys/socket.h>
|
2007-04-12 22:42:49 +00:00
|
|
|
contains definitions for socket level options, described below.
|
|
|
|
Options at
|
2004-11-03 13:51:07 +00:00
|
|
|
other protocol levels vary in format and name; consult the appropriate
|
|
|
|
entries in section 4 of the manual.
|
|
|
|
|
|
|
|
Most socket-level options utilize an
|
|
|
|
.I int
|
2008-07-10 20:53:08 +00:00
|
|
|
argument for
|
2004-11-03 13:51:07 +00:00
|
|
|
.IR optval .
|
|
|
|
For
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR setsockopt (),
|
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
|
|
|
the argument should be nonzero to enable a boolean option, or zero if the
|
2004-11-03 13:51:07 +00:00
|
|
|
option is to be disabled.
|
|
|
|
.PP
|
|
|
|
For a description of the available socket options see
|
|
|
|
.BR socket (7)
|
|
|
|
and the appropriate protocol man pages.
|
|
|
|
.SH "RETURN VALUE"
|
2007-04-12 22:42:49 +00:00
|
|
|
On success, zero is returned.
|
|
|
|
On error, \-1 is returned, and
|
2004-11-03 13:51:07 +00:00
|
|
|
.I errno
|
|
|
|
is set appropriately.
|
|
|
|
.SH ERRORS
|
|
|
|
.TP 10
|
|
|
|
.B EBADF
|
|
|
|
The argument
|
2008-12-03 21:01:54 +00:00
|
|
|
.I sockfd
|
2004-11-03 13:51:07 +00:00
|
|
|
is not a valid descriptor.
|
|
|
|
.TP
|
|
|
|
.B EFAULT
|
2007-04-12 22:42:49 +00:00
|
|
|
The address pointed to by
|
2004-11-03 13:51:07 +00:00
|
|
|
.I optval
|
2007-04-12 22:42:49 +00:00
|
|
|
is not in a valid part of the process address space.
|
|
|
|
For
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR getsockopt (),
|
2004-11-03 13:51:07 +00:00
|
|
|
this error may also be returned if
|
|
|
|
.I optlen
|
|
|
|
is not in a valid part of the process address space.
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
.I optlen
|
2007-04-12 22:42:49 +00:00
|
|
|
invalid in
|
2005-10-20 15:11:10 +00:00
|
|
|
.BR setsockopt ().
|
2008-10-28 19:01:19 +00:00
|
|
|
In some cases this error can also occur for an invalid value in
|
|
|
|
.IR optval
|
|
|
|
(e.g., for the
|
|
|
|
.B IP_ADD_MEMBERSHIP
|
|
|
|
option described in
|
|
|
|
.BR ip (7)).
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B ENOPROTOOPT
|
|
|
|
The option is unknown at the level indicated.
|
|
|
|
.TP
|
|
|
|
.B ENOTSOCK
|
|
|
|
The argument
|
2008-12-03 21:01:54 +00:00
|
|
|
.I sockfd
|
2004-11-03 13:51:07 +00:00
|
|
|
is a file, not a socket.
|
|
|
|
.SH "CONFORMING TO"
|
2007-04-12 22:42:49 +00:00
|
|
|
SVr4, 4.4BSD (these system calls first appeared in 4.2BSD),
|
2006-12-27 02:37:04 +00:00
|
|
|
POSIX.1-2001.
|
2006-08-03 13:57:17 +00:00
|
|
|
.\" SVr4 documents additional ENOMEM and ENOSR error codes, but does
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" not document the
|
2006-08-03 13:57:17 +00:00
|
|
|
.\" .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
|
|
|
|
.\" options
|
2007-05-16 02:54:18 +00:00
|
|
|
.SH NOTES
|
2007-06-10 18:08:27 +00:00
|
|
|
POSIX.1-2001 does not require the inclusion of
|
|
|
|
.IR <sys/types.h> ,
|
|
|
|
and this header file is not required on Linux.
|
|
|
|
However, some historical (BSD) implementations required this header
|
|
|
|
file, and portable applications are probably wise to include it.
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
The
|
2006-08-03 13:57:17 +00:00
|
|
|
.I optlen
|
2007-04-12 22:42:49 +00:00
|
|
|
argument of
|
2007-06-23 07:19:07 +00:00
|
|
|
.BR getsockopt ()
|
|
|
|
and
|
|
|
|
.BR setsockopt ()
|
2007-04-12 22:42:49 +00:00
|
|
|
is in reality an
|
2006-08-03 13:57:17 +00:00
|
|
|
.I "int [*]"
|
|
|
|
(and this is what 4.x BSD and libc4 and libc5 have).
|
2007-04-12 22:42:49 +00:00
|
|
|
Some POSIX confusion resulted in the present
|
|
|
|
.IR socklen_t ,
|
2006-08-03 13:57:17 +00:00
|
|
|
also used by glibc.
|
2004-11-03 13:51:07 +00:00
|
|
|
See also
|
|
|
|
.BR accept (2).
|
|
|
|
.SH BUGS
|
|
|
|
Several of the socket options should be handled at lower levels of the
|
|
|
|
system.
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR ioctl (2),
|
|
|
|
.BR socket (2),
|
|
|
|
.BR getprotoent (3),
|
|
|
|
.BR protocols (5),
|
|
|
|
.BR socket (7),
|
|
|
|
.BR tcp (7),
|
|
|
|
.BR unix (7)
|