[ Team LiB ] Previous Section Next Section

17.7 Interface Operations

As we showed in the previous section, the SIOCGIFCONF request returns the name and a socket address structure for each interface that is configured. There are a multitude of other requests that we can then issue to set or get all the other characteristics of the interface. The get version of these requests (SIOCGxxx) is often issued by the netstat program, and the set version (SIOCSxxx) is often issued by the ifconfig program. Any user can get the interface information, while it takes superuser privileges to set the information.

These requests take or return an ifreq structure whose address is specified as the third argument to ioctl. The interface is always identified by its name: le0, lo0, ppp0, etc. in the ifr_name member.

Many of these requests use a socket address structure to specify or return an IP address or address mask with the application. For IPv4, the address or mask is contained in the sin_addr member of an Internet socket address structure; for IPv6, it is in the sin6_addr member of an IPv6 socket address structure.

SIOCGIFADDR

Return the unicast address in the ifr_addr member.

SIOCSIFADDR

Set the interface address from the ifr_addr member. The initialization function for the interface is also called.

SIOCGIFFLAGS

Return the interface flags in the ifr_flags member. The names of the various flags are IFF_xxx and are defined by including the <net/if.h> header. The flags indicate, for example, if the interface is up (IFF_UP), if the interface is a point-to-point interface (IFF_POINTOPOINT), if the interface supports broadcasting (IFF_BROADCAST), and so on.

SIOCSIFFLAGS

Set the interface flags from the ifr_flags member.

SIOCGIFDSTADDR

Return the point-to-point address in the ifr_dstaddr member.

SIOCSIFDSTADDR

Set the point-to-point address from the ifr_dstaddr member.

SIOCGIFBRDADDR

Return the broadcast address in the ifr_broadaddr member. The application must first fetch the interface flags and then issue the correct request: SIOCGIFBRDADDR for a broadcast interface or SIOCGIFDSTADDR for a point-to-point interface.

SIOCSIFBRDADDR

Set the broadcast address from the ifr_broadaddr member.

SIOCGIFNETMASK

Return the subnet mask in the ifr_addr member.

SIOCSIFNETMASK

Set the subnet mask from the ifr_addr member.

SIOCGIFMETRIC

Return the interface metric in the ifr_metric member. The interface metric is maintained by the kernel for each interface but is used by the routing daemon routed. The interface metric is added to the hop count (to make an interface less favorable).

SIOCSIFMETRIC

Set the interface routing metric from the ifr_metric member.

In this section, we described the generic interface requests. Many implementations have additional requests as well.

    [ Team LiB ] Previous Section Next Section