ifiter_ioctl.c revision ca485ab26fffa241a3eac1899b2d2012dd1fdb73
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* Obtain the list of network interfaces using the SIOCGIFCONF ioctl.
* See netintro(4).
*/
struct isc_interfaceiter {
unsigned int magic; /* Magic number. */
int socket;
void *buf; /* Buffer for sysctl data. */
unsigned int bufsize; /* Bytes allocated. */
unsigned int pos; /* Current offset in
SIOCGIFCONF data */
};
/*
* Size of buffer for SIOCGIFCONF, in bytes. We assume no sane system
* will have more than a megabyte of interface configuration data.
*/
#define IFCONF_BUFSIZE_INITIAL 4096
#define IFCONF_BUFSIZE_MAX 1048576
{
return (ISC_R_NOMEMORY);
/* Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. */
"making interface scan socket: %s",
goto socket_failure;
}
/*
* Get the interface configuration, allocating more memory if
* necessary.
*/
for (;;) {
goto alloc_failure;
}
break;
"get interface configuration: %s",
goto ioctl_failure;
}
"get interface configuration: "
"maximum buffer size exceeded");
goto ioctl_failure;
}
}
/*
* A newly created iterator has an undefined position
* until isc_interfaceiter_first() is called.
*/
return (ISC_R_SUCCESS);
return (result);
}
/*
* Get information about the current interface to iter->current.
* If successful, return ISC_R_SUCCESS.
* If the interface has an unsupported address family,
* return ISC_R_FAILURE. In case of other failure,
* return ISC_R_UNEXPECTED.
*/
static isc_result_t
int family;
return (ISC_R_FAILURE);
/* Get interface flags. */
"%s: getting interface flags: %s",
return (ISC_R_UNEXPECTED);
}
/* If the interface is point-to-point, get the destination address. */
"%s: getting destination address: %s",
return (ISC_R_UNEXPECTED);
}
&ifreq.ifr_dstaddr);
}
/* Get the network mask. */
"%s: getting netmask: %s",
return (ISC_R_UNEXPECTED);
}
return (ISC_R_SUCCESS);
}
/*
* Step the iterator to the next interface. Unlike
* isc_interfaceiter_next(), this may leave the iterator
* positioned on an interface that will ultimately
* be ignored. Return ISC_R_NOMORE if there are no more
* interfaces, otherwise ISC_R_SUCCESS.
*/
static isc_result_t
#ifdef ISC_NET_HAVESALEN
else
#endif
return (ISC_R_NOMORE);
return (ISC_R_SUCCESS);
}
static void
}