diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f03925bc1c757d9802b1cb753efd490de6656681..3b2cb83c48dcf13fd8cec881eb357d9759fa4a2e 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 d123248787cf0cb1b11fed03b281b1147cf097eb..91a5274aa58d658e7b78485a2fb494c6eb422757 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 236cf83efea58659e42e0afd1babb18184f66790..01e9c5b954dd0113979bedfca687e207a11aae36 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;