|GETSOCKOPT(2)||Linux Programmer's Manual||GETSOCKOPT(2)|
NAMEgetsockopt, setsockopt - get and set options on sockets
#include <sys/types.h> /* See NOTES */
int getsockopt(int sockfd , int level , int optname ,
void * optval , socklen_t * optlen );
int setsockopt(int sockfd , int level , int optname ,
const void * optval , socklen_t optlen );
DESCRIPTIONgetsockopt() and setsockopt() manipulate options for the socket referred to by the file descriptor sockfd. Options may exist at multiple protocol levels; they are always present at the uppermost socket level.
For a description of the available socket options see socket(7) and the appropriate protocol man pages.
RETURN VALUEOn success, zero is returned. On error, -1 is returned, and errno is set appropriately.
- The argument sockfd is not a valid descriptor.
- The address pointed to by optval is not in a valid part of the process address space. For getsockopt(), this error may also be returned if optlen is not in a valid part of the process address space.
- optlen invalid in setsockopt(). In some cases this error can also occur for an invalid value in optval (e.g., for the IP_ADD_MEMBERSHIP option described in ip(7)).
- The option is unknown at the level indicated.
- The argument sockfd is a file, not a socket.
CONFORMING TOSVr4, 4.4BSD (these system calls first appeared in 4.2BSD), POSIX.1-2001.
NOTESPOSIX.1-2001 does not require the inclusion of <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.
BUGSSeveral of the socket options should be handled at lower levels of the system.
SEE ALSOioctl(2), socket(2), getprotoent(3), protocols(5), socket(7), tcp(7), unix(7)
COLOPHONThis page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.