UNIX网络编程卷一:第十七章 ioctl

ioctl函数传统上一直作为不适合归入其它精细定义类别的特性的系统借口。

POSIX致力于摆脱ioctl借口,办法是创造新的函数来取代ioctl,例如:

Unix终端接口传统上使用ioctl访问,而POSIX为终端创造了12个新函数:tcgetattr  tcflush  ....

但是,ioctl依然保留了不少功能,用于:获取接口信息、访问路由表、访问ARP高速缓存等。


网络程序(特别是服务器程序)经常在启动后使用ioctl获取所在主机全部网络接口的信息:接口地址、是否支持广播、是否支持多播等。


NAME
       ioctl - control device

SYNOPSIS
       #include <sys/ioctl.h>

       int ioctl(int d, unsigned long request, ...);

DESCRIPTION
       The  ioctl()  function  manipulates  the  underlying device parameters of special files.  In particular, many operating characteristics of character special files (e.g., terminals) may be con‐
       trolled with ioctl() requests.  The argument d must be an open file descriptor.

       The second argument is a device-dependent request code.  The third argument is an untyped pointer to memory.  It's traditionally char *argp (from the days before void * was valid C), and  will
       be so named for this discussion.

       An  ioctl()  request  has  encoded in it whether the argument is an in parameter or out parameter, and the size of the argument argp in bytes.  Macros and defines used in specifying an ioctl()
       request are located in the file <sys/ioctl.h>.

RETURN VALUE
       Usually, on success zero is returned.  A few ioctl() requests use the return value as an output parameter and return a nonnegative value on success.  On error, -1 is returned, and errno is set
       appropriately.

ERRORS
       EBADF  d is not a valid descriptor.

       EFAULT argp references an inaccessible memory area.

       EINVAL Request or argp is not valid.

       ENOTTY d is not associated with a character special device.

       ENOTTY The specified request does not apply to the kind of object that the descriptor d references.

ioctl用于操作设备,该设备的描述符由d指定。第三个参数是一个指针,指针的类型依赖于request。其中与网络相关的request如下表所示:





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值