ioctl(), ioctl_socket()

http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fi%2Fioctl.html

目录

Synopsis:

Arguments:

Library:

Description:

How ioctl() commands map to other commands

Commands with special handling in ioctl_socket()

Returns:

Errors:

Classification:

Caveats:

See also:


Control a device

Synopsis:

#include <sys/ioctl.h> 

int ioctl( int fd, 
           int request, 
           ... );

int ioctl_socket( int fd, 
                  int request, 
                  ... );

Arguments:

fd

An open file descriptor for the file or device that you want to manipulate.

request

What you want to do to the file or device; see below for a summary. The macros and definitions that you use in specifying a request are located in the file <sys/ioctl.h>.

Additional arguments

As required by the request.

Library:

FunctionLibraryLinking option to qcc
ioctl()libc-l c (This library is usually included automatically.)
ioctl_socket()libsocket-l socket

Description:

The ioctl() function manipulates the underlying parameters of files. In particular, it can be used to control many of the operating attributes of files (such as the attributes of terminals).

The ioctl_socket() function is an optimized version of ioctl() that provides special handling for commands that use embedded pointers (see “Commands with special handling in ioctl_socket(),” below). It uses ioctl() for commands that don't require special handling. The fd argument must be a socket for ioctl_socket().


Note:If you're using QNX Neutrino 6.4.1 or earlier, use ioctl_socket() instead of ioctl() in network applications such as packet filters.

In QNX Neutrino 6.5.0 and later, ioctl() handles embedded pointers, so you don't have to use ioctl_socket() instead.


The request argument determines whether the subsequent arguments are an “in” or “out” parameter; it also specifies the size of the arguments in bytes.

How ioctl() commands map to other commands

Some ioctl() commands map to calls to fcntl()tcgetattr()tcsetattr(), and tcsetsid(). Other commands are transformed into a different devctl() command, and the rest are simply passed to devctl(). Here's a summary:

ioctl() commandDescriptionMaps to:
FIOASYNCSet or clear asynchronous I/Ofcntl(): F_GETFL (which becomes a devctl() DCMD_ALL_GETFLAGS), followed by fcntl(): F_SETFL (which becomes a devctl() DCMD_ALL_SETFLAGS), setting or clearing O_ASYNC
FIOCLEXSet “close on exec” on a file descriptorfcntl(): F_SETFD with FD_CLOEXEC
FIOGETOWNGet the ownerfcntl(): F_GETOWN
FIONBIOSet or clear non-blocking I/Ofcntl(): F_GETFL (which becomes a devctl() DCMD_ALL_GETFLAGS), followed by fcntl(): F_SETFL (which becomes a devctl() DCMD_ALL_SETFLAGS), setting or clearing O_NONBLOCK
FIONCLEXRemove “close on exec”fcntl(): F_SETFD with ~FD_CLOEXEC
FIONREADGet the number of bytes to readdevctl(): DCMD_CHR_ISCHARS
FIOSETOWNSet the ownerfcntl(): F_SETOWN
NOSIOCGIFCONFGet ifnet listPassed to devctl()
OSIOCGIFADDRGet ifnet addressPassed to devctl()
OSIOCGIFBRDADDRGet broadcast addressPassed to devctl()
OSIOCGIFCONFGet ifnet listPassed to devctl()
OSIOCGIFDSTADDRGet point-to-point addressPassed to devctl()
OSIOCGIFNETMASKGet net address maskPassed to devctl()
SIOCADDMULTIAdd multicast addressPassed to devctl()
SIOCADDRTAdd routePassed to devctl()
SIOCAIFADDRAdd or change an interface aliasPassed to devctl()
SIOCALIFADDRAdd interface addressPassed to devctl()
SIOCATMARKAt out-of-band mark?Passed to devctl()
SIOCDARPDelete ARP entryPassed to devctl()
SIOCDELMULTIDelete multicast addressPassed to devctl()
SIOCDELRTDelete routePassed to devctl()
SIOCDIFADDRDelete interface addressPassed to devctl()
SIOCDIFPHYADDRDelete gif addressesPassed to devctl()
SIOCDLIFADDRDelete interface addressPassed to devctl()
SIOCGARPGet ARP entryPassed to devctl()
SIOCGDRVSPECGet driver-specific parametersPassed to devctl()
SIOCGETSGCNTGet the source group packet countPassed to devctl()
SIOCGETVIFCNTGet the packet count for a virtual interfacePassed to devctl()
SIOCGHIWATGet high watermarkPassed to devctl()
SIOCGIFADDRGet the interface addressPassed to devctl()
SIOCGIFALIASGet interface aliasPassed to devctl()
SIOCGIFASYNCMAPGet ppp asyncmapPassed to devctl()
SIOCGIFBRDADDRGet broadcast addressPassed to devctl()
SIOCGIFCAPGet capabilitiesPassed to devctl()
SIOCGIFCONFReturn a list of interface (transport layer) addressesPassed to devctl()
SIOCGIFDLTGet data link typePassed to devctl()
SIOCGIFDSTADDRGet point-to-point addressPassed to devctl()
SIOCGIFFLAGSGet ifnet flagsPassed to devctl()
SIOCGIFGENERICGeneric interface get opPassed to devctl()
SIOCGIFMEDIAGet net media; ioctl_socket() provides special handling for this command.Passed to devctl()
SIOCGIFMETRICGet interface metricPassed to devctl()
SIOCGIFMTUGet ifnet MTUPassed to devctl()
SIOCGIFNETMASKGet net address maskPassed to devctl()
SIOCGIFPDSTADDRGet gif pdst addressPassed to devctl()
SIOCGIFPSRCADDRGet gif psrc addressPassed to devctl()
SIOCGLIFADDRGet interface addressPassed to devctl()
SIOCGLIFPHYADDRGet gif addressesPassed to devctl()
SIOCGLOWATGet low watermarkPassed to devctl()
SIOCGPGRPGet process groupfcntl(): F_GETOWN
SIOCIFCREATECreate clone interfacePassed to devctl()
SIOCIFDESTROYDestroy clone interfacePassed to devctl()
SIOCIFGCLONERSGet cloners; ioctl_socket() provides special handling for this command.Passed to devctl()
SIOCSARPSet ARP entryPassed to devctl()
SIOCSDRVSPECSet driver-specific parametersPassed to devctl()
SIOCSHIWATSet high watermarkPassed to devctl()
SIOCSIFADDRSet ifnet addressPassed to devctl()
SIOCSIFASYNCMAPSet ppp asyncmapPassed to devctl()
SIOCSIFBRDADDRSet broadcast addressPassed to devctl()
SIOCSIFCAPSet capabilitiesPassed to devctl()
SIOCSIFDSTADDRSet point-to-point addressPassed to devctl()
SIOCSIFFLAGSSet ifnet flagsPassed to devctl()
SIOCSIFGENERICGeneric interface set opPassed to devctl()
SIOCSIFMEDIASet net mediaPassed to devctl()
SIOCSIFMETRICSet interface metricPassed to devctl()
SIOCSIFMTUSet ifnet MTUPassed to devctl()
SIOCSIFNETMASKSet net address maskPassed to devctl()
SIOCSIFPHYADDRSet gif addressPassed to devctl()
SIOCSLIFPHYADDRSet gif addressesPassed to devctl()
SIOCSLOWATSet low watermarkPassed to devctl()
SIOCSPGRPSet process groupfcntl(): F_SETOWN
TCFLSHFlush buffersPassed to devctl()
TCGETAGet the terminal's properties in a termio structuretcgetattr()
TCGETSGet the terminal's properties in a termios structuretcgetattr()
TCSBRKSend a break for a period of timedevctl() : DCMD_CHR_SERCTL
TCSETASet the terminal's propertiestcsetattr()
TCSETAFSet the terminal's properties, waiting until all currently written data has been transmitted, and discarding any received but unread datatcsetattr()
TCSETAWSet the terminal's properties, waiting until all currently written data has been transmittedtcsetattr()
TCSETSSet the terminal's properties from a termios structuredevctl() : DCMD_CHR_TCSETATTR
TCSETSFDrain the output, flush the input, and setPassed to devctl()
TCSETSWDrain output, setPassed to devctl()
TCXONCPerform a flow-control operation on a data streamdevctl(): DCMD_CHR_TCFLOW
TIOCCBRKClear the break bittcsetattr()
TIOCCDTRClear the Data Terminal Ready linedevctl() : DCMD_CHR_LINESTATUS, followed by DCMD_CHR_SERCTL
TIOCDRAINWait until output has draineddevctl(): DCMD_CHR_TCDRAIN
TIOCEXCLSet exclusive use of ttyfcntl(): F_SETLK
TIOCFLUSHFlush buffersdevctl(): DCMD_CHR_TCFLUSH
TIOCGETAGet the terminal's properties in a termios structuredevctl() : DCMD_CHR_TCGETATTR
TIOCGETCGet special characterstcgetattr()
TIOCGETPGet the terminal's parameters in a sgttyb structuretcgetattr()
TIOCGETPGRPGet the process group of the tty (POSIX)Passed to devctl()
TIOCGLTCGet local special characterstcgetattr()
TIOCGPGRPGet the process group of the ttydevctl(): DCMD_CHR_TCGETPGRP
TIOCGSIZEGet window sizedevctl(): DCMD_CHR_GETSIZE
TIOCGWINSZGet window sizedevctl(): DCMD_CHR_GETSIZE
TIOCHPCLHang up on last closetcsetattr()
TIOCLGETGet local modestcgetattr()
TIOCLSETSet entire local mode wordtcsetattr()
TIOCMBICClear modem port B interruptdevctl() : DCMD_CHR_LINESTATUS, followed by DCMD_CHR_SERCTL
TIOCMBISSet modem port B interruptdevctl() : DCMD_CHR_LINESTATUS, followed by DCMD_CHR_SERCTL
TIOCMGETSet the state of the modem linesdevctl() : DCMD_CHR_SERCTL
TIOCMSETSet all modem bitsPassed to devctl()
TIOCNOTTYMake this terminal not be the controlling terminal for the processtcsetsid()
TIOCNXCLReset exclusive use of ttyfcntl(): F_SETLK
TIOCOUTQOutput queue sizedevctl(): DCMD_CHR_OSCHARS
TIOCPKTPty: set/clear packet modePassed to devctl()
TIOCSBRKSet break bitPassed to devctl()
TIOCSCTTYMake the terminal become the controlling ttytcsetsid()
TIOCSDTRSet the Data Terminal Ready linedevctl() : DCMD_CHR_LINESTATUS, followed by DCMD_CHR_SERCTL
TIOCSETASet the terminal's properties from a termios structuredevctl() : DCMD_CHR_TCSETATTR
TIOCSETAFDrain the output, flush the input, and setdevctl(): DCMD_CHR_TCSETATTRF
TIOCSETAWDrain output, setdevctl(): DCMD_CHR_TCSETATTRD
TIOCSETCSet special characterstcsetattr()
TIOCSETNSimilar to TIOCSETP, but the changes are made immediately without discarding any data.tcsetattr()
TIOCSETPSet the terminal's parameters in a sgttyb structure. No change is made until all currently written data has been transmitted, at which point any received but unread data is discarded.tcsetattr()
TIOCSETPGRPSet the process group of the tty (POSIX)Passed to devctl()
TIOCSINUSESet exclusive use of ttyfcntl(): F_SETLK
TIOCSLTCSet local special characterstcsetattr()
TIOCSPGRPSet the process group of the ttydevctl(): DCMD_CHR_TCSETPGRP
TIOCSSIZESet the window sizedevctl(): DCMD_CHR_SETSIZE
TIOCSTARTStart output, like Ctrl-QPassed to devctl()
TIOCSTISimulate terminal inputdevctl(): DCMD_CHR_TCINJECTC
TIOCSTOPStop output, like Ctrl-SPassed to devctl()
TIOCSWINSZSet window sizedevctl(): DCMD_CHR_SETSIZE
UIOCCMDUser control operator nPassed to devctl()

Note:If you're writing a resource manager, note that the iofunc_devctl_default() function handles the DCMD_ALL_GETFLAGS and DCMD_ALL_SETFLAGS commands; your resource manager will need to handle all other devctl commands that apply to it.

Commands with special handling in ioctl_socket()

The ioctl_socket() function provides special handling for the commands listed below. Unless otherwise noted, it eventually passes the command to devctl().

These commands are for the Berkeley Packet Filter:

BIOCGDLTLIST

Get an array of the available types of the data link layer underlying the attached interface.

BIOCSETF

Set the BPF filter program.

These commands are for use with cryptography:

CIOCCRYPT

Request a symmetric-key (or unkeyed hash) operation.

CIOCGSESSION

Set up a session for symmetric crypto operations.

CIOCKEY

Perform an asymmetric crypto operation.

CRIOGET

Get a cloned file descriptor of /dev/crypto by calling open(). This isn't necessary in QNX Neutrino, but we've provided it for compatibility and portability.

The following commands are for use with the Packet Filtering interface; for more information, see the entry for pf in the Utilities Reference:

  • DIOCGETSRCNODES
  • DIOCGETSTATES
  • DIOCIGETIFACES
  • DIOCRADDADDRS
  • DIOCRADDTABLES
  • DIOCRCLRASTATS
  • DIOCRCLRTSTATS
  • DIOCRDELADDRS
  • DIOCRDELTABLES
  • DIOCRGETADDRS
  • DIOCRGETASTATS
  • DIOCRGETTABLES
  • DIOCRGETTSTATS
  • DIOCRINADEFINE
  • DIOCRSETADDRS
  • DIOCRSETTFLAGS
  • DIOCRTSTADDRS
  • DIOCXBEGIN
  • DIOCXCOMMIT
  • DIOCXROLLBACK

These commands are for use with sockets:

SIOCG80211

Get configuration or status information.

SIOCG80211NWID

Get the network ID.

SIOCG80211NWKEY

Get the values of the WEP keys.

SIOCG80211STATS, SIOCG80211ZSTATS

Get IEEE 80211 statistics.

SIOCGETVLAN

Get the vlan tag and parent for a given vlan interface.

SIOCGIFMEDIA

Get net media.

SIOCIFGCLONERS

Get cloners.

SIOCS80211

Set configuration or status information.

SIOCS80211NWID

Set the network ID.

SIOCS80211NWKEY

Set the WEP key.

SIOCSETVLAN

Set the vlan tag and parent for a given vlan interface.

Returns:

A value based on the request, or -1 if an error occurs (errno is set).

Errors:

EBADF

Invalid descriptor fd.

EINVAL

The request or optional variables aren't valid.

ENOBUFS

There wasn't enough memory available to allocate for data referred to by embedded pointers.

ENOTTY

The fd argument isn't associated with a character-special device; the specified request doesn't apply to the kind of object that the descriptor fd references.

Classification:

POSIX 1003.1 XSR

Safety: 
Cancellation pointNo
Interrupt handlerNo
Signal handlerNo
ThreadNo

Caveats:

The ioctl() function is a Unix function that varies greatly from platform to platform.

See also:

devctl()fcntl()tcgetattr()tcsetattr()tcsetsid().

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值