sockio

Name

sockio -- socket ioctl commands

Synopsis

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

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

Description

Socket ioctl commands are a subset of the ioctl calls, which can perform a variety of functions on sockets. sockfd shall contain the value of a file descriptor that was created with the socket or accept calls.

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

Gets the interface configuration list for the system.

Note

SIOCGIFCONF is similar to the if_nameindex family found in the ISO POSIX (2003) or the getifaddrs family found in BSD derived systems.

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 can return any nonnegative value.

NoteRationale
 

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

SIOCGIFFLAGS

Gets 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

Gets 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.

SIOCGIFNETMASK

Gets 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.

FIONREAD

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

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.