qsap: Add API to get device mac address based on interface name.
This adds new API linux_get_ifhwaddr() which can be used to get mac address of input interface. IOCTL SIOCGIFHWADDR is used to get the interface address. CRs-Fixed: 2080924 Change-Id: I1b825fb2c1f35280d2d57928be4f87d23d78decb
This commit is contained in:
committed by
Gerrit - the friendly Code Review server
parent
a7c3aa8a21
commit
0e5ec067f7
@@ -45,6 +45,7 @@
|
||||
#include <unistd.h>
|
||||
#include <private/android_filesystem_config.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <netlink/netlink.h>
|
||||
#include <netlink/genl/genl.h>
|
||||
#include <netlink/genl/family.h>
|
||||
@@ -3469,6 +3470,33 @@ int qsap_control_bridge(int argc, char ** argv)
|
||||
}
|
||||
|
||||
|
||||
int linux_get_ifhwaddr(const char *ifname, char *addr)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
#ifndef MAC2STR
|
||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#endif
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
||||
if (ioctl(sock, SIOCGIFHWADDR, &ifr)) {
|
||||
ALOGE("Could not get interface %s hwaddr: %s", ifname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
|
||||
ALOGE("%s: Invalid HW-addr family 0x%04x", ifname, ifr.ifr_hwaddr.sa_family);
|
||||
return -1;
|
||||
}
|
||||
memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
|
||||
ALOGE("%s: " MACSTR, ifname, MAC2STR(addr));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int qsap_add_or_remove_interface(const char *newIface , int createIface)
|
||||
{
|
||||
const char *wlanIface = "wlan0";
|
||||
|
||||
@@ -618,6 +618,7 @@ int qsap_prepare_softap(void);
|
||||
int qsap_unprepare_softap(void);
|
||||
int qsap_is_fst_enabled(void);
|
||||
int qsap_control_bridge(int argc, char ** argv);
|
||||
int linux_get_ifhwaddr(const char *ifname, char *addr);
|
||||
|
||||
#if __cplusplus
|
||||
}; // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user