ioctl Socket Control Operations
来源:互联网 发布:java字符串转整型 编辑:程序博客网 时间:2024/05/22 13:45
Purpose
Performs network related control operations.
Syntax
#include <sys/ioctl.h>int ioctl (fd, cmd, .../* arg */) int fd;int cmd; int ... /* arg */
Description
The socket ioctl commands perform a variety of network-related control. The fd argument is a socket descriptor. For non-socket descriptors, the functions performed by this call are unspecified.
The cmd argument and an optional third argument (with varying type) are passed to and interpreted by the socket ioctl function to perform an appropriate control operation specified by the user.
The socket ioctl control operations can be in the following control operations categories:
- Socket
- Routing table
- ARP table
- Global network parameters
- Interface
Parameters
fdOpen file descriptor that refers to a socket created using socket or accept calls.cmdSelects the control function to be performed..../* arg */Represents additional information that is needed to perform the requested function. The type of arg depends on the particular control request, but it is either an integer or a pointer to a socket-specific data structure.Socket Control Operations
The following ioctl commands operate on sockets:
ioctl(fd, SIOCATMARK,&atmark);int atmark;
If atmark is set to 1 on return, the read pointer points to the mark and the next read returns data after the mark. Ifatmark is set to 0 on return, (assuming out-of-band data is present on the data stream), the next read returns data sent prior to the out-of-band mark.SIOCGPGRPSIOCSPGRP sets the process group information for a socket. SIOCGPGRP gets the process group ID associated with a socket.
ioctl (fd, cmd, (int)&pgrp);int pgrp;
- cmd
- Set to SIOCSPGRP or SIOCGPGRP.
- pgrp
- Specifies the process group ID for the socket.
Routing Table Control Operations
The following ioctl commands operate on the kernel routing table:
SIOCDELRTSIOCADDRT adds a route entry in the routing table. SIOCDELRT deletes a route entry from the routing table.
ioctl(fd, cmd, (caddr_t)&route);struct ortentry route;
- cmd
- Set to SIOCADDRT or SIOCDELRT.
ioctl (fd, SIOUPDROUTE, (caddr_t)&ifr);struct ifreq ifr;
ARP Table Control Operations
The following ioctl commands operate on the kernel ARP table. The net/if_arp.h header file must be included.
SIOCDARP
SIOCGARPSIOCSARP adds or modifies an ARP entry in the ARP table. SIOCDARP deletes an ARP entry from the ARP table. SIOCGARP gets an ARP entry from the ARP table.
ioctl(fd, cmd, (caddr_t)&ar);struct arpreq ar;
- cmd
- Set to SIOCSARP, SIOCDARP, or SIOCGARP.
Global Network Parameters Control Operations
The following ioctl commands operate as global network parameters:
SIOCGNETOPT
SIOCDNETOPT
SIOCGNETOPT1SIOCSNETOPT sets the value of a network option. SIOCGNETOPT gets the value of a network option. SIOCDNETOPT sets the default values of a network option.
ioctl(fd, cmd, (caddr_t)&oreq);struct optreq oreq;
- cmd
- Set to SIOCSNETOPT, SIOCGNETOPT, or SIOCDNETOPT.
SIOCGNETOPT1 gets the current value, default value, and the range of a network option.
ioctl(fd, SIOCGNETOPT1, (caddr_t)&oreq);struct optreq1 oreq;
The network option information is stored in the optreq1 structure upon return The optreq and optreq1 structures are defined in net/netopt.h.
SIOCGETMTUS
SIOCADDMTU
SIOCDELMTUSIOCGNMTUS gets the number of MTUs maintained in the list of common MTUs. SIOCADDMTU adds an MTU in the list of common MTUs. SIOCDELMTU deletes an MTU from the list of common MTUs.
ioctl(fd, cmd, (caddr_t)&nmtus);int nmtus;
- cmd
- Set to SIOCGNMTUS, SIOCADDMTU, or SIOCDELMTU.
SIOCGETMTUS gets the MTUs maintained in the list of common MTUs.
ioctl(fd, SIOCGETMTUS, (caddr_t)&gm);struct get_mtus gm;
The get_mtus structure is defined in netinet/in.h.
Interface Control Operations
The following ioctl commands operate on interfaces. The net/if.h header file must be included.
SIOCAIFADDR
SIOCDIFADDR
SIOCGIFADDRSIOCSIFADDR sets an interface address. SIOCAIFADDR adds or changes an interface address. SIOCDIFADDR deletes an interface address. The interface address is specified in the ifr.ifr_addr field. SIOCGIFADDR gets an interface address. The address is returned in the ifr.ifr_addr field.
ioctl(fd, cmd, (caddr_t)&ifr, sizeof(struct ifreq));struct ifreq ifr;
- cmd
- Set to SIOCSIFADDR, SIOCAIFADDR, SIOCDIFADDR, or SIOCGIFADDR.
ioctl (fd, SIOCGIFADDRS, (caddr_t)ifaddrsp);struct ifreqaddrs *ifaddrsp;
The interface name is passed in the ifaddrsp->ifr_name field. The addresses associated with the interface are stored in ifaddrsp->ifrasu[] array on return.SIOCGIFDSTADDRSIOCSIFDSTADDR sets the point-to-point address for an interface specified in the ifr.ifr_dstaddr field. SIOCGIFDSTADDR gets the point-to-point address associated with an interface. The address is stored in theifr.ifr_dstaddr field on return.
ioctl(fd, cmd, (caddr_t)&ifr, sizeof(struct ifreq));struct ifreq ifr;
- cmd
- Set to SIOCSIFDSTADDR or SIOCGIFDSTADDR.
SIOCGIFNETMASKSIOCSIFNETMASK sets the interface netmask specified in the ifr.ifr_addr field. SIOCGIFNETMASK gets the interface netmask.
ioctl(fd, cmd, (caddr_t)&ifr, sizeof(struct ifreq));struct ifreq ifr;
- cmd
- Set to SIOCSIFNETMASK or SIOCGIFNETMASK.
SIOCGIFBRDADDRSIOCSIFBRDADDR sets the interface broadcast address specified in the ifr.ifr_broadaddr field. SIOCGIFBRDADDR gets the interface broadcast address. The broadcast address is placed in the ifr.ifr_broadaddr field.
ioctl(fd, cmd, (caddr_t)&ifr, sizeof(struct ifreq));struct ifreq ifr;
- cmd
- Set to SIOCSIFBRDADDR or SIOCGIFBRDADDR.
ioctl(fd, cmd, (caddr_t)&ifconfsize);int ifconfsize;
SIOCGIFCONFReturns configuration information for all the interfaces configured on the system.ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc);struct ifconf ifc;
The configuration information is returned in a list of ifreq structures pointed to by the ifc.ifc_req field, with one ifreqstructure per interface.SIOCGIFFLAGSSIOCSIFFLAGS sets the interface flags. SIOCGIFFLAGS gets the interface flags.
ioctl(fd, cmd, (caddr_t)&ifr);struct ifreq ifr;
Refer to /usr/include/net/if.h for the interface flags, denoted by IFF_xxx.SIOCGIFMETRICSIOCSIFMETRIC sets the interface metric specified in the ifr.ifr_metric field. SIOCGIFMETRIC gets the interface metric. The interface metric is placed in the ifr.ifr_metric field on return.
ioctl(fd, cmd, (caddr_t)&ifr);struct ifreq ifr;
- cmd
- Set to SIOCSIFMETRIC or SIOCGIFMETRIC.
SIOCGIFSUBCHANSIOCSIFSUBCHAN sets the subchannel address specified in the ifr.ifr_flags field. SIOCGIFSUBCHAN gets the subchannel address in the ifr.ifr_flags field.
ioctl(fd, SIOCSIFSUBCHAN, (caddr_t)&ifr);struct ifreq ifr;
SIOCSIFOPTIONS SIOCGIFOPTIONSSIOCSIFOPTIONS sets the interface options. SIOCGIFOPTIONS gets the interface options.
ioctl(fd, SIOCSIFOPTIONS, (caddr_t)&ifr);struct ifreq ifr;
The interface options are stored in the ifr_flags field of the ifreq structure. Refer to /usr/include/net/if.h file for the list of interface options denoted by IFO_xxx.SIOCDELMULTISIOCADDMULTI adds an address to the list of multicast addresses for an interface. SIOCDELMULTI deletes a multicast address from the list of multicast addresses for an interface.
ioctl(fd, cmd, (caddr_t)&ifr);struct ifreq ifr;
- cmd
- Set to SIOCADDMULTI or SIOCDELMULTI.
ioctl (fd, SIOCGETVIFCNT, (caddr_t)&v_req);struct sioc_vif_req v_req;
SIOCGETSGCNTGets the packet count information for the source group specified. The information is stored in the sioc_sg_reqstructure on return.ioctl(fd, SIOCGETSGCNT, (caddr_t)&v_req);struct sioc_sg_req v_req;
SIOCSIFMTU SIOCGIFMTUSIOCSIFMTU sets the interface maximum transmission unit (MTU). SIOCGIFMTU gets the interface MTU.
ioctl(fd, cmd, (caddr_t)&ifr);struct ifreq ifr;
The MTU value is stored in ifr.ifr_mtu field.SIOCIFDETACHSIOCIFATTACH attaches an interface. This initializes and adds an interface in the network interface list. SIOCIFDETACH detaches an interface broadcast address. This removes the interface from the network interface list. The interface name is specified in the ifr.ifr_name field.
ioctl(fd, cmd, (caddr_t)&ifr);struct ifreq ifr;
SIOCSIFGIDLIST SIOCGIFGIDLISTSIOCSIFGIDLIST adds or deletes the list of group IDs specified in the ifrg.ifrg_gidlist field to the gidlist interface. The interface name is specified in the ifrg.ifrg_name field. An operation code, ADD_GRP/DEL_GRP, specified in theifrg.ifrg_gidlist field indicates whether the specified list of group IDs must be added to or deleted from the gidlistinterface. SIOCGIFGIDLIST gets the list of group IDs associated with an interface. The group IDs are placed in the ifrg.ifrg_gidlist field on return.
ioctl(fd, cmd, (caddr_t)&ifrg);struct ifgidreq ifrg;
SIOCIF_ATM_UBR SIOCIF_ATM_SNMPARP
SIOCIF_ATM_DUMPARP
SIOCIF_ATM_IDLE
SIOCIF_ATM_SVC
SIOCIF_ATM_DARP
SIOCIF_ATM_GARP
SIOCIF_ATM_SARPSIOCIF_ATM_UBR sets the UBR rate for an ATM interface.
SIOCIF_ATM_SNMPARP gets the SNMP ATM ARP entries.
SIOCIF_ATM_DUMPARP gets the specified number of ATM ARP entries.
SIOCIF_ATM_DARP deletes an ATM ARP entry from the ARP table.
SIOCIF_ATM_GARP gets an ATM ARP entry to the ARP table.
SIOCIF_ATM_SARP adds an ATM ARP entry. The ARP information is specified in the atm_arpreq structure.
SIOCIF_ATM_SVC specifies whether this interface supports Permanent Virtual Circuit (PVC) and Switched Virtual Circuit (SVC) types of virtual connections. It also specifies whether this interface will be an ARP client or an ARP server for this Logical IP Subnetwork (LIS) based on the flag set in the ifatm_svc_arg structure.
SIOCIF_ATM_IDLE specifies the idle time limit on the interface.SIOCSISNO
SIOCGISNOSIOCSISNO sets interface specific network options for an interface. SIOCGISNO gets interface specific network options associated with an interface.
ioctl(fd, cmd, (caddr_t)&ifr);struct ifreq ifr;
- cmd
- Set to SIOCSISNO or SIOCGISNO.
ioctl(fd, SIOCGIFBAUDRATE, (caddr_t)&ifr);struct ifreq ifr;
The baud rate is stored in the ifr.ifr_baudrate field.SIOCADDIFVIPA SIOCDELIFVIPA
SIOCLISTIFVIPASIOCADDIFVIPA associates the specified list of interfaces pointed to by ifrv.ifrv_ifname with the virtual interface specified by ifrv.ifrv_name. This causes the source address for all outgoing packets on these interfaces to be set to the virtual interface address.
SIOCDELIFVIPA removes the list of specified interfaces pointed to by ifrv.ifrv_ifname, that are associated with the virtual interface specified by ifrv.ifrv_name, using SIOCADDIFVIPA.
SIOCLISTIFVIPA lists all the interfaces associated with the virtual interface specified by ifrv.ifrv_name.
ioctl(fd, SIOCADDIFVIPA, (caddr_t)&ifrv);struct ifvireq ifrv;
The virtual interface information is stored in the ifvireq structure.ioctl(fd, SIOCSIFADDR6, (caddr_t)&ifr);struct in6_ifreq ifr;
SIOCGIFADDR6Gets an IPv6 address.ioctl(fd, SIOCGIFADDR6, (caddr_t)&ifr);struct in6_ifreq ifr;
SIOCSIFDSTADDR6Set the destination (point-to-point) address for a IPv6 address.ioctl(fd, SIOCSIFDSTADDR6, (caddr_t)&ifr);struct in6_ifreq ifr;
SIOCGIFDSTADDR6Get the destination (point-to-point) address for a IPv6 address.ioctl(fd, SIOCGIFDSTADDR6, (caddr_t)&ifr);struct in6_ifreq ifr;
SIOCSIFNETMASK6Set the netmask for an IPv6 address as specified in the ifr.ifr_Addr structure.ioctl(fd, SIOCSIFNETMASK6, (caddr_t)&ifr);struct in6_ifreq ifr;
SIOCGIFNETMASK6Get the netmask for an IPv6 address as specified in the ifr.ifr_Addr structure.ioctl(fd, SIOCGIFNETMASK6, (caddr_t)&ifr);struct in6_ifreq ifr;
ioctl(fd, SIOCDIFADDR6, (caddr_t)&ifr);struct in6_ifreq ifr;
SIOCFIFADDR6Put an IPv6 address at the beginning of the address list.ioctl(fd, SIOCFIFADDR6, (caddr_t)&ifr);struct in6_ifreq ifr;
SIOCAIFADDR6Add or change an IPv6 alias address.ioctl(fd, SIOCAIFADDR6, (caddr_t)&ifra);struct in6_aliasreq ifra;
SIOCADDANY6Add an IPv6 anycast address.ioctl(fd, SIOCADDANY6, (caddr_t)&ifra);struct in6_ifreq ifr;
SIOCDELANY6Delete an IPv6 anycast address.ioctl(fd, SIOCDELANY6, (caddr_t)&ifra);struct in6_ifreq ifr;
SIOCSIFZONE6Set the IPv6 zone ID of an interface at a particular address scope.ioctl(fd, SIOCSIFZONE6, (caddr_t)&ifrz);struct in6_zonereq ifrz;
SIOCGIFZONE6Get the IPv6 scope zone IDs of an interface.ioctl(fd, SIOCGIFZONE6, (caddr_t)&ifrz);struct in6_zonereq ifrz;
SIOCSIFADDRORI6Set the configuration origin for an IPv6 address.ioctl(fd, SIOCSIFADDRORI6, (caddr_t)&ifro);struct ifaddrorigin6 ifro;
SIOCAIFADDR6TAdd or change an IPv6 alias address and type.ioctl(fd, SIOCAIFADDR6T, (caddr_t)&ifra);struct in6_aliasreq2 ifra;
SIOCGIFADDR6TGet the type of an IPv6 address.ioctl(fd, SIOCGIFADDR6T, (caddr_t)&ifra);struct in6_aliasreq2 ifra;
SIOCSIFADDRSTATE6Change the state of an IPv6 address.ioctl(fd, SIOCSIFADDRSTATE6, (caddr_t)&ifra);struct in6_aliasreq2 ifra;
SIOCGIFADDRSTATE6Get the state of an IPv6 address.ioctl(fd, SIOCGIFADDRSTATE6, (caddr_t)&ifra);struct in6_aliasreq2 ifra;
SIOCGSRCFILTER6Get the IPv6 multicast group source filter for an interface.ioctl(fd, SIOCGSRCFILTER6, (caddr_t)&ifrgsf);struct group_source_filter_req ifrgsf;
SIOCACLADDR6Add an IPv6 cluster alias address.ioctl(fd, SIOCACLADDR6, (caddr_t)&ifra);struct in6_aliasreq ifra;
SIOCDCLADDR6Delete an IPv6 cluster address.ioctl(fd, SIOCDCLADDR6, (caddr_t)&ifr);struct in6_ifreq ifr;
SIOCSIFADDRFLAG6Set address source flag for an IPv6 address.ioctl(fd, SIOCSIFADDRFLAG6, (caddr_t)&ifra2);struct in6_aliasreq2 ifra2;
SIOCGIFADDRFLAG6Get address source flag for an IPv6 address.ioctl(fd, SIOCGIFADDRFLAG6, (caddr_t)&ifra2);struct in6_aliasreq2 ifra2;
Return Values
Upon successful completion, ioctl returns 0. Otherwise, it returns -1 and sets errno to indicate the error.
Error Codes
The ioctl commands fail under the following general conditions:
EBADFThe file descriptor fd is not a valid open socket file descriptor.EINTRA signal was caught during ioctl operation.EINVALAn invalid command or argument was specified.If the underlying operation specified by the ioctl command cmd failed, ioctl fails with one of the following error codes:
EACCESPermission denied for the specified operation.EADDRNOTAVAILSpecified address not available for interface.EAFNOSUPPORTOperation not supported on sockets.EBUSYResource is busy.EEXISTAn entry or file already exists.EFAULTArgument references an inaccessible memory area.EIOI/O error.ENETUNREACHGateway unreachable.ENOBUFSRouting table overflow.ENOCONNECTNo connection.ENOMEMNot enough memory available.ENOTCONNThe operation is only defined on a connected socket, but the socket was not connected.ENXIODevice does not exist.ESRCHNo such process.----
====
http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.commtechref%2Fdoc%2Fcommtrf2%2Fioctl_socket_control_operations.htm
- ioctl Socket Control Operations
- ioctl Operations
- input/output control --- ioctl
- fcntl.h(File control operations)
- ioctl 以及socket
- normal socket ioctl to net interface ioctl
- normal socket ioctl to net interface ioctl
- Android - some basic control & resource operations
- Memory Barriers Are Like Source Control Operations
- ioctl 设置非阻塞SOCKET函数
- 网口插拔,调用标准的socket IOCTL失败.
- ioctl 设置非阻塞SOCKET函数
- socket和IOCTL结合实现网络采集
- socket网络编程中的ioctl()函数
- Operations
- socket ioctl socket options struct ifreq; struct ifconf
- ioctl
- ioctl
- 设计模式——备忘录模式(Memento)
- Java图形界面汉诺塔
- 结构体如何使用NSData包装
- linux基础之使用异步 I/O 大大提高应用程序的性能 学习何时以及如何使用 POSIX AIO API
- 开发随笔-.net ThreadPool
- ioctl Socket Control Operations
- 辗转相除
- C#访问PostGreSQL数据库
- Linux下的多进程编程初步
- 1716. Houses (邻接矩阵)
- IE8下struts2 采用ajax提交表单,返回json字符串,解析不了,直接保存json字符串。提示下载action.
- 温故知新 javascript 正则表达式
- nginx + PHP 下 https的设置。
- 杭电 1384 差分约束