71 lines
2.1 KiB
Diff
71 lines
2.1 KiB
Diff
|
From 5dd607059d8a98e04024305ae4afbd038aadbdcd Mon Sep 17 00:00:00 2001
|
||
|
From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= <cbosdonnat@suse.com>
|
||
|
Date: Wed, 15 Mar 2017 14:46:56 +0100
|
||
|
Subject: [PATCH 4/5] util: add virNetDevGetName() function
|
||
|
|
||
|
Add a function getting the name of a network interface out of its index.
|
||
|
---
|
||
|
src/libvirt_private.syms | 1 +
|
||
|
src/util/virnetdev.c | 19 +++++++++++++++++++
|
||
|
src/util/virnetdev.h | 2 ++
|
||
|
3 files changed, 22 insertions(+)
|
||
|
|
||
|
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
||
|
index f03925bc1..3b2cb83c4 100644
|
||
|
--- a/src/libvirt_private.syms
|
||
|
+++ b/src/libvirt_private.syms
|
||
|
@@ -1995,6 +1995,7 @@ virNetDevGetIndex;
|
||
|
virNetDevGetLinkInfo;
|
||
|
virNetDevGetMAC;
|
||
|
virNetDevGetMTU;
|
||
|
+virNetDevGetName;
|
||
|
virNetDevGetOnline;
|
||
|
virNetDevGetPhysicalFunction;
|
||
|
virNetDevGetPromiscuous;
|
||
|
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
|
||
|
index d12324878..91a5274aa 100644
|
||
|
--- a/src/util/virnetdev.c
|
||
|
+++ b/src/util/virnetdev.c
|
||
|
@@ -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:
|
||
|
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
|
||
|
index 236cf83ef..01e9c5b95 100644
|
||
|
--- a/src/util/virnetdev.h
|
||
|
+++ b/src/util/virnetdev.h
|
||
|
@@ -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;
|
||
|
|
||
|
--
|
||
|
2.12.0
|
||
|
|