mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
Add an API for retrieving the MAC address of an interface
* src/util/bridge.c, src/util/bridge.h: Add virNetDevGetMAC
This commit is contained in:
parent
dfb454cebc
commit
ccc243470d
@ -357,6 +357,41 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNetDevGetMAC:
|
||||
* @ifname: interface name to set MTU for
|
||||
* @macaddr: MAC address (VIR_MAC_BUFLEN in size)
|
||||
*
|
||||
* This function gets the @macaddr for a given interface @ifname.
|
||||
*
|
||||
* Returns 0 in case of success or -1 on failure
|
||||
*/
|
||||
int virNetDevGetMAC(const char *ifname,
|
||||
unsigned char *macaddr)
|
||||
{
|
||||
int fd = -1;
|
||||
int ret = -1;
|
||||
struct ifreq ifr;
|
||||
|
||||
if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
|
||||
return -1;
|
||||
|
||||
if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("Cannot get interface MAC on '%s'"),
|
||||
ifname);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
memcpy(macaddr, ifr.ifr_hwaddr.sa_data, VIR_MAC_BUFLEN);
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNetDevGetMTU:
|
||||
* @ifname: interface name get MTU for
|
||||
|
@ -112,6 +112,9 @@ int virNetDevTapCreate(char **ifname,
|
||||
int virNetDevSetMAC(const char *ifname,
|
||||
const unsigned char *macaddr)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||
int virNetDevGetMAC(const char *ifname,
|
||||
unsigned char *macaddr)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||
int virNetDevSetMTU(const char *ifname,
|
||||
int mtu)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
||||
|
Loading…
Reference in New Issue
Block a user