mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: add virNetDevGetName() function
Add a function getting the name of a network interface out of its index.
This commit is contained in:
parent
3ee35d7d6c
commit
5dd607059d
@ -1995,6 +1995,7 @@ virNetDevGetIndex;
|
||||
virNetDevGetLinkInfo;
|
||||
virNetDevGetMAC;
|
||||
virNetDevGetMTU;
|
||||
virNetDevGetName;
|
||||
virNetDevGetOnline;
|
||||
virNetDevGetPhysicalFunction;
|
||||
virNetDevGetPromiscuous;
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user