提交 ccc24347 编写于 作者: D Daniel P. Berrange

Add an API for retrieving the MAC address of an interface

* src/util/bridge.c, src/util/bridge.h: Add virNetDevGetMAC
上级 dfb454ce
...@@ -357,6 +357,41 @@ cleanup: ...@@ -357,6 +357,41 @@ cleanup:
return ret; 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: * virNetDevGetMTU:
* @ifname: interface name get MTU for * @ifname: interface name get MTU for
......
...@@ -112,6 +112,9 @@ int virNetDevTapCreate(char **ifname, ...@@ -112,6 +112,9 @@ int virNetDevTapCreate(char **ifname,
int virNetDevSetMAC(const char *ifname, int virNetDevSetMAC(const char *ifname,
const unsigned char *macaddr) const unsigned char *macaddr)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; 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 virNetDevSetMTU(const char *ifname,
int mtu) int mtu)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册