]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: add virNetDevGetName() function
authorCédric Bosdonnat <cbosdonnat@suse.com>
Wed, 15 Mar 2017 13:46:56 +0000 (14:46 +0100)
committerCédric Bosdonnat <cbosdonnat@suse.com>
Wed, 22 Mar 2017 08:01:33 +0000 (09:01 +0100)
Add a function getting the name of a network interface out of its index.

src/libvirt_private.syms
src/util/virnetdev.c
src/util/virnetdev.h

index f03925bc1c757d9802b1cb753efd490de6656681..3b2cb83c48dcf13fd8cec881eb357d9759fa4a2e 100644 (file)
@@ -1995,6 +1995,7 @@ virNetDevGetIndex;
 virNetDevGetLinkInfo;
 virNetDevGetMAC;
 virNetDevGetMTU;
+virNetDevGetName;
 virNetDevGetOnline;
 virNetDevGetPhysicalFunction;
 virNetDevGetPromiscuous;
index d123248787cf0cb1b11fed03b281b1147cf097eb..91a5274aa58d658e7b78485a2fb494c6eb422757 100644 (file)
@@ -899,6 +899,25 @@ virNetDevGetRcvAllMulti(const char *ifname,
     return virNetDevGetIFFlag(ifname, VIR_IFF_ALLMULTI, receive);
 }
 
+char *virNetDevGetName(int ifindex)
+{
+    char name[IFNAMSIZ];
+    char *ifname = NULL;
+
+    memset(&name, 0, sizeof(name));
+
+    if (!if_indextoname(ifindex, name)) {
+        virReportSystemError(errno,
+                             _("Failed to convert interface index %d to a name"),
+                             ifindex);
+        goto cleanup;
+    }
+
+   ignore_value(VIR_STRDUP(ifname, name));
+
+ cleanup:
+     return ifname;
+}
 
 /**
  * virNetDevGetIndex:
index 236cf83efea58659e42e0afd1babb18184f66790..01e9c5b954dd0113979bedfca687e207a11aae36 100644 (file)
@@ -157,6 +157,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
 int virNetDevSetName(const char *ifname, const char *newifname)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
+char *virNetDevGetName(int ifindex)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
 int virNetDevGetIndex(const char *ifname, int *ifindex)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;