📄 syscalls_49.html
字号:
<!-- This HTML file has been created by texi2html 1.29
from syscalls.texi on 4 June 1994 -->
<TITLE>Syscall specifications of Linux - getsockopt</TITLE>
<P>Go to the <A HREF="syscalls_48.html" tppabs="http://personal.xfol.com/%7erezaie/syscall/syscalls_48.html">previous</A>, <A HREF="syscalls_50.html" tppabs="http://personal.xfol.com/%7erezaie/syscall/syscalls_50.html">next</A> section.<P>
<H2><A NAME="SEC49" HREF="syscalls_toc.html#SEC49" tppabs="http://personal.xfol.com/%7erezaie/syscall/syscalls_toc.html#SEC49">getsockopt</A></H2>
<P>
<H3>SYNOPSIS</H3>
<P>
<CODE>int getsockopt(int <VAR>s</VAR>, int <VAR>level</VAR>, int <VAR>optname</VAR>,
void *<VAR>optval</VAR>, int *<VAR>optlen</VAR>);</CODE>
<P>
<CODE>int setsockopt(int <VAR>s</VAR>, int <VAR>level</VAR>, int <VAR>optname</VAR>,
const void *<VAR>optval</VAR>, int <VAR>optlen</VAR>);</CODE>
<P>
<H3>PARAMETERS</H3>
<P>
<VAR>s</VAR>: [in] the socket we want to work on.
<P>
<VAR>level</VAR>: [in] the protocol level to access.
<P>
<VAR>optname</VAR>: [in] the option to access.
<P>
<VAR>optval</VAR>: for <CODE>getsockopt</CODE>, [out] points to the buffer where to
save the option value. For <CODE>setsockopt</CODE>, [in] points to the buffer
containing the new option value.
<P>
<VAR>optlen</VAR>: for <CODE>getsockopt</CODE>, [in out] on entry, the maximum
length of <VAR>optval</VAR>, on return, the actual length of the option. For
<CODE>setsockopt</CODE>, the length of the new option.
<P>
<H3>DESCRIPTION</H3>
<P>
The possible values of <VAR>level</VAR> are <VAR>SOL_SOCKET</VAR> and any valid
protocol number. At socket level, a value of zero for the options is
boolean flase and a non-zero value is boolean true. The following
options are recognized at socket level:
<P>
<DL COMPACT>
<DT><CODE>SO_DEBUG</CODE>
<DD>Enable/disable the recording of the debug information by the underliying
protocol modules. <VAR>optval</VAR> is an boolean value (int).
<P>
<DT><CODE>SO_REUSEADDR</CODE>
<DD>Enable/disable local address reuse so that a <CODE>bind</CODE> call can reuse
old addresses. <VAR>optval</VAR> is a boolean value (int).
<P>
<DT><CODE>SO_KEEPALIVE</CODE>
<DD>Enable/disable the "keep connections alive" feature. Using this feature,
periodic messages are sent to the remote connection. If the peer machine
does not respond to those messages, the connection is broken and the
processes using the socket receive a <CODE>SIGPIPE</CODE> signal. <VAR>optval</VAR>
is a boolean value (int).
<P>
<DT><CODE>SO_DONTROUTE</CODE>
<DD>Enable/disable the routing bypass for outgoing message. If enabled, the
socket completely bypass the routing facilities of the operating
system. <VAR>optval</VAR> is a boolean value (int).
<P>
<DT><CODE>SO_LINGER</CODE>
<DD>Linger on close if data present. Without this feature, a <CODE>close</CODE> on
a socket is always performed in a quick non-blocking fashion. However,
when this feature is enabled, the <CODE>close</CODE> call will block for a
while if the socket still has data enqueued on the send queue. The call
will block until it is able to send the data or if a specified timeout
value expire. <VAR>optval</VAR> is a <CODE>struct linger</CODE> structure.
<P>
<DT><CODE>SO_BROADCAST</CODE>
<DD>Enable/disable the permission of broadcasting packets. <VAR>optval</VAR> is a
boolean value (int).
<P>
<DT><CODE>SO_OOBINLINE</CODE>
<DD>Enable/disable the reception of out-of-band data as in band data.
<VAR>optval</VAR> is a boolean value (int).
<P>
<DT><CODE>SO_SNDBUF</CODE>
<DD>Set the buffer size for output. <VAR>optval</VAR> is an int.
<P>
<DT><CODE>SO_RCVBUF</CODE>
<DD>Set the buffer size for input. <VAR>optval</VAR> is an int.
<P>
<DT><CODE>SO_SNDLOWAT</CODE>
<DD>Set minimum count for output. This count is the mininum number of bytes
that must be stored in the send buffer before actually sending them on
the network. <VAR>optval</VAR> is an int.
<P>
<DT><CODE>SO_RCVLOWAT</CODE>
<DD>Set minimum count for input. This count is the mininum number of bytes
that must be received in the receive buffer before returning from a call
reading from the socket. <VAR>optval</VAR> is an int.
<P>
<DT><CODE>SO_SNDTIMEO</CODE>
<DD>Set timeout for output calls. <VAR>optval</VAR> is an <CODE>struct timeval</CODE>.
<P>
<DT><CODE>SO_RCVTIMEO</CODE>
<DD>Set timeout for input calls. <VAR>optval</VAR> is an <CODE>struct timeval</CODE>.
<P>
<DT><CODE>SO_TYPE</CODE>
<DD>For <CODE>getsockopt</CODE> only: get the type of socket. <VAR>optval</VAR> is an int.
<P>
<DT><CODE>SO_TYPE</CODE>
<DD>For <CODE>getsockopt</CODE> only: get the last error on the socket.
<VAR>optval</VAR> is an int.
</DL>
<P>
<H3>RETURN VALUE</H3>
<P>
On success zero is returned. On error, -1 is returned and <CODE>errno</CODE> is
set to one of the following values:
<P>
<UL>
<LI><CODE>ENOPROTOOPT</CODE>: the option is not valid for the protocol specified.
<P>
<LI><CODE>EBADF</CODE>, <CODE>ENOTSOCK</CODE> and <CODE>EFAULT</CODE>.
</UL>
<P>
<P>Go to the <A HREF="syscalls_48.html" tppabs="http://personal.xfol.com/%7erezaie/syscall/syscalls_48.html">previous</A>, <A HREF="syscalls_50.html" tppabs="http://personal.xfol.com/%7erezaie/syscall/syscalls_50.html">next</A> section.<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -