aboutsummaryrefslogtreecommitdiffstats
path: root/iw_if.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2014-01-25 00:07:31 +0000
committerJonathan McCrohan <jmccrohan@gmail.com>2014-01-25 00:07:31 +0000
commitb7fe9575ab40a3bcde643a8ae8750ca6fd2aaad7 (patch)
treed220eddc3489f44845e9855e901290f7f712a626 /iw_if.c
parentbea11309641a93ea51622fc85331d3960011afe4 (diff)
parentd7ca0c3e555ef0b5250873ddce48ccf2326b017a (diff)
downloadwavemon-b7fe9575ab40a3bcde643a8ae8750ca6fd2aaad7.tar.gz
Merge tag 'upstream/0.7.6'
Upstream version 0.7.6
Diffstat (limited to 'iw_if.c')
-rw-r--r--iw_if.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/iw_if.c b/iw_if.c
index 8a635f6..97718c4 100644
--- a/iw_if.c
+++ b/iw_if.c
@@ -39,16 +39,20 @@ static int if_get_flags(int skfd, const char *ifname)
return ifr.ifr_flags;
}
-/* Return true if @ifname is known to be up */
+/* Return true if @ifname is known to be up. */
bool if_is_up(int skfd, const char *ifname)
{
return if_get_flags(skfd, ifname) & IFF_UP;
}
/** Bring @ifname up if not already up. Return 0 if ok, < 0 on error. */
-int if_set_up(int skfd, const char *ifname)
+int if_set_up(const char *ifname)
{
struct ifreq ifr;
+ int ret, skfd = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (skfd < 0)
+ err_sys("%s: can not open socket", __func__);
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
@@ -58,7 +62,9 @@ int if_set_up(int skfd, const char *ifname)
return 0;
ifr.ifr_flags |= IFF_UP;
- return ioctl(skfd, SIOCSIFFLAGS, &ifr);
+ ret = ioctl(skfd, SIOCSIFFLAGS, &ifr);
+ close(skfd);
+ return ret;
}
/* Interface information */
@@ -128,6 +134,8 @@ char **iw_get_interface_list(void)
continue;
if_list = realloc(if_list, sizeof(char *) * (nifs + 1));
+ if (if_list == NULL)
+ err_sys("can not reallocate interface list");
if_list[nifs-1] = strdup(p);
if_list[nifs++] = NULL;
}
@@ -157,7 +165,7 @@ void if_getstat(const char *ifname, struct if_stat *stat)
lp += strlen(ifname) + 1;
lp += strspn(lp, " ");
- sscanf(lp, "%llu %llu %lu %lu %lu %lu %lu %lu %llu %llu",
+ sscanf(lp, "%Lu %Lu %lu %lu %lu %lu %lu %lu %Lu %Lu",
&stat->rx_bytes, &stat->rx_packets, &d, &d, &d, &d, &d, &d,
&stat->tx_bytes, &stat->tx_packets);
}
@@ -304,7 +312,9 @@ void dyn_info_cleanup(struct iw_dyn_info *info)
/*
- * get range information
+ * Request range information for a given wireless interface.
+ * @ifname: name of the wireless argument
+ * @range: storage location to populate with range information.
*/
void iw_getinf_range(const char *ifname, struct iw_range *range)
{
@@ -468,6 +478,17 @@ void iw_getstat(struct iw_stat *iw)
iw_sanitize(&iw->range, &iw->stat.qual, &iw->dbm);
}
+const char *we_version(void)
+{
+ static char buf[BUFSIZ];
+ struct iw_stat iw;
+
+ iw_getinf_range(conf_ifname(), &iw.range);
+ sprintf(buf, "wireless extensions v%d (source v%d)",
+ iw.range.we_version_compiled, iw.range.we_version_source);
+ return buf;
+}
+
void dump_parameters(void)
{
struct iw_dyn_info info;
@@ -501,8 +522,7 @@ void dump_parameters(void)
}
printf("\n");
}
- printf(" WE version: %d (source version %d)\n\n",
- iw.range.we_version_compiled, iw.range.we_version_source);
+ printf("\n");
if (info.cap_essid) {
if (info.essid_ct > 1)