栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

linux C语言 ioctl()函数(修改socket

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux C语言 ioctl()函数(修改socket

文章目录
    • man 2 文档

man 2 文档
IOCTL(2)                                                             Linux Programmer's Manual                                                            IOCTL(2)

NAME
       ioctl - control device

SYNOPSIS
       #include 

       int ioctl(int fd, 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 controlled with ioctl() requests.  The argument fd must be an open file descriptor.
       //ioctl() 函数操作特殊文件的底层设备参数。 
       //特别是,字符特殊文件(例如终端)的许多操作特性可以通过 ioctl() 请求进行控制。 
       //参数 fd 必须是打开的文件描述符。

       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.
       //第二个参数是设备相关的请求代码。 
       //第三个参数是指向内存的无类型指针。 
       //传统上它是 char *argp (从 void * 是有效 C 之前的日子开始),并且将在本次讨论中如此命名。

       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 .
       //ioctl() 请求已在其中编码,无论参数是输入参数还是输出参数,以及参数 argp 的大小(以字节为单位)。 
       //用于指定 ioctl() 请求的宏和定义位于文件  中。

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.
       //通常,成功时返回零。 
       //一些 ioctl() 请求使用返回值作为输出参数,并在成功时返回一个非负值。 
       //出错时,返回 -1,并适当设置 errno。

ERRORS
       EBADF  fd is not a valid descriptor.	
       			//fd 不是有效的描述符。

       EFAULT argp references an inaccessible memory area.
       			//argp 引用了一个不可访问的内存区域。

       EINVAL request or argp is not valid.
       			//请求或 argp 无效。

       ENOTTY fd is not associated with a character special device.
       			//fd 不与字符特殊设备相关联。

       ENOTTY The specified request does not apply to the kind of object that the descriptor fd references.
       			//指定的请求不适用于描述符 fd 引用的对象类型。


可以设置socket_fd状态阻塞或非阻塞,参考文章:KYSL socket卡住问题(connect()函数阻塞)解决方案:ioctl()设置socket_fd为非阻塞的,connect()之后用select()+getsockopt()判断

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/867395.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号