|
|
@@ -269,6 +269,7 @@ static int callback_stat(struct nl_msg *msg, void *arg)
|
|
|
} else {
|
|
|
stat->link = 0;
|
|
|
}
|
|
|
+ printf("____link: %d, signal: %d\n", stat->link, stat->signal);
|
|
|
|
|
|
return NL_OK;
|
|
|
}
|
|
|
@@ -472,7 +473,7 @@ static int nl80211_free(nl_handle_t *h)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-static int get_ipaddr(char *ifname, char *ipaddr)
|
|
|
+static int get_ipaddr(char *ifname, int family, char *ipaddr)
|
|
|
{
|
|
|
int r=-1;
|
|
|
struct ifaddrs *ifap, *ifa;
|
|
|
@@ -483,8 +484,8 @@ static int get_ipaddr(char *ifname, char *ipaddr)
|
|
|
}
|
|
|
|
|
|
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
|
|
- if (ifa->ifa_addr != NULL && strcmp(ifa->ifa_name, ifname)==0) {
|
|
|
- if(ifa->ifa_addr->sa_family==AF_INET) {
|
|
|
+ if (ifa->ifa_addr != NULL && strcmp(ifa->ifa_name, ifname)==0 && ifa->ifa_addr->sa_family==family) {
|
|
|
+ if(family==AF_INET) {
|
|
|
struct sockaddr_in *sa,*msk;
|
|
|
sa = (struct sockaddr_in *) ifa->ifa_addr;
|
|
|
msk = (struct sockaddr_in *) ifa->ifa_netmask;
|
|
|
@@ -513,7 +514,7 @@ static int nl_get_ip(ap_stat_t *stat)
|
|
|
int r;
|
|
|
|
|
|
stat->ipaddr[0] = 0;
|
|
|
- r = get_ipaddr(WLAN_IFNAME, stat->ipaddr);
|
|
|
+ r = get_ipaddr(WLAN_IFNAME, AF_INET, stat->ipaddr);
|
|
|
|
|
|
return r;
|
|
|
}
|
|
|
@@ -529,12 +530,13 @@ static int nl_get_signal(ap_stat_t *stat)
|
|
|
h = &nl;
|
|
|
|
|
|
stat->link = stat->signal = 0;
|
|
|
- genlmsg_put(h->msg, 0, 0, h->nl_id, 0, NLM_F_DUMP, NL80211_CMD_GET_STATION, 0); // Setup which command to run.
|
|
|
+ genlmsg_put(h->msg, 0, 0, h->nl_id, 0, 0, NL80211_CMD_GET_STATION, 0); // Setup which command to run.
|
|
|
nla_put_u32(h->msg, NL80211_ATTR_IFINDEX, h->ifindex); // Add message attribute, which interface to use.
|
|
|
- nl_socket_modify_cb(h->sock, NL_CB_VALID, NL_CB_CUSTOM, callback_stat, stat);
|
|
|
- r = nl_send_auto(h->sock, h->msg);
|
|
|
+ nl_cb_set(h->cb, NL_CB_VALID, NL_CB_CUSTOM, callback_stat, stat);
|
|
|
+ r = nl_send_auto_complete(h->sock, h->msg);
|
|
|
+ printf("__________________________r: %d\n", r);
|
|
|
if(r>=0) {
|
|
|
- nl_recvmsgs_default(h->sock);
|
|
|
+ nl_recvmsgs(h->sock, h->cb);
|
|
|
r = 0;
|
|
|
}
|
|
|
nl80211_free(h);
|
|
|
@@ -786,4 +788,5 @@ int wifi_list_free(ap_list_t *list)
|
|
|
list->cnt = 0;
|
|
|
list->info = NULL;
|
|
|
return 0;
|
|
|
-}
|
|
|
+}
|
|
|
+
|