From ebc135537083c0ad2b9aa47796c759eaa7f3995c Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 12 Jun 2007 00:24:33 +0000 Subject: Optionally lock down athsta to a single mac address. See #210 --- athsta.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/athsta.c b/athsta.c index 363f0d7..178d2cc 100644 --- a/athsta.c +++ b/athsta.c @@ -29,7 +29,9 @@ static char name[IFNAMSIZ]; /* name of interface */ static int verbose = 0; +static int only_remote = 0; static uint8_t localaddr[6] = { 0, }; +static struct ether_addr remaddr; static u_int ieee80211_mhz2ieee(u_int freq) @@ -198,7 +200,7 @@ list_stations(int s, int head) struct ieee80211req_sta_info *si, *ni; uint8_t *vp; uint8_t *cp; - int len; + int len, print; (void) memset(&ireq, 0, sizeof(ireq)); (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); @@ -240,8 +242,16 @@ list_stations(int s, int head) if (len < sizeof(struct ieee80211req_sta_info)) ni = NULL; - if (memcmp(localaddr, si->isi_macaddr, sizeof(localaddr)) != 0 && - (!ni || memcmp(ni->isi_macaddr, si->isi_macaddr, sizeof(ni->isi_macaddr)) != 0)) { + print = 0; + + if (memcmp (localaddr, si->isi_macaddr, sizeof (localaddr)) != 0 && + (!ni || memcmp (ni->isi_macaddr, si->isi_macaddr, sizeof (ni->isi_macaddr)) != 0)) + print = 1; + + if (only_remote) + print = (memcmp(&remaddr, si->isi_macaddr, sizeof (remaddr)) == 0); + + if (print) { printf("%s %4u %4d %3dM %4d %4d %6d %6d %-4.4s %3x" , ether_ntoa((const struct ether_addr*) si->isi_macaddr) , IEEE80211_AID(si->isi_associd) @@ -284,26 +294,35 @@ load_lladdr (int s) int main (int argc, char* argv[]) { - int s, i; + struct ether_addr *eth; + int s, i; - if(argc != 2) { - fprintf(stderr, "usage: athsta \n"); - exit(2); - } + if (argc < 2 || argc > 3) { + fprintf (stderr, "usage: athsta [macaddr]\n"); + exit (2); + } - strncpy(name, argv[1], sizeof (name)); - name[sizeof (name) - 1] = 0; + strncpy (name, argv[1], sizeof (name)); + name[sizeof (name) - 1] = 0; + + if (argc == 3) { + eth = ether_aton (argv[2]); + if (!eth) + err (1, "invalid mac address: %s", argv[2]); + memcpy (&remaddr, eth, sizeof (remaddr)); + only_remote = 1; + } if ((s = socket (AF_INET, SOCK_DGRAM, 0)) < 0) err(1, "creating socket failed"); load_lladdr (s); - for (i = 0; ; i++) { - list_stations (s, !(i % 10)); + for (i = 0; ; i++) { + list_stations (s, !(i % 10)); fflush(stdout); - sleep (1); - } + sleep (1); + } - return 0; + return 0; } -- cgit v1.2.3