NAME (名称)

getsockopt, setsockopt - get and set options on sockets

getsockopt, setsockopt - 获取和设置套接字的选项

SYNOPSIS(概要)

#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.

getsockopt()和setsockopt() 根据设置的选项(option) 操作 文件描述符sockfd。
操作可能处于协议层;它们总是出现在最上面的 套接字层(socket level)。

When manipulating socket options, the level at which the option resides and the name of the option must be specified. To manipulate options at the sockets API level, level is specified as SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP; see getprotoent(3).

当操作套接字选项时,必须指定 选项的级别选项的名称
在套接字接口层操作选项时,指定 levelSOL_SOCKET,这里提供了 适当的协议控制选项 的 协议号 去 操作操作其它任意层的选项;
举个栗子,如何表明一个选项 能够被理解成TCP协议,level应该被设置为TCP协议号;参考getprotoent(3)。

The arguments optval and optlen are used to access option values for setsockopt(). For getsockopt() they identify a buffer in which the value for the requested option(s) are to be returned. For getsockopt(), optlen is a value-result argument, initially containing the size of the buffer pointed to by optval, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, optval may be NULL.

参数 optvaloptlen 用于获取 setsockopt() 的选项值。
对于函数getsockopt(),它们(optvaloptlen)表示一个缓冲区,请求选项的内容将在其中返回。
对于函数getsockopt(),optlen 是一个传入传出参数,传入时指的是optval 指向的缓冲区的初始化大小,并在返回时修改以指示返回值的实际大小。
如果没有提供 或 返回 选项值,那么 optval 可能为 NULL。

Optname and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The include file <sys/socket.h> contains definitions for socket level options, described below. Options at other protocol levels vary in format and name; consult the appropriate entries in section 4 of the manual.

Optname 和任何指定的选项 未经解释地 传递给 对应协议模块 进行解释。
头文件 <sys/socket.h> 包含 套接字级别选项 的定义,如下所述。
其他协议级别的选项 在格式和名称上有所不同; 请查阅手册第 4 节中的相应条目。

Most socket-level options utilize an int argument for optval. For setsockopt(), the argument should be nonzero to enable a boolean option, or zero if the option is to be disabled.

大多数 使用 int 参数 来表示 套接字选项optval 的 等级。
对于函数setsockopt(),参数(指的应该是level)应该为非0来启用布尔选项,或者通过数值0来禁用该选项。

For a description of the available socket options see socket(7) and the appropriate protocol man pages.

有关可用套接字选项的描述,请参见 socket(7) 和相应的协议手册页。

RETURN VALUE(返回值)

On success, zero is returned for the standard options. On error, -1 is returned, and errno is set appropriately.

成功时返回0。失败时返回-1,并设置错误码。

Netfilter allows the programmer to define custom socket options with associated handlers; for such options, the return value on success is the value returned by the handler.

Netfilter 允许程序员使用相关的 处理程序(handler) 定义自定义套接字选项;
对于此类选项,成功时的返回值是 处理程序(handler) 返回的值。

ERRORS(错误)

ERRORS English DESCRIPTION 中文说明
EBADF
(Error: Bad Fd)
The argument sockfd is not a valid descriptor. 无效的参数sockfd
EFAULT
(Error: Fault)
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. optval 指向的地址不在进程地址空间的有效部分。 对于函数 getsockopt(),如果指针参数 optlen 不在进程地址空间的有效部分中,也可能返回此错误。
EINVAL
(Error: invalid)
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)). 在 setsockopt() 中 optlen 无效。 在某些情况下,optval 中的无效值也会发生此错误(例如,对于 ip(7) 中描述的 IP_ADD_MEMBERSHIP 选项)。
ENOPROTOOPT
(Error: No Protocol Option)
The option is unknown at the level indicated. 在指定的 level 上,该 option 是未知的。
ENOTSOCK The file descriptor sockfd does not refer to a socket. 输入的文件描述符sockfd并不是个套接字

CONFORMING TO(符合…)

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

NOTES(说明)

POSIX.1 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.

POSIX.1 不需要包含 <sys/types.h>,Linux 上也不需要这个头文件。
但是,一些历史 (BSD) 实现需要此头文件,并且可移植应用程序可能 明智地 包含它。

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

getsockopt() 和 setsockopt() 的 optlen 参数实际上是一个 int [*] (这就是 4.x BSD 和 libc4 和 libc5 所具有的)。
一些 POSIX 混淆? 导致了现在的 socklen_t,glibc 也使用了它。 另请参阅接受 (2)。

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), ip(7), packet(7), socket(7), tcp(7), udp(7), unix(7)

COLOPHON - Linux 2015-12-28

This page is part of release 4.04 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/.

注:上述翻译是机翻加人工修正,可能还有不理解的地方导致翻译得不是很恰当;

【man】getsockopt 和 setsockopt相关推荐

  1. getsockopt和setsockopt函数

    在Unix网络编程中通常用到getsockopt和setsockopt两个函数来获取和设置套接口的选项. getsockopt()函数用于获取任意类型.任意状态套接口的选项当前值,并把结果存入optv ...

  2. 网络编程学习笔记(getsockopt和setsockopt函数)

    其原型为: #include <sys/socket.h> int getsockopt(int sockfd, int level, int optname, void *optval, ...

  3. 套接字属性函数getsockopt和setsockopt

    套接字属性函数 int getsockopt(int sockfd,int level,int optname,void *optval,socklen_t *optlen) 功能:获得套接字属性 参 ...

  4. 全志XR806芯片 getsockopt、setsockopt失败如何解决?

    1. 问题背景 调用 setsockopt 设置 socket 属性失败,或者 getsockopt 获取 socket 属性失败. 2. 问题描述 调用 setsockopt.getsockopt ...

  5. getsockopt和setsockopt

    下面2个系统调用是专门用来读取和设置socket文件描述符属性的方法: 这2个函数成功时返回0,失败返回-1并设置errno. 看个例子,server.c #include<sys/socket ...

  6. C语言socket getsockopt() setsockopt()函数(获取和设置套接口的选项?)

    文章目录 man 文档(越看越懵逼啊!) 解释 getsockopt()函数用于获取任意类型.任意状态套接口的选项当前值,并把结果存入optval. setsockopt()函数用于任意类型.任意状态 ...

  7. TCP/IP编程之getsockopt/setsockopt函数详解

    前述: 有很多方法来获取和设置影响套接字的选项: · getsockopt和setsockopt函数 · fcntl函数,是把套接字设置为非阻塞式I/O型或者信号驱动式I/O型以及设置套接字属主的PO ...

  8. C语言socket getsockopt() setsockopt()函数(获取和设置套接口的选项?)(套接字级别SOL_SOCKET)

    文章目录 man 文档(越看越懵逼啊!) 解释 getsockopt()函数用于获取任意类型.任意状态套接口的选项当前值,并把结果存入optval. setsockopt()函数用于任意类型.任意状态 ...

  9. [精华] 讨论 Setsockopt选项

    有时候我们要控制套接字的行为(如修改缓冲区的大小),这个时候我们就要控制套接字的选项了.   以下资料均从网上收集得到 getsockopt 和 setsockopt 获得套接口选项: int get ...

最新文章

  1. javascript对象之window对象详解
  2. java将图片放进mysql中_在java代码中怎么从服务器上把图片拿来放到数据库里
  3. CentOS配置SSH单向无密码访问
  4. SAP MM Consignment 寄售库存
  5. 实训七(项目准备与创建)
  6. 透析阿里云视频云「低代码音视频工厂」之能量引擎——vPaaS视频原生应用开发平台
  7. 时尚精美电商专题首页设计PSD分层模板资源
  8. Oracle 备份shell,oracle数据库shell备份脚本
  9. C++ 字节序测试代码
  10. 【Git/Github学习笔记】Git分支管理(一)
  11. [转]RUP (From 中科永联)
  12. Android蓝牙4.0单车锁应用实例开发
  13. 诚之和:裁员、关店,贝壳内部正在发生一场博弈?
  14. 震撼!寒冬腊月里惊现多台历途外墙清洗机器人 1
  15. RMA Line stuck in AWAITING_RETURN or AWAITING_RETURN_DISPOSITION (文档 ID 378221.1)
  16. 三、Bugku----手机热点------流量分析题------obex
  17. Android 仿微信录制短视频(不使用 FFmpeg)
  18. swift 获取导航栏底部线
  19. windows记事本特别注意
  20. 5.4 控制器的功能和工作原理

热门文章

  1. 创业服务资源获取的途径有哪些?
  2. RabbitMq install on Centos6.3
  3. Java基于springboot+vue的流浪动物救助收养平台 nodejs 前后端分离
  4. Cocos2d-HTML5--人物动画
  5. 整合SEO和UEO也许才是SEOer的出路
  6. 深度剖析C语言结构体
  7. param name=robot_description command= $(find xacro)/xacro --inorder ' $(arg model)' 到底什么意思
  8. 从VirtualDom(虚拟Dom)到真实DOM
  9. 【历史上的今天】11 月 15 日:全球首款商用微处理器;微软进军游戏界;ICQ 诞生
  10. DisplayPort 端口