On 11/03/2011 01:30 PM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange"<berrange(a)redhat.com>
* src/util/bridge.c, src/util/bridge.h: Add virNetDevGetMAC
---
src/util/bridge.c | 35 +++++++++++++++++++++++++++++++++++
src/util/bridge.h | 3 +++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/src/util/bridge.c b/src/util/bridge.c
index 247ce93..3a7012c 100644
--- a/src/util/bridge.c
+++ b/src/util/bridge.c
@@ -358,6 +358,41 @@ cleanup:
}
/**
+ * 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
*
diff --git a/src/util/bridge.h b/src/util/bridge.h
index 0cc89c0..7504925 100644
--- a/src/util/bridge.h
+++ b/src/util/bridge.h
@@ -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;
I like the short patches :-)
ACK