Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Jul 2012 06:11:27 +0000 (UTC)
From:      Adrian Chadd <adrian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r238646 - head/tools/tools/ath/athratestats
Message-ID:  <201207200611.q6K6BRFk063368@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adrian
Date: Fri Jul 20 06:11:26 2012
New Revision: 238646
URL: http://svn.freebsd.org/changeset/base/238646

Log:
  Tidy things up substantially:
  
  * remove some debugging;
  * introduce command line arguments;
  * introduce support for non-ath0 interfaces.

Modified:
  head/tools/tools/ath/athratestats/main.c

Modified: head/tools/tools/ath/athratestats/main.c
==============================================================================
--- head/tools/tools/ath/athratestats/main.c	Fri Jul 20 05:47:12 2012	(r238645)
+++ head/tools/tools/ath/athratestats/main.c	Fri Jul 20 06:11:26 2012	(r238646)
@@ -57,6 +57,12 @@
 
 #include "ath_rate/sample/sample.h"
 
+/*
+ * This needs to be big enough to fit the two TLVs, the rate table
+ * and the rate statistics table for a single node.
+ */
+#define	STATS_BUF_SIZE	8192
+
 struct ath_ratestats {
 	int s;
 	struct ath_rateioctl re;
@@ -159,20 +165,13 @@ ath_setsta(struct ath_ratestats *r, cons
 static void
 ath_rate_ioctl(struct ath_ratestats *r)
 {
-	printf("ether: %x:%x:%x:%x:%x:%x\n",
-	    r->re.is_u.macaddr[0],
-	    r->re.is_u.macaddr[1],
-	    r->re.is_u.macaddr[2],
-	    r->re.is_u.macaddr[3],
-	    r->re.is_u.macaddr[4],
-	    r->re.is_u.macaddr[5]);
+
 	if (ioctl(r->s, SIOCGATHNODERATESTATS, &r->re) < 0)
 		err(1, "ioctl");
 }
 
-#define	STATS_BUF_SIZE	8192
 int
-main(int argc, const char *argv[])
+main(int argc, char *argv[])
 {
 	struct ath_ratestats r;
 	struct ether_addr *e;
@@ -180,6 +179,33 @@ main(int argc, const char *argv[])
 	struct ath_rateioctl_tlv *av;
 	struct sample_node *sn = NULL;
 	struct ath_rateioctl_rt *rt = NULL;
+	char const *ifname = NULL, *macaddr = NULL;
+	int c;
+	int do_all = 0;
+
+	ifname = getenv("ATH");
+	if (ifname == NULL)
+		ifname = "ath0";
+
+	while ((c = getopt(argc, argv, "ahi:m:")) != -1) {
+		switch (c) {
+		case 'a':
+			do_all = 1;
+			break;
+		case 'i':
+			ifname = optarg;
+			break;
+		case 'm':
+			macaddr = optarg;
+			break;
+			
+		default:
+			errx(1,
+			    "usage: %s [-h] [-i ifname] [-a] [-m macaddr]\n",
+			    argv[0]);
+			/* NOTREACHED */
+		}
+	}
 
 	buf = calloc(1, STATS_BUF_SIZE);
 	if (buf == NULL)
@@ -191,11 +217,17 @@ main(int argc, const char *argv[])
 		err(1, "socket");
 	}
 	/* XXX error check */
-	ath_setifname(&r, "ath0");
+	ath_setifname(&r, ifname);
 
-	e = ether_aton(argv[1]);
+	if (macaddr == NULL) {
+		errx(1, "%s: macaddress wasn't supplied and no -a given\n",
+		    argv[0]);
+		/* NOTREACHED */
+	}
+	e = ether_aton(macaddr);
+	if (e == NULL)
+		err(1, "ether_aton");
 
-	/* caddr_t ? */
 	r.re.buf = buf;
 	r.re.len = STATS_BUF_SIZE;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201207200611.q6K6BRFk063368>