ioctl()

The operating characteristics of sockets can be controlled using the ioctl() call.

Rules:
  • This call can be used only in the AF_INET domain.
  • Only the ioctl() commands that are documented in this topic are supported by this API.
#include <manifest.h>
#include <socket.h>
#include <bsdtypes.h>
#include <ioctl.h>
#include <rtrouteh.h>
#include <if.h>
#include <ezbcmonc.h>
int ioctl(int s, unsigned long cmd, char *arg)
Parameter
Description
s
The socket descriptor.
cmd
The command to perform.
arg
Points to the data associated with cmd.
The operations to be controlled are determined by cmd. The arg parameter points to data associated with the particular command, and its format depends on the command being requested. The following keywords are valid ioctl() keywords:
Keyword
Description
FIONBIO
Sets or clears nonblocking I/O for a socket. The variable arg points to an integer. If the integer is 0, nonblocking I/O on the socket is cleared; otherwise, the socket is set for nonblocking I/O.
FIONREAD
Gets for the socket the number of immediately readable bytes. The variable arg points to an integer.
SIOCADDRT
Adds a routing table entry. The variable arg points to a rtentry structure, as defined in RTROUTE.H. The routing table entry, passed as an argument, is added to the routing tables.
SIOCATMARK
Queries whether the current location in the data input is pointing to out-of-band data. The variable arg points to an integer of 1 when the socket points to a mark in the data stream for out-of-band data; otherwise, it points to 0.
SIOCDELRT
Deletes a routing table entry. The variable arg points to a rtentry structure, as defined in RTROUTE.H. If the structure exists, the routing table entry passed as an argument is deleted from the routing tables.
SIOCGIFADDR
Gets the network interface address. The variable arg points to an ifreq structure, as defined in IF.H. The interface address is returned in the argument.
SIOCGIFBRDADDR
Gets the network interface broadcast address. The variable arg points to an ifreq structure, as defined in IF.H. The interface broadcast address is returned in the argument.
SIOCGIFCONF
Gets the network interface configuration. The variable arg points to an ifconf structure, as defined in IF.H. The interface configuration is returned in the argument.
SIOCGIFDSTADDR
Gets the network interface destination address. The variable arg points to an ifreq structure, as defined in IF.H. The interface destination (point-to-point) address is returned in the argument.
SIOCGIFFLAGS
Gets the network interface flags. The variable arg points to an ifreq structure, as defined in IF.H. The interface flags are returned in the argument.
SIOCGIFMETRIC
Gets the network interface routing metric. The variable arg points to an ifreq structure, as defined in IF.H. The interface routing metric is returned in the argument.
SIOCGIFNETMASK
Gets the network interface network mask. The variable arg points to an ifreq structure, as defined in IF.H. The interface network mask is returned in the argument.
SIOCSIFMETRIC
Sets the network interface routing metric. The variable arg points to an ifreq structure, as defined in IF.H. The interface routing metric is set to the value passed in the argument.
SIOCGMONDATA
Returns TCP/IP stack statistical counters. The variable arg points to a MonDataIn structure. The counters are returned in a MonDataOut structure. Both of these structures are defined in EZBZMONC in SEZANMAC.
Note: The ARP counter data provided differs depending on the type of device. See z/OS Communications Server: IP Configuration Guide for information about devices that support ARP Offload and what is supported for each device.

Return values

The value 0 indicates success; the value -1 indicates an error. Errno identifies the specific error.
Errno
Description
EBADF
The s parameter is not a valid socket descriptor.
EINVAL
The request is not valid, or not supported.
EFAULT
The arg is a bad pointer.

Example

int s;
int dontblock;
int rc;
⋮
/* Place the socket into nonblocking mode */
dontblock = 1;
rc = ioctl(s, FIONBIO, (char *) &dontblock);
⋮