aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers/linux_ioctl.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-01-03 20:17:08 (GMT)
committerJouni Malinen <j@w1.fi>2010-01-03 20:17:08 (GMT)
commit2ac9688eb884c27cb0e66470e3fd26b9d94c2999 (patch)
tree4f17d6c9739d6359836ddedc3b044b7350f549ce /src/drivers/linux_ioctl.c
parent34f2f814e08a08806e81047198bca08537bfa5bc (diff)
downloadhostap-2ac9688eb884c27cb0e66470e3fd26b9d94c2999.zip
hostap-2ac9688eb884c27cb0e66470e3fd26b9d94c2999.tar.gz
hostap-2ac9688eb884c27cb0e66470e3fd26b9d94c2999.tar.bz2
Use common driver code for Linux hwaddr get/set
Diffstat (limited to 'src/drivers/linux_ioctl.c')
-rw-r--r--src/drivers/linux_ioctl.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c
index 733bdb2..549ebb4 100644
--- a/src/drivers/linux_ioctl.c
+++ b/src/drivers/linux_ioctl.c
@@ -15,6 +15,7 @@
#include "utils/includes.h"
#include <sys/ioctl.h>
#include <net/if.h>
+#include <net/if_arp.h>
#include "utils/common.h"
#include "linux_ioctl.h"
@@ -54,3 +55,45 @@ int linux_set_iface_flags(int sock, const char *ifname, int dev_up)
return 0;
}
+
+
+int linux_get_ifhwaddr(int sock, const char *ifname, u8 *addr)
+{
+ struct ifreq ifr;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ if (ioctl(sock, SIOCGIFHWADDR, &ifr)) {
+ wpa_printf(MSG_ERROR, "Could not get interface %s hwaddr: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
+ wpa_printf(MSG_ERROR, "%s: Invalid HW-addr family 0x%04x",
+ ifname, ifr.ifr_hwaddr.sa_family);
+ return -1;
+ }
+ os_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+
+ return 0;
+}
+
+
+int linux_set_ifhwaddr(int sock, const char *ifname, const u8 *addr)
+{
+ struct ifreq ifr;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ os_memcpy(ifr.ifr_hwaddr.sa_data, addr, ETH_ALEN);
+ ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+
+ if (ioctl(sock, SIOCSIFHWADDR, &ifr)) {
+ wpa_printf(MSG_DEBUG, "Could not set interface %s hwaddr: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}