Setsocketopt getsocketopt Comparison Full parameter description

Source: Internet
Author: User
Tags socket error

These socket options can is set by usingsetsockopt(2) and read withgetsockopt(2) With the socket level set toSol_socketFor all sockets:So_acceptconnReturns a value indicating whether or not this socket has been marked to accept withListen(). The value 0 indicates that this is not a listening socket, the value 1 indicates to this is a listening socket. Can only being read withgetsockopt().So_bsdcompatEnable BSD bug-to-bug compatibility. This is used by the UDP Protocol module in Linux 2.0 and 2.2. If enabled ICMP errors received for a UDP socket won't be passed to the user program. In later kernel versions, support for this option has been phased out:linux 2.4 silently it, and Linux ignores 2.6 TES a kernel Warning (PRINTK ()) If a program uses this option. Linux 2.0 also enabled BSD bug-to-bug compatibility options (random header changing, skipping of the broadcast flag) for R AW sockets with this option, but that is removed in Linux 2.2.So_bindtodeviceBind this socket to a particular device like "eth0", as specified in the passed interface name. If the name is a empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-length null terminated interface name string with the maximum size ofIfnamsiz. If a socket is bound to a interface, only packets received from that particular interface are processed by the socket. This is only works for some socket types, particularlyaf_inetSockets. It isn't supported for packet sockets (use normalBind(8) there).So_broadcastSet or get the broadcast flag. When enabled, datagram sockets receive packets sent to a broadcast address and they are to send allowed to a packets Cast address. This option has no effect on stream-oriented sockets.So_debugEnable socket debugging. Only allowed for processes with theCap_net_adminCapability or an effective user ID of 0.So_errorGet and clear the pending socket error. Only valid as agetsockopt(). expects an integer.So_dontrouteDon ' t send via Gateway A, only send to directly connected hosts. The same effect can be achieved by setting theMsg_dontrouteFlag on a socketSend(2) operation. Expects an integer boolean flag.so_keepaliveEnable sending of keep-alive messages on connection-oriented sockets. Expects an integer boolean flag.So_lingerSets or gets theSo_lingerOption. The argument is a linger structure.

struct Linger {
    int l_onoff;    /* Linger Active *
    /int l_linger;   /* How many seconds to linger for *
/};
When enabled, a Close(2) or shutdown(2) won't return until all queued messages for the socket have been successfully sent or the linger timeout has been re ached. Otherwise, the call returns immediately and the closing are done in the background. When the ' is ' closed as part of Exit(2), it always lingers in the background. So_oobinlineIf This option is enabled, the Out-of-band data are directly placed into the receive data stream. Otherwise out-of-band data is only passed the Msg_oobFlag is set during receiving. so_passcredEnable or disable the receiving of the scm_credentialsControl message. For more information Unix(7). so_peercredReturn the credentials of the foreign process connected to this socket. This is the possible for connected Pf_unixStream sockets and Pf_unixStream and datagram socket pairs created using Socketpair(2); The Unix(7). The returned credentials are those that were in effect at the Connect(2) or Socketpair(2). Argument is a ucred structure. Only valid as a getsockopt(). so_prioritySet the protocol-defined priority for all packets to is sent on this socket. Linux uses this value to order the networking queues:packets with a higher priority may is processed the He selected device queueing discipline. For IP(7), this is also sets the IP type-of-service (TOS) field for outgoing packets. Setting a priority outside the range 0 to 6 requires the Cap_net_adminCapability. So_rcvlowatand So_sndlowatSpecify the minimum number of bytes in the buffer until the socket layer would pass the data to the Protocol ( So_sndlowat) or the user on receiving ( So_rcvlowat). These two values are initialised to 1. So_sndlowatIs isn't changeable on Linux ( setsockoptFails with the error enoprotoopt). So_rcvlowatis changeable only since Linux 2.4. The Select(2) and Poll(2) system calls currently does not respect the So_rcvlowatsetting on Linux, and mark a socket readable when even a single byte of the data is available. A subsequent read from the socket would block until So_rcvlowatBytes are available. So_rcvtimeoand So_sndtimeoSpecify the receiving or sending timeouts until reporting an error. The parameter is a struct timeval. If an input or output function blocks for this period of time, and data has been sent or received, the return value of tha t function would be the amount of data transferred; If no data has been transferred and the timeout has been reached then-1 are returned with errno set to Eagain or Ewouldblo CK just as if the socket was specified to be nonblocking. If The timeout is set to zero (the default) then the operation would never timeout. So_rcvbufSets or gets the maximum socket receive buffer in bytes. The kernel doubles this value (to allow spaces for bookkeeping overhead) when it is set using setsockopt(), and this doubled the value is returned by getsockopt(). The default value is set by the Rmem_defaultSysctl and the maximum allowed value is set by the Rmem_maxSysctl. The minimum (doubled) value is 256. So_rcvbufforce(Since Linux 2.6.14 )Using This socket option, a privileged ( Cap_net_admin) process can perform the same task as So_rcvbuf, but the Rmem_maxLimit can be overridden. so_reuseaddrIndicates that's rules used in validating addresses supplied in a Bind(2) Call should allow reuse of the local addresses. For pf_inetSockets This means that a socket could bind, except when there be an active listening socket bound to the address. When the listening socket was bound to Inaddr_anyWith a specific port then it isn't possible to bind to the to. So_sndbufSets or gets the maximum socket send buffer in bytes. The kernel doubles this value (to allow spaces for bookkeeping overhead) when it is set using setsockopt(), and this doubled the value is returned by getsockopt(). The default value is set by the Wmem_defaultSysctl and the maximum allowed value is set by the Wmem_maxSysctl. The minimum (doubled) value is 2048. So_sndbufforce(Since Linux 2.6.14 )Using This socket option, a privileged ( Cap_net_admin) process can perform the same task as So_sndbuf, but the Wmem_maxLimit can be overridden. So_timestampEnable or disable the receiving of the So_timestampControl message. The timestamp control message was sent with level Sol_socketAnd the Cmsg_data field is a struct timeval indicating the reception time of the ' last packet passed to the ' user in this CA LL. cmsg(3) for the details on control messages. So_typeGets the socket type as an integer (like Sock_stream). Can only being read with getsockopt().

Reference articles:

Http://linux.die.net/man/7/socket

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.