next_iface() fails when SIOCGLIFNUM not defined

Patrick Baggett baggett.patrick at gmail.com
Thu Oct 28 06:54:50 UTC 2010


When building dhcp-server on IRIX 6.5 using the native system compilers, I
see that the interface enumeration fails because the function
begin_iface_scan() doesn't know how to handle the case when SIOCGLIFNUM
isn't defined. This ioctl allows you to figure out the number of interfaces
in a system ahead of time without tediously calling realloc() with sizes
that are multiples of "struct ifreq" until the system says it has the right
size. IRIX 6.5 does not provide this ioctl, so begin_iface_scan() just
arbitrarily says there are 64 interfaces, which is a pretty safe bet that no
interface will be left behind.

The problem is that once the number of interfaces is /known/, this value is
never reduced to the correct number, so next_iface() keeps getting called
and eventually fails because there aren't really 64 interfaces in the
system.

The fix is relatively simple. The ioctl returns the size in bytes of the
structures, so dividing by the size of the structure returns the correct
number of interfaces. Specifically, after the ioctl(..., SIOCGLIFCONF, ) (~
line 289) call, add:

#ifndef SIOCGLIFNUM
/* Compute returned number of interfaces */
ifaces->num = ifaces->conf.lifc_len / sizeof(struct ifreq);
#endif

This fixes the error on dhcpd startup that reads:

Error getting interface flags for '': No such device or address

-- Patrick Baggett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.isc.org/pipermail/dhcp-hackers/attachments/20101028/9f1d6cdc/attachment.html>


More information about the dhcp-hackers mailing list