ioctl()--Perform I/O Control Request


  Syntax
 #include <sys/types.h>
 #include <sys/ioctl.h>

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

  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes

The ioctl() function performs control functions (requests) on a descriptor.


Parameters

descriptor
(Input) The descriptor on which the control request is to be performed.

request
(Input) The request that is to be performed on the descriptor.

...
(Input) A variable number of optional parameters that are dependent on the request.

The ioctl() requests that are supported are:

FIOASYNC Set or clear the flag that allows the receipt of asynchronous I/O signals (SIGIO).

The third parameter represents a pointer to an integer flag. A nonzero value sets the socket to generate SIGIO signals, while a zero value sets the socket to not generate SIGIO signals. Note that before the SIGIO signals can be delivered, you must use either the FIOSETOWN or SIOCSPGRP ioctl() request, or the F_SETOWN fcntl() command to set a process ID or a process group ID to indicate what process or group of processes will receive the signal. Once conditioned to send SIGIO signals, a socket will generate SIGIO signals whenever certain significant conditions change on the socket. For example, SIGIO will be generated when normal data arrives on the socket, when out-of-band data arrives on the socket (in addition to the SIGURG signal), when an error occurs on the socket, or when end-of-file is received on the socket. It is also generated when a connection request is received on the socket (if it is a socket on which the listen() verb has been done). Also note that a socket can be set to generate the SIGIO signal by using the fcntl() command F_SETFL with a flag value specifying FASYNC.

FIOCCSID Return the coded character set ID (CCSID) associated with the open instance represented by the descriptor and the CCSID associated with the object. The third parameter represents a pointer to the structure Qp0lFIOCCSID, which is defined in <sys/ioctl.h>. This information may be necessary to correctly manipulate data read from or written to a file opened in another process.

If the open instance represented by the descriptor is in binary mode (the open() did not specify the O_TEXTDATA open flag), the open instance CCSID returned is equal to the object CCSID returned.

This function will fail with error code [ENOTSUP] if the descriptor represents either a pipe, transport layer interface (TLI), or socket.

FIOGETOWN Get the process ID or process group ID that is to receive the SIGIO and SIGURG signals.

The third parameter represents a pointer to a signed integer that will contain the process ID or the process group ID to which the socket is currently sending asynchronous signals such as SIGURG. A process ID is returned as a positive integer, and a process group ID is specified as a negative integer. A 0 value returned indicates that no asynchronous signals can be generated by the socket. A positive or a negative value indicates that the socket has been set to generate SIGURG signals.

FIONBIO Set or clear the nonblocking I/O flag (O_NONBLOCK oflag). The third parameter represents a pointer to an integer flag. A nonzero value sets the nonblocking I/O flag for the descriptor; a zero value clears the flag.

FIONREAD Return the number of bytes available to be read. The third parameter represents a pointer to an integer that is set to the number of bytes available to be read.

FIOSETOWN Set the process ID or process group ID that is to receive the SIGIO and SIGURG signals.

The third parameter represents a pointer to a signed integer that contains the process ID or the process group ID to which the socket should send asynchronous signals such as SIGURG. A process ID is specified as a positive integer, and a process group ID is specified as a negative integer. Specifying a 0 value resets the socket such that no asynchronous signals are delivered. Specifying a process ID or a process group ID requests that sockets begin sending the SIGURG signal to the specified ID when out-of-band data arrives on the socket.

SIOCADDRT Add an entry to the interface routing table. Valid for sockets with address family of AF_INET.

The third parameter represents a pointer to the structure rtentry, which is defined in <net/route.h>:

      struct rtentry {
         struct sockaddr rt_dst;
         struct sockaddr rt_mask;
         struct sockaddr rt_gateway;
         int rt_mtu;
         u_short rt_flags;
         u_short rt_refcnt;
         u_char rt_protocol;
         u_char rt_TOS;
         char rt_if[IFNAMSIZ];
      };

The rt_dst, rt_mask, and rt_gateway fields are the route destination address, route address mask, and gateway address, respectively. rt_mtu is the maximum transfer unit associated with the route. rt_flags contains flags that give some information about a route (for example, whether the route was created dynamically, whether the route is usable, type of route, and so on). rt_refcnt indicates the number of references that exist to the route entry. rt_protocol indicates how the route entry was generated (for example, configuration(RTP_CONFIG), ICMP redirect(RTP_ICMP), and so on). These constants are defined in <route.h>. rt_tos is the type of service associated with the route. rt_if is a NULL-terminated string that represents the interface IP address in dotted decimal format that is associated with the route.

To add a route, the following fields must be set:

  • rt_dst
  • rt_mask
  • rt_gateway
  • rt_tos
  • rt_protocol
  • rt_mtu (Setting the rt_mtu value to zero essentially means use the MTU from the associated line description used when the route is bound to an IFC.)
  • rt_if (rt_if can be set to the dotted decimal equivalent of INADDR_ANY, which is 0.)

In addition, the rt_flags bit flags can be set to the following:

  • RTF_NOREBIND_IFC_FAIL if no rebinding of the route is to occur when the interface associated with the route fails.
  • RTF_NOREBIND_IFC_ACTV if no rebinding is to occur when interfaces are activated or deactivated.
  • RTF_TOS_IS_PRIORITY if the rt_TOS field of the rtentry structure specifies the route priority. Valid values for IPv4 route priorities are 1 through 10, inclusive.
  • Other valid flag values are defined in <route.h>.

To delete a route, the following fields must be set:

  • rt_dst
  • rt_mask
  • rt_gateway
  • rt_tos
  • rt_protocol

All other fields are ignored when adding or removing an entry.

SIOCADDRT6 Add an IPv6 entry to the interface routing table. Valid for sockets with address family of AF_INET or AF_INET6.

The third parameter represents a pointer to the structure ip6rtentry, which is defined in <net/route.h>:

      struct ip6rtentry {
         struct  sockaddr_in6 rt_dst;
         struct  sockaddr_in6 rt_nexthop;
         int     rt_mtu;
         u_short rt_flags;
         u_char  rt_prefixlen;
         u_char  rt_protocol;
         char    rt_priority;
         char    rt_if[32];
      };

The rt_dst, rt_prefixlen, and rt_nexthop fields are the route destination address, prefix length of the address, and next hop address, respectively. rt_mtu is the maximum transfer unit associated with the route. rt_flags is not used. rt_protocol indicates how the route entry was generated (for example, configuration(RTP_CONFIG), ICMP redirect(RTP_ICMP), and so on). These constants are defined in <route.h>. rt_priority is the priority of the route when there are multiple routes to the same destination. rt_if is a NULL-terminated string that represents the line name of the interface that is associated with the route.

To add a route, the following fields must be set:

  • rt_dst
  • rt_prefixlen
  • rt_nexthop
  • rt_mtu (Setting the rt_mtu value to zero essentially means use the MTU from the associated line description used when the route is bound to an IFC.)
  • rt_protocol
  • rt_if
  • rt_priority field must be set to one the following to specify the route priority:
    • RTP_LOW_PRIORITY
    • RTP_MEDIUM_PRIORITY
    • RTP_HIGH_PRIORITY
  • rt_flags bit flags must be set to zero

To delete a route, the following fields must be set:

  • rt_dst
  • rt_prefixlen
  • rt_nexthop
  • rt_protocol
  • rt_if

All other fields are ignored when adding or removing an entry.

SIOCATMARK Return the value indicating whether socket's read pointer is currently at the out-of-band mark.

The third parameter represents a pointer to an integer flag. If the socket's read pointer is currently at the out-of-band mark, the flag is set to a nonzero value. If it is not, the flag is set to zero.

SIOCDELRT Delete an entry from the interface routing table. Valid for sockets with address family of AF_INET.

See SIOCADDRT for more information about the third parameter.

SIOCDELRT6 Delete an IPv6 entry from the interface routing table. Valid for sockets with address family of AF_INET or AF_INET6.

See SIOCADDRT6 for more information about the third parameter.

SIOCGIFADDR Get the interface address. Valid for sockets with address family of AF_INET.

The third parameter represents a pointer to the structure ifreq, defined in <net/if.h>:

      struct ifreq {
         char ifr_name[IFNAMSIZE];
         union {
          struct sockaddr ifru_addr;
          struct sockaddr ifru_mask;
          struct sockaddr ifru_broadaddr;
          short ifru_flags;
          int ifru_mtu;
          int infu_rbufsize;
          char ifru_linename[10];
          char ifru_TOS;
         } ifr_ifru;
      };

ifr_name is the name of the interface for which information is to be retrieved. The IBM® i implementation requires this field to be set to a NULL-terminated string that represents the interface IP address in dotted decimal format. Depending on the request, one of the fields in the ifr_ifru union will be set upon return from the ioctl() call. ifru_addr is the local IP address of the interface. ifru_mask is the subnetwork mask associated with the interface. ifru_broadaddr is the broadcast address. ifru_flags contains flags that give some information about an interface (for example, token-ring routing support, whether interface is active, broadcast address, and so on). ifru_mtu is the maximum transfer unit configured for the interface. ifru_rbufsize is the reassembly buffer size of the interface. ifru_linename is the line name associated with the interface. ifru_TOS is the type of service configured for the interface.

See getifaddrs() to obtain this information for IPv6 interfaces.

SIOCGIFBRDADDR Get the interface broadcast address. Valid for sockets with address family of AF_INET.

See SIOCGIFADDR for more information about the third parameter.

SIOCGIFCONF Get the interface configuration list. Valid for sockets with address family of AF_INET.

The third parameter represents a pointer to the structure ifconf, defined in <net/if.h>:

      struct ifconf [
         int ifc_len;
         int ifc_configured;
         int ifc_returned;
         union {
          caddr_t ifcu_buf;
          struct ifreq *ifcu_req;
         } ifc_ifcu;
      ];

ifc_len is a value-result field. The caller passes the size of the buffer pointed to by ifcu_buf. On return, ifc_len contains the amount of storage that was used in the buffer pointed to by ifcu_buf for the interface entries. ifc_configured is the number of interface entries in the interface list. ifc_returned is the number of interface entries that were returned (this is dependent on the size of the buffer pointed to by ifcu_buf). ifcu_buf is the user buffer in which a list of interface entries will be stored. Each stored entry will be an ifreq structure.

To get the interface configuration list, the following fields must be set:

  • ifc_len
  • ifcu_buf

See SIOCGIFADDR for more information about the list of ifreq structures returned. For this request, the ifr_name and ifru_addr fields will be set to a value.

Note: Additional information about each individual interface can be obtained using these values and the other interface-related requests.

SIOCGIFFLAGS Get interface flags. Valid for sockets with address family of AF_INET.

See SIOCGIFADDR for more information about the third parameter.

SIOCGIFLIND Get the interface line description name. Valid for sockets with address family of AF_INET.

See SIOCGIFADDR for more information about the third parameter.

SIOCGIFMTU Get the interface network MTU. Valid for sockets with address family of AF_INET.

See SIOCGIFADDR for more information about the third parameter.

SIOCGIFNETMASK Get the mask for the network portion of the interface address. Valid for sockets with address family of AF_INET.

See SIOCGIFADDR for more information about the third parameter.

SIOCGIFRBUFS Get the interface reassembly buffer size. Valid for sockets with address family of AF_INET.

See SIOCGIFADDR for more information about the third parameter.

SIOCGIFTOS Get the interface type-of-service (TOS). Valid for sockets with address family of AF_INET.

See SIOCGIFADDR for more information about the third parameter.

SIOCGPGRP Get the process ID or process group ID that is to receive the SIGIO and SIGURG signals.

See FIOGETOWN for more information about the third parameter.

SIOCGRTCONF Get the route configuration list. Valid for sockets with address family of AF_INET.

For the SIOCGRTCONF request, the third parameter represents a pointer to the structure rtconf, also defined in <net/route.h>:

      struct rtconf [
         int rtc_len;
         int rtc_configured;
         int rtc_returned;
         union {
          caddr_t rtcu_buf;
          struct rtentry *rtcu_req;
         } rtc_rtcu;
      ];

rtc_len is a value-result field. The caller passes the size of the buffer pointed to by rtcu_buf. On return, rtc_len contains the amount of storage that was used in the buffer pointed to by rtcu_buf for the route entries. rtc_configured is the number of route entries in the route list. rtc_returned is the number of route entries that were returned (this is dependent on the size of the buffer pointed to by rtcu_buf). rtcu_buf is the user buffer in which a list of route entries will be stored. Each stored entry will be an rtentry structure.

To get the route configuration list, the following fields must be set:

  • rtc_len
  • rtcu_buf

See SIOCADDRT for more information about the list of rtentry structures returned. For this request, all fields in each rtentry structure will be set to a value.

See QtocLstNetRte to obtain this information for all IPv6 routes.

SIOCSENDQ Return the number of bytes on the send queue that have not been acknowledged by the remote system. Valid for sockets with address family of AF_INET or AF_INET6 and socket type of SOCK_STREAM.

The third parameter represents a pointer to an integer that is set to the number of bytes yet to be acknowledged as being received by the remote TCP transport driver.

Notes:

  1. SIOCSENDQ is used after a series of blocking or non-blocking send operations to see if the sent data has reached the transport layer on the remote system. Note that this does not guarantee the data has reached the remote application.

  2. When SIOCSENDQ is used in a multithreaded application, the actions of other threads must be considered by the application. SIOCSENDQ provides a result for a socket descriptor at the given point in time when the ioctl()) request is received by the TCP transport layer. Blocking send operations that have not completed, as well as non-blocking send operations in other threads issued after the SIOCSENDQ ioctl(), are not reflected in the result obtained for the SIOCSENDQ ioctl().

  3. In a situation where the application has multiple threads sending data on the same socket descriptor, the application should not assume that all data has been received by the remote side when 0 is returned if the application is not positive that all send operations in the other threads were complete at the time the SIOCSENDQ ioctl() was issued. An application should issue the SIOCSENDQ ioctl() only after it has completed all of the send operations. No value is added by querying the machine to see if it has sent all of the data when the application itself has not sent all of the data in a given unit of work.


SIOCSPGRP Set the process ID or process group ID that is to receive the SIGIO and SIGURG signals.

See FIOSETOWN for more information about the third parameter.


Authorities

The user profile for the thread must have *IOSYSCFG special authority to issue any of the following requests: SIOCADDRT, SIOCDELRT, SIOCADDRT6 and SIOCDELRT6.

Return Value

0
ioctl() was successful
-1
ioctl() was not successful. The errno global variable is set to indicate the error.

Error Conditions

If ioctl() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

Error condition Additional information
[EACCES]

If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems.

[EAGAIN]  
[EBADF]  
[EBADFID]  
[EBUSY]  
[EDAMAGE]  
[EFAULT]  
[EINTR]  
[EINVAL]  
[EIO]  
[ENOBUFS]  
[ENOSPC]  
[ENOSYS]  
[ENOTAVAIL]  
[ENOTSAFE]  
[ENOTSUP]  
[EPERM]  
[EPIPE]  
[ERESTART]  
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[EUNATCH]  
[EUNKNOWN]  

If interaction with a file server is required to access the object, errno could also indicate one of the following errors:

Error condition Additional information
[EADDRNOTAVAIL]  
[ECONNABORTED]  
[ECONNREFUSED]  
[ECONNRESET]  
[EHOSTDOWN]  
[EHOSTUNREACH]  
[ENETDOWN]  
[ENETRESET]  
[ENETUNREACH]  
[ETIMEDOUT]  


Error Messages

The following messages may be sent from this function:

Message ID Error Message Text
CPFA0D4 E File system error occurred. Error number &1.
CPFA081 E Unable to set return value or error code.
CPF3CF2 E Error(s) occurred during running of &1 API.
CPE3418 E Possible APAR condition or hardware failure.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.


Usage Notes

  1. This function will fail with error code [ENOTSAFE] when all the following conditions are true:


  2. QDLS File System Differences

    QDLS does not support ioctl().

  3. QOPT File System Differences

    QOPT does not support ioctl().


Related Information


API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]