From: Ben Pfaff Date: Tue, 20 Jan 2009 21:34:13 +0000 (-0800) Subject: New function netdev_enumerate(). X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=52e7e1151b49932522a8230f48918e99bbb41066;p=sliver-openvswitch.git New function netdev_enumerate(). --- diff --git a/lib/netdev.c b/lib/netdev.c index e83c64752..9a91e2f62 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -65,6 +65,7 @@ #include "packets.h" #include "poll-loop.h" #include "socket-util.h" +#include "svec.h" #define THIS_MODULE VLM_netdev #include "vlog.h" @@ -948,6 +949,27 @@ netdev_arp_lookup(const struct netdev *netdev, } return retval; } + +/* Initializes 'svec' with a list of the names of all known network devices. */ +void +netdev_enumerate(struct svec *svec) +{ + struct if_nameindex *names; + + svec_init(svec); + names = if_nameindex(); + if (names) { + size_t i; + + for (i = 0; names[i].if_name != NULL; i++) { + svec_add(svec, names[i].if_name); + } + if_freenameindex(names); + } else { + VLOG_WARN("could not obtain list of network device names: %s", + strerror(errno)); + } +} static void restore_all_flags(void *aux); diff --git a/lib/netdev.h b/lib/netdev.h index 28a96e44f..46f0cb088 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -46,6 +46,7 @@ struct ofpbuf; struct in_addr; struct in6_addr; +struct svec; enum netdev_feature_type { NETDEV_FEAT_CURRENT, @@ -91,4 +92,6 @@ int netdev_turn_flags_on(struct netdev *, enum netdev_flags, bool permanent); int netdev_turn_flags_off(struct netdev *, enum netdev_flags, bool permanent); int netdev_arp_lookup(const struct netdev *, uint32_t ip, uint8_t mac[6]); +void netdev_enumerate(struct svec *); + #endif /* netdev.h */