Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
#include <sys/ioctl.h>
int ioctl(int fildes int cmd, ... /* arg */);
#define _XOPEN_SOURCE_EXTENDED 1
/** OR **/
#define _OE_SOCKETS
#include <sys/ioctl.h>
#include <net/rtrouteh.h>
#include <net/if.h>
int ioctl(int fildes, int cmd, ... /* arg */);
#define _XOPEN_SOURCE_EXTENDED 1
#include <stropts.h>
int ioctl(int fildes int cmd, ... /* arg */);
ioctl() performs a variety of control functions on devices. The cmd argument and an optional third argument (with varying type) are passed to and interpreted by the device associated with fildes.
The cmd argument selects the control function to be performed and will depend on the device being addressed.
The arg argument represents additional information that is needed by this specific device to perform the requested function. The type of arg depends upon the particular control request, but it is either an integer or a pointer to a device-specific data structure.
FIOGETOWN and FIOSETOWN are equivalent to the F_GETOWN and F_SETOWN commands of fctl(). For information on the values for pid, refer to that function. This function is only valid for AF_INET stream sockets.
Gets the network interface address. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface address is returned in the argument. This option is valid only for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
Gets the network interface broadcast address. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface broadcast address is returned in the argument. This option is valid only for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
Gets the network interface configuration. arg is a pointer to an ifconf structure, as defined in <net/if.h>. The interface configuration is returned in the buffer pointed to by the ifconf structure. The returned data's length is returned in the field that had originally contained the length of the buffer. This option is valid only for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
To request OSM interfaces, the application must have READ authorization to the EZB.OSM.sysname.tcpname resource.
A struct __net_ifconf6header_s is passed as the argument of the ioctl. This structure specifies the buffer where the configuration information is to be written and is returned with the number of entries and entry length of each struct, and __net_ifconf6entry_s that was written to the output buffer. These structures are defined in <sys/ioctl.h>.
If __nif6h_buflen and __nif6h_buffer are both zero, a query function is performed and the header is returned with:
errno = ERANGE, or
errno = EINVAL and __nif6h_version has changed
The call
was converted into a query function and the header has been filled
in as described above. In these cases, the content of the output buffer
is undefined.If Common INET is configured and multiple TCP/IP stacks are attached to the socket, the output from each stack that is enabled for IPv6 will be concatenated in the output buffer and the header will contain the total number of entries returned from all the stacks. The version returned with the query function will be the highest version supported by all the stacks.
This ioctl can be issued on an AF_INET or AF_INET6 socket.
Gets the network interface destination address. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface destination (point-to-point) address is returned in the argument. This option is valid only for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
Gets the network interface flags. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface flags are returned in the argument. This option is valid only for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
Gets the network interface routing metric. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface routing metric is returned in the argument. This option is valid only for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
Gets the network interface MTU (maximum transmission unit). arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface MTU is returned in the argument, arg->ifr_mtu. This option is only valid for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
Gets the network interface network mask. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface network mask is returned in the argument. This option is valid only for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
sysplexFqDnData structure contains server name(input), group name(input) and fully qualified domain name(output).
#include <ezbzsdnc.h>
sysplexFqDn splxFqDn;
sysplexFqDnData splxData;
int rc;
splxFqDn.splxVersion = splxDataVersion;
splxFqDn.splxBufLen = sizeof(sysplexFqDnData);
splxFqDn.splxBufAddr = &splxData;
/* Assign values to splxData.groupName, */
/* splxData.serverName if required */
.
.
/* Get the fully qualified domain name */
rc = ioctl(s,SIOCGSPLXFQDN, (char *) &splxFqDn);
/* splxData.domainName contains the fully*/
/* qualified domain name. */
Used to SET or GET the security environment for a server socket. arg points to a struct __seco_s where element __seco_argument is set to 1 for a SET and 2 for a GET request.
When used with the SET argument, the AF_UNIX stream socket server will designate the server socket as one that requires the full security environment of the connecting client to be available before the connect will complete successfully. During connect processing, connect obtains the security environment of the connector and anchors it off the connector's socket for use by the server. If the security environment cannot be obtained during connect processing, the connect will fail. This command has no effect on sockets that do not become server sockets.
When used with the GET argument, the AF_UNIX stream socket server will copy the previously SET security environment from the connector's address space to the server's address space so it can be used as input on calls to the security product. This command has meaning only for server sockets that previously issued SIOCSECENVR with the SET argument.
Sets the network interface routing metric. arg is a pointer to an ifreq structure, as defined in <net/if.h>. SIOCSIFMETRIC sets the interface routing metric to the value passed in the argument. This option is valid only for the AF_INET domain.
This macro is protected by the _OPEN_SYS_IF_EXT feature.
Special behavior for C++: To use this function with C++, you must use the _XOPEN_SOURCE_EXTENDED 1 feature test macro.
If successful, ioctl() returns 0.
int s;
int dontblock;
int rc;
⋮
/* Place the socket into nonblocking mode */
dontblock = 1;
rc = ioctl(s, FIONBIO, (
char *) &dontblock);
⋮
If arg is 0, the calling process will be unregistered and will not receive further SIGPOLL signals for the STREAM associated with fildes.
Processes that wish to receive SIGPOLL signals must explicitly register to receive them using I_SETSIG. If several processes register to receive this signal for the same event on the same STREAM, each process will be signaled when the event occurs.
The maxlen member in the ctlbuf and databuf strbuf structure must be set to the number of bytes of control information and/or data information, respectively, to retrieve. The flags member may be marked RS_HIPRI or 0, as described by getmsg() - getpmsg(). If the process sets flags to RS_HIPRI, for example, I_PEEK will only look for a high-priority message on the STREAM head read queue.
I_PEEK returns 1 if a message was retrieved, and returns 0 if no message was found on the STREAM head read queue, or if the RS_HIPFI flag was set in flags and a high-priority message was not present on the STREAM head read queue. It does not wait for a message to arrive. On return, ctlbuf specifies information in the control buffer, databuf specifies information in the data buffer, and flags contains the value RS_HIPRI or 0.
The bitwise inclusive-OR of RMSGD and RMSGN will return EINVAL. The bitwise inclusive-OR of RNORM and either RMSGD or RMSGN will result in the other flag overriding RNORM which is the default.
The len member in the ctlbuf strbuf structure must be set to the size of a pointer plus the number of bytes of control information to be sent with the message. The fildes member specifies the file descriptor of the other STREAM, and the offset member, which must be suitably aligned for use as a pointer, specifies the offset from the start of the control buffer where I_FDINSERT will store a pointer whose interpretation is specific to the STREAM end. The len member in the databuf strbuf structure must be set to the number of bytes of data information to be sent with the message, or 0 if no data part is to be sent.
The flags member specifies the type of message to be created. A normal message is created if flags is set to 0, and a high-priority message is created if flags is set to RS_HIPRI. For non-priority messages, I_FDINSERT will block if the STREAM write queue is full due to internal flow control conditions. For priority messages, I_FDINSERT does not block on this condition. For non-priority messages, I_FDINSERT does not block when the write queue is full and O_NONBLOCK is set. Instead, it fails and sets errno to EAGAIN.
I_FDINSERT also blocks, unless prevented by lack of internal resources, waiting for the availability of message blocks in the STREAM, regardless of priority or whether O_NONBLOCK has been specified. No partial message is sent.
This mechanism is provided to send ioctl() requests to downstream modules and drivers. It allows information to be sent with ioctl(), and returns to the process any information sent upstream by the downstream recipient. I_STR blocks until the system responds with either a positive or negative acknowledgement message, or until the request "times out" after some period of time. If the request times out, it fails with errno set to ETIME.
At most, one I_STR can be active on a STREAM. Further I_STR calls will block until the active I_STR completes at the STREAM head. The default timeout interval for these requests is 15 seconds. The O_NONBLOCK flag has no effect on this call.
To send requests downstream, arg must point to a strioctl structure.
The ic_cmd member is the internal ioctl() command intended for a downstream module or driver and ic_timeout is the number of seconds (-1 = infinite, 0 = use implementation-dependent timeout interval, >0 = as specified) an I_STR request will wait for acknowledgement before timing out. ic_len member has two uses: on input, it contains the length of the data argument passed in, and on return from the command, it contains the number of bytes being returned to the process (the buffer pointed to by ic_dp should be large enough to contain the maximum amount of data that any module or the driver in the STREAM can return.)
The STREAM head will convert the information pointed to by the strioctl structure to an internal ioctl() command message and send it downstream.
An I_STR can also fail while waiting for an acknowledgement if a message indicating an error or a hang-up is received at the STREAM head. In addition, an error code can be returned in the positive or negative acknowledgement message, in the event the ioctl() command sent downstream fails. For these cases, I_STR fails with errno set to the value in the message.
The fd member is a file descriptor. The uid and gid members are the effective user ID and effective group ID, respectively, of the sending process.
If O_NONBLOCK is not set I_RECVFD blocks until a message is present at the STREAM head. If O_NONBLOCK is set, I_RECVFD fails with errno set to EAGAIN if no message is present at the STREAM head.
If the message at the STREAM head is a message sent by an I_SENDFD, a new file descriptor is allocated for the open file descriptor referenced in the message. The new file descriptor is placed in the fd member of the strrecvfd structure pointed to by arg.
The sl_nmods member indicates the number of entries the process has allocated in the array. Upon return, the sl_modlist member of the str_list structure contains the list of module names. The number of entries that have been filled into the sl_modlist array is found in the sl_nmode member (the number includes the number of module including the driver). The return value from ioctl() is 0. The entries are filled in starting at the top of the STREAM and continuing downstream until either the end of the STREAM is reached, or the number of requested modules (sl_nmods) is satisfied.
ANYMARK Check if the message is marked.
LASTMARK Check if the message is the last one marked on the queue.
The bitwise inclusive-OR of the flags ANYMARK and LASTMARK is permitted.
The return value is 1 if the mark condition is satisfied and 0 otherwise.
ioctl() with the I_ATMARK command will fail if:
EINVAL Non-valid arg value.
ioctl() with the I_CKBAND command will fail if :
EINVAL Non-valid arg value.
ioctl() with the I_GETBAND command will fail if:
ENODATA No message on the STREAM head read queue.
ioctl() with the I_CANPUT command will fail if:
EINVAL Non-valid arg value.
ioctl() with the I_SETCLTIME command will fail if:
EINVAL Non-valid arg value.
An I_LINK can also fail while waiting for the multiplexing driver to acknowledge the request, if a message indicating an error or a hang-up is received at the STREAM head of fildes. In addition, an error code can be returned in the positive or negative acknowledgement message. For these cases, I_LINK fails with errno set to the value in the message.
An I_UNLINK can also fail while waiting for the multiplexing driver to acknowledge the request if a message indicating an error or a hang-up is received at the STREAM head of fildes In addition, an error code can be returned in the positive or negative acknowledgement message. For these cases, I_UNLINK fails with errno set to the value in the message.
An I_PLINK can also fail while waiting for the multiplexing driver to acknowledge the request, if a message indicating an error or a hang-up is received at the STREAM head of fildes In addition, an error code can be returned in the positive or negative acknowledgement message. For these cases, I_PLINK fails with errno set to the value in the message.
An I_PUNLINK can also fail while waiting for the multiplexing driver to acknowledge the request if a message indicating an error or a hang-up is received at the STREAM head of fildes. In addition, an error code can be returned in the positive or negative acknowledgement message. For these cases, I_PUNLINK fails with errno set to the value in the message.
If successful, ioctl() returns a value other than -1 that depends upon the STREAMS device control function.
If unsuccessful, ioctl() returns -1 and sets errno to one of the following values.
Under the following general conditions, ioctl() will fail if:
If a STREAM is connected downstream from a multiplexer, any ioctl() command except I_UNLINK and I_PUNLINK will set errno to EINVAL.
If successful, ioctl() returns 0.
int s;
int rc;
int acllen;
ext_acl_t aclbufp;
s = open("datafile", O_RDWR);
acllen = sizeof struct ACL_buf + (1024 * sizeof ACL_entry);
aclbufp = (ext_acl_t) malloc(acllen);
rc = ioctl(s, GETFACL, acllen, aclbufp)