1GETSOCKOPT(2)              Linux Programmer's Manual             GETSOCKOPT(2)
2
3
4

NAME

6       getsockopt, setsockopt - get and set options on sockets
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/socket.h>
11
12
13       int  getsockopt(int  s, int level, int optname, void *optval, socklen_t
14       *optlen);
15
16       int setsockopt(int s, int  level,  int  optname,  const  void  *optval,
17       socklen_t optlen);
18

DESCRIPTION

20       getsockopt()  and setsockopt() manipulate the options associated with a
21       socket.  Options may exist at multiple protocol levels; they are always
22       present at the uppermost socket level.
23
24       When  manipulating socket options the level at which the option resides
25       and the name of the option must be specified.  To manipulate options at
26       the  socket  level,  level  is  specified as SOL_SOCKET.  To manipulate
27       options at any other level the protocol number of the appropriate  pro‐
28       tocol  controlling  the  option  is supplied.  For example, to indicate
29       that an option is to be interpreted by the TCP protocol,  level  should
30       be set to the protocol number of TCP; see getprotoent(3).
31
32       The  parameters  optval and optlen are used to access option values for
33       setsockopt().  For getsockopt() they identify a  buffer  in  which  the
34       value  for  the  requested  option(s) are to be returned.  For getsock‐
35       opt(), optlen is a value-result  parameter,  initially  containing  the
36       size  of  the  buffer  pointed  to by optval, and modified on return to
37       indicate the actual size of the value returned.  If no option value  is
38       to be supplied or returned, optval may be NULL.
39
40       Optname  and  any  specified  options  are  passed uninterpreted to the
41       appropriate protocol  module  for  interpretation.   The  include  file
42       <sys/socket.h> contains definitions for socket level options, described
43       below.  Options at other protocol levels vary in format and name;  con‐
44       sult the appropriate entries in section 4 of the manual.
45
46       Most  socket-level  options  utilize  an int parameter for optval.  For
47       setsockopt(), the parameter should be  non-zero  to  enable  a  boolean
48       option, or zero if the option is to be disabled.
49
50
51       For a description of the available socket options see socket(7) and the
52       appropriate protocol man pages.
53
54

RETURN VALUE

56       On success, zero is returned.  On error, -1 is returned, and  errno  is
57       set appropriately.
58

ERRORS

60       EBADF     The argument s is not a valid descriptor.
61
62       EFAULT    The  address  pointed  to by optval is not in a valid part of
63                 the process address space.  For getsockopt(), this error  may
64                 also  be  returned  if  optlen  is not in a valid part of the
65                 process address space.
66
67       EINVAL    optlen invalid in setsockopt().
68
69       ENOPROTOOPT
70                 The option is unknown at the level indicated.
71
72       ENOTSOCK  The argument s is a file, not a socket.
73

CONFORMING TO

75       SVr4,  4.4BSD  (these  system  calls   first   appeared   in   4.2BSD),
76       POSIX.1-2001.
77

NOTE

79       The  optlen  argument of getsockopt and setsockopt is in reality an int
80       [*] (and this is what 4.x BSD and libc4 and libc5  have).   Some  POSIX
81       confusion  resulted  in the present socklen_t, also used by glibc.  See
82       also accept(2).
83

BUGS

85       Several of the socket options should be handled at lower levels of  the
86       system.
87

SEE ALSO

89       ioctl(2),  socket(2),  getprotoent(3), protocols(5), socket(7), tcp(7),
90       unix(7)
91
92
93
94Linux Man Page                    1999-05-24                     GETSOCKOPT(2)
Impressum