提交 5dd60705 编写于 作者: C Cédric Bosdonnat

util: add virNetDevGetName() function

Add a function getting the name of a network interface out of its index.
上级 3ee35d7d
...@@ -1995,6 +1995,7 @@ virNetDevGetIndex; ...@@ -1995,6 +1995,7 @@ virNetDevGetIndex;
virNetDevGetLinkInfo; virNetDevGetLinkInfo;
virNetDevGetMAC; virNetDevGetMAC;
virNetDevGetMTU; virNetDevGetMTU;
virNetDevGetName;
virNetDevGetOnline; virNetDevGetOnline;
virNetDevGetPhysicalFunction; virNetDevGetPhysicalFunction;
virNetDevGetPromiscuous; virNetDevGetPromiscuous;
......
...@@ -899,6 +899,25 @@ virNetDevGetRcvAllMulti(const char *ifname, ...@@ -899,6 +899,25 @@ virNetDevGetRcvAllMulti(const char *ifname,
return virNetDevGetIFFlag(ifname, VIR_IFF_ALLMULTI, receive); 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: * virNetDevGetIndex:
......
...@@ -157,6 +157,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs) ...@@ -157,6 +157,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
int virNetDevSetName(const char *ifname, const char *newifname) int virNetDevSetName(const char *ifname, const char *newifname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; 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) int virNetDevGetIndex(const char *ifname, int *ifindex)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册