Пример #1
0
/**
 * Get a list of all network interfaces including name and IP address.
 * Both IPv4 and IPv6 are supported
 *
 * @param ifh Interface handler, called once per network interface
 * @param arg Handler argument
 *
 * @return 0 if success, otherwise errorcode
 */
int net_if_apply(net_ifaddr_h *ifh, void *arg)
{
#ifdef HAVE_GETIFADDRS
	return net_getifaddrs(ifh, arg);
#else
	return net_if_list(ifh, arg);
#endif
}
Пример #2
0
/**
 * Debug network interfaces
 *
 * @param pf     Print handler for debug output
 * @param unused Unused parameter
 *
 * @return 0 if success, otherwise errorcode
 */
int net_if_debug(struct re_printf *pf, void *unused)
{
	int err;

	(void)unused;

	err = re_hprintf(pf, "net interfaces:\n");

#ifdef HAVE_GETIFADDRS
	err |= net_getifaddrs(if_debug_handler, pf);
#else
	err |= net_if_list(if_debug_handler, pf);
#endif

	return err;
}
Пример #3
0
/**
 * Get IP address for a given network interface
 *
 * @param ifname  Network interface name (optional)
 * @param af      Address Family
 * @param ip      Returned IP address
 *
 * @return 0 if success, otherwise errorcode
 *
 * @deprecated Works for IPv4 only
 */
int net_if_getaddr(const char *ifname, int af, struct sa *ip)
{
	struct ifentry ife;
	int err;

	if (!ip)
		return EINVAL;

	ife.af     = af;
	ife.ifname = (char *)ifname;
	ife.ip     = ip;
	ife.sz     = 0;
	ife.found  = false;

#ifdef HAVE_GETIFADDRS
	err = net_getifaddrs(if_getaddr_handler, &ife);
#else
	err = net_if_list(if_getaddr_handler, &ife);
#endif

	return ife.found ? err : ENODEV;
}