New function netdev_enumerate().
authorBen Pfaff <blp@nicira.com>
Tue, 20 Jan 2009 21:34:13 +0000 (13:34 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 21 Jan 2009 00:45:22 +0000 (16:45 -0800)
lib/netdev.c
lib/netdev.h

index e83c647..9a91e2f 100644 (file)
@@ -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));
+    }
+}
 \f
 static void restore_all_flags(void *aux);
 
index 28a96e4..46f0cb0 100644 (file)
@@ -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 */