src/dpdk/drivers/net/vdev_netvsc/vdev_netvsc.c
static int
vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface,
				      const struct rte_ether_addr *eth_addr,
				      va_list ap), int is_netvsc, ...)
{
	struct if_nameindex *iface = if_nameindex();
	int s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
	unsigned int i;
	int ret = 0;

	if (!iface) {
		ret = -ENOBUFS;
		DRV_LOG(ERR, "cannot retrieve system network interfaces");
		goto error;
	}
	if (s == -1) {
		ret = -errno;
		DRV_LOG(ERR, "cannot open socket: %s", rte_strerror(errno));
		goto error;
	}
	for (i = 0; iface[i].if_name; ++i) {
		int is_netvsc_ret;
		struct ifreq req;
		struct rte_ether_addr eth_addr;
		va_list ap;

		is_netvsc_ret = vdev_netvsc_iface_is_netvsc(&iface[i]) ? 1 : 0;
		if (is_netvsc ^ is_netvsc_ret)
			continue;
		strlcpy(req.ifr_name, iface[i].if_name, sizeof(req.ifr_name));
		if (ioctl(s, SIOCGIFHWADDR, &req) == -1) {
			DRV_LOG(WARNING, "cannot retrieve information about"
					 " interface \"%s\": %s",
					 req.ifr_name, rte_strerror(errno));
			continue;
		}
		if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER)
			continue;
		memcpy(eth_addr.addr_bytes, req.ifr_hwaddr.sa_data,
		       RTE_DIM(eth_addr.addr_bytes));
		va_start(ap, is_netvsc);
		ret = func(&iface[i], &eth_addr, ap);
		va_end(ap);
		if (ret)
			break;
	}
error:
	if (s != -1)
		close(s);
	if (iface)
		if_freenameindex(iface);
	return ret;
}
/**
 * Iterate over system network interfaces.
 *
 * This function runs a given callback function for each netdevice found on
 * the system.
 *
 * @param func
 *   Callback function pointer. List traversal is aborted when this function
 *   returns a nonzero value.
 * @param is_netvsc
 *   Indicates the device type to iterate - netvsc or non-netvsc.
 * @param ...
 *   Variable parameter list passed as @p va_list to @p func.
 *
 * @return
 *   0 when the entire list is traversed successfully, a negative error code
 *   in case or failure, or the nonzero value returned by @p func when list
 *   traversal is aborted.
 */
Iterate over system network interfaces.
This function runs a given callback function for each netdevice found on
the system.

@param func
Callback function pointer. List traversal is aborted when this function
returns a nonzero value.
@param is_netvsc
Indicates the device type to iterate - netvsc or non-netvsc.
@param
Variable parameter list passed as @p va_list to @p func.

@return
0 when the entire list is traversed successfully, a negative error code
in case or failure, or the nonzero value returned by @p func when list
traversal is aborted.
Iterate over system network interfaces . This function runs a given callback function for each netdevice found on the system . @param func Callback function pointer . List traversal is aborted when this function returns a nonzero value . @param is_netvsc Indicates the device type to iterate - netvsc or non - netvsc . @param Variable parameter list passed as @p va_list to @p func . @return 0 when the entire list is traversed successfully a negative error code in case or failure or the nonzero value returned by @p func when list traversal is aborted .
static int
vdev_netvsc_foreach_iface(int (*func)(const struct if_nameindex *iface,
				      const struct rte_ether_addr *eth_addr,
				      va_list ap), int is_netvsc, ...)
{
	struct if_nameindex *iface = if_nameindex();
	int s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
	unsigned int i;
	int ret = 0;
	if (!iface) {
		ret = -ENOBUFS;
		DRV_LOG(ERR, "cannot retrieve system network interfaces");
		goto error;
	}
	if (s == -1) {
		ret = -errno;
		DRV_LOG(ERR, "cannot open socket: %s", rte_strerror(errno));
		goto error;
	}
	for (i = 0; iface[i].if_name; ++i) {
		int is_netvsc_ret;
		struct ifreq req;
		struct rte_ether_addr eth_addr;
		va_list ap;
		is_netvsc_ret = vdev_netvsc_iface_is_netvsc(&iface[i]) ? 1 : 0;
		if (is_netvsc ^ is_netvsc_ret)
			continue;
		strlcpy(req.ifr_name, iface[i].if_name, sizeof(req.ifr_name));
		if (ioctl(s, SIOCGIFHWADDR, &req) == -1) {
			DRV_LOG(WARNING, "cannot retrieve information about"
					 " interface \"%s\": %s",
					 req.ifr_name, rte_strerror(errno));
			continue;
		}
		if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER)
			continue;
		memcpy(eth_addr.addr_bytes, req.ifr_hwaddr.sa_data,
		       RTE_DIM(eth_addr.addr_bytes));
		va_start(ap, is_netvsc);
		ret = func(&iface[i], &eth_addr, ap);
		va_end(ap);
		if (ret)
			break;
	}
error:
	if (s != -1)
		close(s);
	if (iface)
		if_freenameindex(iface);
	return ret;
}
static int vdev_netvsc_foreach_iface ( int ( * func ) ( const struct if_nameindex * iface , const struct rte_ether_addr * eth_addr , va_list ap ) , int is_netvsc , ... ) { struct if_nameindex * iface = if_nameindex ( ) ; int s = socket ( PF_INET , SOCK_DGRAM , IPPROTO_IP ) ; unsigned int i ; int ret = 0 ; if ( ! iface ) { ret = - ENOBUFS ; DRV_LOG ( ERR , " " ) ; goto error ; } if ( s == -1 ) { ret = - errno ; DRV_LOG ( ERR , " " , rte_strerror ( errno ) ) ; goto error ; } for ( i = 0 ; iface [ i ] . if_name ; ++ i ) { int is_netvsc_ret ; struct ifreq req ; struct rte_ether_addr eth_addr ; va_list ap ; is_netvsc_ret = vdev_netvsc_iface_is_netvsc ( & iface [ i ] ) ? 1 : 0 ; if ( is_netvsc ^ is_netvsc_ret ) continue ; strlcpy ( req . ifr_name , iface [ i ] . if_name , sizeof ( req . ifr_name ) ) ; if ( ioctl ( s , SIOCGIFHWADDR , & req ) == -1 ) { DRV_LOG ( WARNING , " " " \" \" " , req . ifr_name , rte_strerror ( errno ) ) ; continue ; } if ( req . ifr_hwaddr . sa_family != ARPHRD_ETHER ) continue ; memcpy ( eth_addr . addr_bytes , req . ifr_hwaddr . sa_data , RTE_DIM ( eth_addr . addr_bytes ) ) ; va_start ( ap , is_netvsc ) ; ret = func ( & iface [ i ] , & eth_addr , ap ) ; va_end ( ap ) ; if ( ret ) break ; } error : if ( s != -1 ) close ( s ) ; if ( iface ) if_freenameindex ( iface ) ; return ret ; }
Iterate over system network interfaces.
Iterate over system network interfaces .