概述
有很多的方法来获取和设置影响套接口的选项:
。函数getsockopt, setsockopt
。函数fcntl
。函数ioctl (留到十六章讨论)
本章按以下的分类详细介绍所有套接口选项:基本,IPv4,IPv6,TCP.
函数fcntl 是设置套接口为非阻塞I/O型或信号驱动I/O型以及设置套接口的数主的Posix的方法。
#include <sys/socket.h>
int getsocketopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
int setsocketopt(int sockfd, int level, int optname, const void *optval, socklen_t *optlen);
返回:0---OK, -1----出错
这两个函数仅用于套接口。