From: Ben Pfaff Date: Tue, 20 Jan 2009 21:34:13 +0000 (-0800) Subject: New function netdev_enumerate(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71f16d083c64f8021ea82a4c972aca150fc1c633;p=openvswitch New function netdev_enumerate(). --- diff --git a/lib/netdev.c b/lib/netdev.c index 5d6f2246..a2287864 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 7fc96222..843a143a 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, @@ -92,4 +93,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 */