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 1f25e42d8..0fe88c3fa 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1982,6 +1982,7 @@ virNetDevFeatureTypeToString; virNetDevGetFeatures; virNetDevGetIndex; virNetDevGetLinkInfo; +virNetDevGetName; virNetDevGetMAC; virNetDevGetMTU; virNetDevGetOnline; 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.11.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list