From 7d71de5a36bda0b7583f7e513b481ba1906c008d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 12 Jul 2009 00:21:38 -0700 Subject: [PATCH] Use interface index to resolve interface name --- plugins/supplicant.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/plugins/supplicant.c b/plugins/supplicant.c index 8f185e0..92668f8 100644 --- a/plugins/supplicant.c +++ b/plugins/supplicant.c @@ -254,22 +254,34 @@ static char *get_bssid(struct connman_device *device) { char *bssid; unsigned char ioctl_bssid[ETH_ALEN]; - int fd, ret; + int ifindex; + char *ifname; struct iwreq wrq; + int fd, err; + + ifindex = connman_device_get_index(device); + if (ifindex < 0) + return NULL; - if (connman_device_get_type(device) != CONNMAN_DEVICE_TYPE_WIFI) + ifname = connman_inet_ifname(ifindex); + if (ifname == NULL) return NULL; fd = socket(PF_INET, SOCK_DGRAM, 0); - if (fd < 0) + if (fd < 0) { + g_free(ifname); return NULL; + } memset(&wrq, 0, sizeof(wrq)); - strncpy(wrq.ifr_name, connman_device_get_interface(device), IFNAMSIZ); + strncpy(wrq.ifr_name, ifname, IFNAMSIZ); + + err = ioctl(fd, SIOCGIWAP, &wrq); - ret = ioctl(fd, SIOCGIWAP, &wrq); + g_free(ifname); close(fd); - if (ret != 0) + + if (err < 0) return NULL; memcpy(ioctl_bssid, wrq.u.ap_addr.sa_data, ETH_ALEN); -- 2.7.4