sockio

Name

sockio -- socket ioctl commands

Synopsis

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>

int ioctl(int sockfd, int request, void * argp);

Description

Socket ioctl() commands are a subset of the ioctl() calls, which can perform a variety of functions on sockets. sockfd shall be an open file descriptor referring to a socket (see the socket() or accept() functions).

Socket ioctl() commands apply to the underlying network interfaces, and affect the entire system, not just the file descriptor used to issue the ioctl().

The following values for request are accepted:

SIOCGIFCONF (Deprecated)

Get the interface configuration list for the system.

Note: The SIOCGIFCONF interface is superceded by the if_nameindex() family of functions (see POSIX 1003.1-2008 (ISO/IEC 9945-2009)). A future version of this specification may withdraw this value for request.

argp shall point to a ifconf structure, as described in <net/if.h>. Before calling, the caller shall set the ifc_ifcu.ifcu_req field to point to an array of ifreq structures, and set ifc_len to the size in bytes of this allocated array. Upon return, ifc_len will contain the size in bytes of the array which was actually used. If it is the same as the length upon calling, the caller should assume that the array was too small and try again with a larger array.

On success, SIOCGIFCONF shall return a nonnegative value.

Rationale: Historical UNIX systems disagree on the meaning of the return value.

SIOCGIFFLAGS

Get the interface flags for the indicated interface. argp shall point to a ifreq structure. Before calling, the caller should fill in the ifr_name field with the interface name, and upon return, the ifr_ifru.ifru_flags field is set with the interface flags.

SIOCGIFADDR

Get the interface address for the given interface. argp shall point to a ifreq structure. Before calling, the caller should fill in the ifr_name field with the interface name, and upon return, the ifr_ifru.ifru_addr field is set with the interface address.

SIOCGIFBRDADDR

Get the interface broadcast address for the given interface. argp shall point to a ifreq structure. Before calling, the caller should fill in the ifr_name field with the interface name, and upon return, the ifr_ifru.ifru_broadcast field is set with the interface broadcast address.

SIOCGIFDSTADDR

Get the point-to-point address for the given interface. argp shall point to a ifreq structure. Before calling, the caller should fill in the ifr_name field with the interface name, and upon return, the ifr_dstaddr field is set with the point-to-point address.

SIOCGIFNAME

Get the name of an interface. argp shall point to a ifreq structure. Before calling, the caller should fill in the ifr_ifindex field with the number (index) of the interface, and upon return, the ifr_name field is set with the interface name.

SIOCGIFNETMASK

Get the network mask for the given interface. argp shall point to a ifreq structure. Before calling, the caller should fill in the ifr_name field with the interface name, and upon return, the ifr_ifru.ifru_netmask field is set with the network mask.

SIOCGIFMTU

Get the Maximum Transmission Unit (MTU) size for the given interface. argp shall point to a ifreq structure. Before calling, the caller should fill in the ifr_name field with the interface name, and upon return, the ifr_ifru.ifru_mtu field is set with the MTU. Note: The range of valid values for MTU varies for an interface depending on the interface type.

FIONREAD

Get the amount of queued unread data in the receive buffer. argp shall point to an integer where the result is to be placed.

Note: Some implementations may also support the use of FIONREAD on other types of file descriptor. However, the LSB only specifies its behavior for a socket related file descriptor.

Return Value

On success, if request is SIOCGIFCONF, a non-negative integer shall be returned. If request is not SIOCGIFCONF, on success 0 is returned. On error, -1 is returned and the global variable errno is set appropriately.

Errors

EBADF 

sockfd is not a valid descriptor.

EFAULT 

argp references an inaccessible memory area.

ENOTTY 

The specified request does not apply to the kind of object that the descriptor sockfd references.

EINVAL 

Either request or argp is invalid.

ENOTCONN 

The operation is only defined on a connected socket, but the socket wasn't connected.