sockio

Name

sockio -- socket ioctl commands

Synopsis

#include <sys/socket.h>
#include <net/if.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 must 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 ioctls are provided:

SIOCGIFCONF

Gets the interface configuration list for the system. [1] argp is a pointer to a ifconf structure. Before calling, the caller must allocate the ifc_ifcu.ifcu_req field to point to an array of ifreq structures, and set if_len to the size of this allocated array (in bytes). Upon return, if_len will contain the amount of the array which was actually used (again, in bytes). 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. [2]

SIOCGIFFLAGS

Gets the interface flags for the indicated interface. argp is a pointer 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 list for the system. argp is a pointer 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 indicated interface. argp is a pointer 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.

The sockaddr structure is as specified in the Single UNIX Specification.

Return Value

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

sockfd is not associated with a character special device.

ENOTTY

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

EINVAL

request and argp are not valid.

Notes

[1]

SIOCGIFCONF is similar to the if_nameindex family found in the Single UNIX Specification, Version 3 or the getifaddrs family found in BSD.

[2]

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