table of contents
other versions
- wheezy 3.44-1
- jessie 3.74-1
- jessie-backports 4.10-2~bpo8+1
- testing 4.10-2
- unstable 4.10-2
other sections
GETSOCKOPT(2) | Linux Programmer's Manual | GETSOCKOPT(2) |
NAME¶
getsockopt, setsockopt - get and set options on socketsSYNOPSIS¶
#include <sys/types.h> /* See NOTES */#include <sys/socket.h>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);
DESCRIPTION¶
getsockopt() 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.RETURN VALUE¶
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.ERRORS¶
- EBADF
- The argument sockfd is not a valid descriptor.
- EFAULT
- 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.
- EINVAL
- 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)).
- ENOPROTOOPT
- The option is unknown at the level indicated.
- ENOTSOCK
- The argument sockfd is a file, not a socket.
CONFORMING TO¶
SVr4, 4.4BSD (these system calls first appeared in 4.2BSD), POSIX.1-2001.NOTES¶
POSIX.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.BUGS¶
Several of the socket options should be handled at lower levels of the system.SEE ALSO¶
ioctl(2), socket(2), getprotoent(3), protocols(5), socket(7), tcp(7), unix(7)COLOPHON¶
This page is part of release 3.44 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/.2008-12-03 | Linux |