Hi List,
This is the current patch for the iw-3.3 that is enhanced to
display mpp_paths and known_gates paths for "mpath dump" and
"mpath get".
For this enhancement to work, mac80211 and cfg80211 should also
be patched. This patch will be sent in a separate message.
The motivation behind this patch is to provide a better tool
that we can use when we actually operate production meshes,
as well as providing a tool to peek into the various paths
in the path lists, in the kernel.
This is not a proposed patch, only intended to share some
experiences with the such tool among member of the list.
It also displays symbolic names rather than numeric values
for MAC addresses and BSSIDs for all commands, if they are
found in /etc/ethers. This enhancement does not require the
mac80211 and cfg80211 patch.
Changes:
o "mpath dump" and "mpath get" understands extended flag values
that indicates which of the three path lists, i.e., regular
mpath, mpp_paths and known_gate paths, each path belongs to.
As far as my experience, all paths in known_gate paths
also appear in the regular path list, but it is included for
safety.
o The "Next" field is now "Next/Gate" field, to reflect the
above change. If a path is a regular path, then it's "Next",
otherwise it's "Gate".
o The "Next/Gate" field shows "<direct>" if Dest == Next/Gate.
o Flags are now printed symbolically:
A = Active
F = Fixed
r = Resolving
R = Resolved
G = Gateway path (in the regular path list)
T = Root path
P = Path in "mpp_paths" list (rest of the fields will be empty)
g = Path in "known_gates" list (ditto)
The "Serial number valid" flag is not displayed, but expressed
as SN field having some numeric value. If this flag is absent,
then the SN field will be empty.
o ExpTime, Dtim and Dret fields are dropped by default to keep the
width of one line < 80. A new "-w" (for wide) option at the end
of the command line will display these fields.
o The ExpTime field, even when it is enabled with the "-w" option,
a value will be printed only if the path is active. (Current
kernel code doesn't care the exptime of in-active paths.)
o MAC addresses are, by default, and for all commands, printed
symbolically if they are found in the /etc/ethers file, according
to the following rule.
- If a MAC address is found in the file, and the corresponding
name is less than or equals to 17 characters in length,
then the name is printed.
- If the name exceeds 17 characters in length, it will be
truncated to 16 characters, and a plus sign ('+') is added
at the end to indicate the overflow status.
- If the address doesn't match, then the vender part of the
address is extracted and searched in the /etc/ethers again.
- If the vendor entry (last 3 octets = "00:00:00") is found,
and the corresponding name is less than or equals to 8
characters in length, then the name is concatenated with
the numeric representation of the non-vender part of the
address, with colon (":") as a separator.
- If the vendor name is longer than 8 characters in length,
then it is truncated to 8 characters, and concatenated
with the numeric representation of the non-vender part of
the address, with plus sign ("+") as a separator.
o If the behavior of the symbolic address printing is undesirable,
it can be suppressed with global option "-n",
e.g. "iw -n mesh0 mpath dump".
o The global option "-N" will print both symbolic and numeric addresses.
o Symbolic addresses can also be used for input if they are "deterministic".
Deterministic means that a name has one-to-one correspondence with
a non-vender entry in the /etc/ethers file. Names with vender part,
names with plus sign ("+") are not deterministic. This means that
output/input is (sometimes) asymmetric.
o The patched iw will detect unpatched kernel and displays a
warning message. If this is annoying, an environment variable
IW_MPATH_FLAGS8 will stop it.
Enjoy,
--- shinoda
---
diff --git a/event.c b/event.c
index bc39662..3826d35 100644
--- a/event.c
+++ b/event.c
@@ -60,10 +60,10 @@ static void print_frame(struct print_event_args *args,
struct nlattr *attr)
goto print_frame;
}
- mac_addr_n2a(macbuf, frame + 10);
- printf(" %s -> ", macbuf);
- mac_addr_n2a(macbuf, frame + 4);
- printf("%s", macbuf);
+ printf(" ");
+ iw_print_macaddr(frame + 10);
+ printf(" -> ", macbuf);
+ iw_print_macaddr(frame + 4);
switch (frame[0] & 0xfc) {
case 0x10: /* assoc resp */
@@ -129,10 +129,13 @@ static void parse_cqm_event(struct nlattr **attrs)
attrs[NL80211_ATTR_MAC]) {
uint32_t frames;
char buf[3*6];
+ unsigned char *peerdata;
frames = nla_get_u32(cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT]);
- mac_addr_n2a(buf, nla_data(attrs[NL80211_ATTR_MAC]));
- printf("peer %s didn't ACK %d packets\n", buf, frames);
+ peerdata = nla_data(attrs[NL80211_ATTR_MAC]);
+ printf("peer ");
+ iw_print_macaddr(peerdata);
+ printf(" didn't ACK %d packets\n", buf, frames);
} else
printf("unknown event\n");
}
@@ -159,8 +162,10 @@ static void parse_mic_failure(struct nlattr **attrs)
if (attrs[NL80211_ATTR_MAC]) {
char addr[3 * ETH_ALEN];
- mac_addr_n2a(addr, nla_data(attrs[NL80211_ATTR_MAC]));
- printf(" source MAC address %s", addr);
+ unsigned char *srcdata;
+ srcdata = nla_data(attrs[NL80211_ATTR_MAC]);
+ printf(" source MAC address ");
+ iw_print_macaddr(addr);
}
if (attrs[NL80211_ATTR_KEY_SEQ] &&
@@ -189,6 +194,7 @@ static int print_event(struct nl_msg *msg, void *arg)
struct nlattr *tb[NL80211_ATTR_MAX + 1], *nst;
struct print_event_args *args = arg;
char ifname[100];
+ unsigned char *macdata;
char macbuf[6*3];
__u8 reg_type;
struct ieee80211_beacon_channel chan_before_beacon, chan_after_beacon;
@@ -318,16 +324,17 @@ static int print_event(struct nl_msg *msg, void *arg)
break;
case NL80211_CMD_NEW_STATION:
- mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC]));
- printf("new station %s\n", macbuf);
+ macdata = nla_data(tb[NL80211_ATTR_MAC]);
+ iw_print_macanddev("new station ", macdata, NULL);
break;
case NL80211_CMD_DEL_STATION:
- mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC]));
- printf("del station %s\n", macbuf);
+ macdata = nla_data(tb[NL80211_ATTR_MAC]);
+ iw_print_macanddev("del station ", macdata, NULL);
break;
case NL80211_CMD_JOIN_IBSS:
- mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC]));
- printf("IBSS %s joined\n", macbuf);
+ macdata = nla_data(tb[NL80211_ATTR_MAC]);
+ iw_print_macanddev("IBSS", macdata, NULL);
+ printf(" joined\n");
break;
case NL80211_CMD_AUTHENTICATE:
printf("auth");
@@ -380,8 +387,8 @@ static int print_event(struct nl_msg *msg, void *arg)
printf("failed to connect");
}
if (tb[NL80211_ATTR_MAC]) {
- mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC]));
- printf(" to %s", macbuf);
+ macdata = nla_data(tb[NL80211_ATTR_MAC]);
+ iw_print_macanddev(" to ", macdata, NULL);
}
if (status)
printf(", status: %d: %s", status,
get_status_str(status));
@@ -390,8 +397,8 @@ static int print_event(struct nl_msg *msg, void *arg)
case NL80211_CMD_ROAM:
printf("roamed");
if (tb[NL80211_ATTR_MAC]) {
- mac_addr_n2a(macbuf, nla_data(tb[NL80211_ATTR_MAC]));
- printf(" to %s", macbuf);
+ macdata = nla_data(tb[NL80211_ATTR_MAC]);
+ iw_print_macanddev(" to ", macdata, NULL);
}
printf("\n");
break;
diff --git a/iw.c b/iw.c
index b5e668c..00d381c 100644
--- a/iw.c
+++ b/iw.c
@@ -37,6 +37,7 @@ static inline void nl_socket_free(struct nl_sock *h)
#endif /* CONFIG_LIBNL20 && CONFIG_LIBNL30 */
int iw_debug = 0;
+int iw_macpmode = MAC_PRINT_MODE_SYMBOLIC;
static int nl80211_init(struct nl80211_state *state)
{
@@ -145,6 +146,8 @@ static void usage(bool full)
printf("Usage:\t%s [options] command\n", argv0);
usage_options();
printf("\t--version\tshow version (%s)\n", iw_version);
+ printf("\t-n\tdo not show symbolic addresses\n");
+ printf("\t-N\tshow symbolic and numeric addresses\n");
printf("Commands:\n");
for_each_cmd(section) {
if (section->parent)
@@ -427,17 +430,25 @@ int main(int argc, char **argv)
argc--;
argv0 = *argv++;
- if (argc > 0 && strcmp(*argv, "--debug") == 0) {
- iw_debug = 1;
+ while (argc > 0 && **argv == '-') {
+ if (argc > 0 && strcmp(*argv, "--version") == 0) {
+ version();
+ return 0;
+ }
+
+ if (argc > 0 && strcmp(*argv, "--debug") == 0)
+ iw_debug = 1;
+
+ if (argc > 0 && strcmp(*argv, "-n") == 0)
+ iw_macpmode = MAC_PRINT_MODE_NUMERIC;
+
+ if (argc > 0 && strcmp(*argv, "-N") == 0)
+ iw_macpmode = MAC_PRINT_MODE_BOTH;
+
argc--;
argv++;
}
- if (argc > 0 && strcmp(*argv, "--version") == 0) {
- version();
- return 0;
- }
-
/* need to treat "help" command specially so it works w/o nl80211 */
if (argc == 0 || strcmp(*argv, "help") == 0) {
usage(argc != 0);
diff --git a/iw.h b/iw.h
index 3379a7f..508a9b9 100644
--- a/iw.h
+++ b/iw.h
@@ -160,6 +160,17 @@ enum print_ie_type {
PRINT_LINK,
};
+extern int iw_macpmode;
+
+#define MAC_PRINT_MODE_SYMBOLIC (1 << 0)
+#define MAC_PRINT_MODE_NUMERIC (1 << 1)
+#define MAC_PRINT_MODE_BOTH (MAC_PRINT_MODE_SYMBOLIC|MAC_PRINT_MODE_NUMERIC)
+
+#define sprintmac(buf, mac) \
+ sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", \
+ (mac)[0], (mac)[1], (mac)[2], \
+ (mac)[3], (mac)[4], (mac)[5])
+
#define BIT(x) (1ULL<<(x))
void print_ies(unsigned char *ie, int ielen, bool unknown,
diff --git a/link.c b/link.c
index 11ee0aa..a6dc412 100644
--- a/link.c
+++ b/link.c
@@ -39,6 +39,7 @@ static int link_bss_handler(struct nl_msg *msg, void *arg)
};
struct link_result *result = arg;
char mac_addr[20], dev[20];
+ char *macdata;
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
@@ -60,18 +61,18 @@ static int link_bss_handler(struct nl_msg *msg, void *arg)
if (!bss[NL80211_BSS_STATUS])
return NL_SKIP;
- mac_addr_n2a(mac_addr, nla_data(bss[NL80211_BSS_BSSID]));
+ macdata = nla_data(bss[NL80211_BSS_BSSID]);
if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
switch (nla_get_u32(bss[NL80211_BSS_STATUS])) {
case NL80211_BSS_STATUS_ASSOCIATED:
- printf("Connected to %s (on %s)\n", mac_addr, dev);
+ iw_print_macanddev("Connected to ", macdata, dev);
break;
case NL80211_BSS_STATUS_AUTHENTICATED:
- printf("Authenticated with %s (on %s)\n", mac_addr, dev);
+ iw_print_macanddev("Authenticated with ", macdata, dev);
return NL_SKIP;
case NL80211_BSS_STATUS_IBSS_JOINED:
- printf("Joined IBSS %s (on %s)\n", mac_addr, dev);
+ iw_print_macanddev("Joined IBSS ", macdata, dev);
break;
default:
return NL_SKIP;
diff --git a/mpath.c b/mpath.c
index 3afe7b7..0195ce6 100644
--- a/mpath.c
+++ b/mpath.c
@@ -8,27 +8,15 @@
#include <netlink/msg.h>
#include <netlink/attr.h>
+#include <netinet/ether.h>
+
#include "nl80211.h"
#include "iw.h"
-SECTION(mpath);
-
-enum plink_state {
- LISTEN,
- OPN_SNT,
- OPN_RCVD,
- CNF_RCVD,
- ESTAB,
- HOLDING,
- BLOCKED
-};
-
-enum plink_actions {
- PLINK_ACTION_UNDEFINED,
- PLINK_ACTION_OPEN,
- PLINK_ACTION_BLOCK,
-};
+bool widemode = false;
+bool anyiface = false;
+SECTION(mpath);
static int print_mpath_handler(struct nl_msg *msg, void *arg)
{
@@ -43,8 +31,11 @@ static int print_mpath_handler(struct nl_msg *msg, void *arg)
[NL80211_MPATH_INFO_EXPTIME] = { .type = NLA_U32 },
[NL80211_MPATH_INFO_DISCOVERY_TIMEOUT] = { .type = NLA_U32 },
[NL80211_MPATH_INFO_DISCOVERY_RETRIES] = { .type = NLA_U8 },
- [NL80211_MPATH_INFO_FLAGS] = { .type = NLA_U8 },
+ [NL80211_MPATH_INFO_FLAGS] = { .type = NLA_U32 },
};
+ uint32_t flags;
+ uint8_t *dstmac, *nxtmac;
+ char flagbuf[10], *flagp;
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
@@ -66,33 +57,96 @@ static int print_mpath_handler(struct nl_msg *msg, void
*arg)
return NL_SKIP;
}
- mac_addr_n2a(dst, nla_data(tb[NL80211_ATTR_MAC]));
- mac_addr_n2a(next_hop, nla_data(tb[NL80211_ATTR_MPATH_NEXT_HOP]));
+ dstmac = nla_data(tb[NL80211_ATTR_MAC]);
+ nxtmac = nla_data(tb[NL80211_ATTR_MPATH_NEXT_HOP]);
+
+ if (iw_macpmode & MAC_PRINT_MODE_SYMBOLIC) {
+ mac_addr_n2a(dst, dstmac);
+ mac_addr_n2a(next_hop, nxtmac);
+ } else {
+ sprintmac(dst, dstmac);
+ sprintmac(next_hop, nxtmac);
+ }
+
+ printf("%s ", dst);
+
+ if (memcmp(dstmac, nxtmac, 6) == 0)
+ printf("<direct> ");
+ else
+ printf("%s ", next_hop);
+
if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
- printf("%s %s %s", dst, next_hop, dev);
- if (pinfo[NL80211_MPATH_INFO_SN])
- printf("\t%u",
- nla_get_u32(pinfo[NL80211_MPATH_INFO_SN]));
- if (pinfo[NL80211_MPATH_INFO_METRIC])
- printf("\t%u",
- nla_get_u32(pinfo[NL80211_MPATH_INFO_METRIC]));
- if (pinfo[NL80211_MPATH_INFO_FRAME_QLEN])
- printf("\t%u",
- nla_get_u32(pinfo[NL80211_MPATH_INFO_FRAME_QLEN]));
- if (pinfo[NL80211_MPATH_INFO_EXPTIME])
- printf("\t%u",
- nla_get_u32(pinfo[NL80211_MPATH_INFO_EXPTIME]));
- if (pinfo[NL80211_MPATH_INFO_DISCOVERY_TIMEOUT])
- printf("\t%u",
- nla_get_u32(pinfo[NL80211_MPATH_INFO_DISCOVERY_TIMEOUT]));
- if (pinfo[NL80211_MPATH_INFO_DISCOVERY_RETRIES])
- printf("\t%u",
- nla_get_u8(pinfo[NL80211_MPATH_INFO_DISCOVERY_RETRIES]));
- if (pinfo[NL80211_MPATH_INFO_FLAGS])
- printf("\t0x%x",
- nla_get_u8(pinfo[NL80211_MPATH_INFO_FLAGS]));
+
+ printf("%-8s", dev);
+
+ flagp = flagbuf;
+
+ if (pinfo[NL80211_MPATH_INFO_FLAGS]) {
+ flags = nla_get_u32(pinfo[NL80211_MPATH_INFO_FLAGS]);
+ if (flags & NL80211_MPATH_FLAG_ACTIVE)
+ *flagp++ = 'A';
+ if (flags & NL80211_MPATH_FLAG_FIXED)
+ *flagp++ = 'F';
+ if (flags & NL80211_MPATH_FLAG_IS_MPPPATH)
+ *flagp++ = 'P';
+ if (flags & NL80211_MPATH_FLAG_IS_KNOWN_GATE)
+ *flagp++ = 'g';
+ else if (flags & NL80211_MPATH_FLAG_IS_GATE)
+ *flagp++ = 'G';
+ if (flags & NL80211_MPATH_FLAG_IS_ROOT)
+ *flagp++ = 'T';
+ if (flags & NL80211_MPATH_FLAG_RESOLVING)
+ *flagp++ = 'r';
+ if (flags & NL80211_MPATH_FLAG_RESOLVED)
+ *flagp++ = 'R';
+ // if (flags & NL80211_MPATH_FLAG_SN_VALID)
+ // *flagp++ = 'S';
+ } else {
+ *flagp++ = '-';
+ }
+
+ *flagp = 0;
+ printf("%-9s", flagbuf);
+
+ if (!(flags & NL80211_MPATH_FLAG_IS_MPPPATH)) {
+ if (pinfo[NL80211_MPATH_INFO_SN])
+ if (flags & NL80211_MPATH_FLAG_SN_VALID)
+ printf("%-8u",
+
nla_get_u32(pinfo[NL80211_MPATH_INFO_SN]));
+ else
+ printf("%-8s", "-");
+ if (pinfo[NL80211_MPATH_INFO_METRIC])
+ printf("%-7u",
+ nla_get_u32(pinfo[NL80211_MPATH_INFO_METRIC]));
+ if (pinfo[NL80211_MPATH_INFO_FRAME_QLEN])
+ printf("%-5u",
+ nla_get_u32(pinfo[NL80211_MPATH_INFO_FRAME_QLEN]));
+
+ if (widemode) {
+ if (pinfo[NL80211_MPATH_INFO_EXPTIME])
+ printf("%-6u",
+
nla_get_u32(pinfo[NL80211_MPATH_INFO_EXPTIME]));
+
+ if (pinfo[NL80211_MPATH_INFO_DISCOVERY_TIMEOUT])
+ printf("%-5u",
+
nla_get_u32(pinfo[NL80211_MPATH_INFO_DISCOVERY_TIMEOUT]));
+ if (pinfo[NL80211_MPATH_INFO_DISCOVERY_RETRIES])
+ printf("%-3u",
+
nla_get_u8(pinfo[NL80211_MPATH_INFO_DISCOVERY_RETRIES]));
+ }
+ }
printf("\n");
+
+ if (iw_macpmode == MAC_PRINT_MODE_BOTH) {
+ sprintmac(dst, dstmac);
+ if (memcmp(dstmac, nxtmac, ETH_ALEN) != 0)
+ sprintmac(next_hop, nxtmac);
+ else
+ next_hop[0] = 0;
+ printf("%-.17s %-.17s\n", dst, next_hop);
+ }
+
return NL_SKIP;
}
@@ -113,9 +167,6 @@ static int handle_mpath_get(struct nl80211_state *state,
argc--;
argv++;
- if (argc)
- return 1;
-
NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_mpath_handler, NULL);
@@ -184,11 +235,28 @@ static int handle_mpath_dump(struct nl80211_state *state,
struct nl_msg *msg,
int argc, char **argv)
{
- printf("DEST ADDR NEXT HOP IFACE\tSN\tMETRIC\tQLEN\t"
- "EXPTIME\t\tDTIM\tDRET\tFLAGS\n");
+ for ( ; argc ; argc--) {
+ if (strcmp(*argv, "-w") == 0) {
+ widemode = true;
+ continue;
+ }
+ if (strcmp(*argv, "-a") == 0) {
+ anyiface = true;
+ continue;
+ }
+ return 1;
+ }
+
+ printf("Dest Next/Gate Iface Flags SN
Metric Qlen");
+ if (widemode)
+ printf(" Exp Dtim Dret\n");
+ else
+ printf("\n");
+
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_mpath_handler, NULL);
+
return 0;
}
-COMMAND(mpath, dump, NULL,
+COMMAND(mpath, dump, "[-w|-a]",
NL80211_CMD_GET_MPATH, NLM_F_DUMP, CIB_NETDEV, handle_mpath_dump,
"List known mesh paths.");
diff --git a/nl80211.h b/nl80211.h
index 0d1a386..ce7ea22 100644
--- a/nl80211.h
+++ b/nl80211.h
@@ -1742,6 +1742,10 @@ enum nl80211_mpath_flags {
NL80211_MPATH_FLAG_SN_VALID = 1<<2,
NL80211_MPATH_FLAG_FIXED = 1<<3,
NL80211_MPATH_FLAG_RESOLVED = 1<<4,
+ NL80211_MPATH_FLAG_IS_ROOT = 1<<5,
+ NL80211_MPATH_FLAG_IS_GATE = 1<<6,
+ NL80211_MPATH_FLAG_IS_MPPPATH = 1<<7,
+ NL80211_MPATH_FLAG_IS_KNOWN_GATE = 1<<8,
};
/**
diff --git a/scan.c b/scan.c
index 110e1d3..17a1cba 100644
--- a/scan.c
+++ b/scan.c
@@ -1126,6 +1126,7 @@ static int print_bss_handler(struct nl_msg *msg, void
*arg)
};
struct scan_params *params = arg;
int show = params->show_both_ie_sets ? 2 : 1;
+ unsigned char *bssdat;
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
@@ -1144,9 +1145,9 @@ static int print_bss_handler(struct nl_msg *msg, void
*arg)
if (!bss[NL80211_BSS_BSSID])
return NL_SKIP;
- mac_addr_n2a(mac_addr, nla_data(bss[NL80211_BSS_BSSID]));
+ bssdat = nla_data(bss[NL80211_BSS_BSSID]);
if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
- printf("BSS %s (on %s)", mac_addr, dev);
+ iw_print_macanddev("BSS", bssdat, dev);
if (bss[NL80211_BSS_STATUS]) {
switch (nla_get_u32(bss[NL80211_BSS_STATUS])) {
diff --git a/station.c b/station.c
index 6b3d21d..611d2f5 100644
--- a/station.c
+++ b/station.c
@@ -115,6 +115,7 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
[NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED },
};
char *chain;
+ unsigned char *staaddr;
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
@@ -136,9 +137,9 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
return NL_SKIP;
}
- mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC]));
+ staaddr = nla_data(tb[NL80211_ATTR_MAC]);
if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
- printf("Station %s (on %s)", mac_addr, dev);
+ iw_print_macanddev("Station", staaddr, dev);
if (sinfo[NL80211_STA_INFO_INACTIVE_TIME])
printf("\n\tinactive time:\t%u ms",
diff --git a/util.c b/util.c
index 103ded9..b7ea69a 100644
--- a/util.c
+++ b/util.c
@@ -5,46 +5,109 @@
#include "iw.h"
#include "nl80211.h"
-void mac_addr_n2a(char *mac_addr, unsigned char *arg)
+#include <netinet/ether.h>
+#include <string.h>
+
+void
+iw_print_macaddr(unsigned char *addr)
{
- int i, l;
+ char mac_addr[20];
+
+ if (iw_macpmode & MAC_PRINT_MODE_SYMBOLIC) {
+ mac_addr_n2a(mac_addr, addr);
+ printf("%s ", mac_addr);
+ }
+ if (iw_macpmode & MAC_PRINT_MODE_NUMERIC) {
+ sprintmac(mac_addr, addr);
+ printf(iw_macpmode == MAC_PRINT_MODE_BOTH ? "(%s)" : "%s",
+ mac_addr);
+ }
+}
- l = 0;
- for (i = 0; i < ETH_ALEN ; i++) {
- if (i == 0) {
- sprintf(mac_addr+l, "%02x", arg[i]);
- l += 2;
- } else {
- sprintf(mac_addr+l, ":%02x", arg[i]);
- l += 3;
+void
+iw_print_macanddev(char *label, unsigned char *addr, char *dev)
+{
+ char mac_addr[20];
+
+ printf("%s ", label);
+ iw_print_macaddr(addr);
+ if (dev)
+ printf(" on %s", dev);
+}
+
+char *
+iw_ether_b2host(char *addr)
+{
+ static char namebuf[128];
+ static char ouibuf[128];
+ struct ether_addr binmac;
+ struct ether_addr binoui;
+
+ memcpy(binmac.ether_addr_octet, addr, 6);
+
+ if (ether_ntohost(namebuf, &binmac) == 0) {
+ if (strlen(namebuf) > 17) {
+ namebuf[16] = '+';
+ namebuf[17] = 0;
}
+ return(namebuf);
+ }
+
+ memcpy(binoui.ether_addr_octet, addr, 3);
+ memset(&binoui.ether_addr_octet[3], 0, 3);
+
+ if (ether_ntohost(ouibuf, &binoui) == 0) {
+ if (strlen(ouibuf) > 8) {
+ ouibuf[8] = '+';
+ ouibuf[9] = 0;
+ } else
+ strcat(ouibuf, ":");
+
+ sprintf(namebuf, "%-0.9s%x:%x:%x", ouibuf,
+ addr[3] & 0xff, addr[4] & 0xff, addr[5] & 0xff);
+
+ return(namebuf);
}
+
+ return(ether_ntoa(&binmac));
}
-int mac_addr_a2n(unsigned char *mac_addr, char *arg)
+int
+iw_ether_host2b(char *name, char *binaddr)
{
- int i;
+ struct ether_addr binmac;
+ struct ether_addr *p;
+ char *sep;
- for (i = 0; i < ETH_ALEN ; i++) {
- int temp;
- char *cp = strchr(arg, ':');
- if (cp) {
- *cp = 0;
- cp++;
- }
- if (sscanf(arg, "%x", &temp) != 1)
- return -1;
- if (temp < 0 || temp > 255)
- return -1;
+ if (ether_hostton(name, &binmac) == 0) {
+ memcpy(binaddr, binmac.ether_addr_octet, 6);
+ return 0;
+ }
- mac_addr[i] = temp;
- if (!cp)
- break;
- arg = cp;
+ if (p = ether_aton(name)) {
+ memcpy(binaddr, p->ether_addr_octet, 6);
+ return 0;
}
- if (i < ETH_ALEN - 1)
- return -1;
+ return -1;
+}
+
+void mac_addr_n2a(char *mac_addr, unsigned char *arg)
+{
+ int i, l;
+
+ char *name;
+
+ name = iw_ether_b2host(arg);
+ sprintf(mac_addr, "%-17s", name);
+}
+
+int mac_addr_a2n(unsigned char *mac_addr, char *arg)
+{
+ int i;
+
+ if (iw_ether_host2b(arg, mac_addr))
+ return -1;
return 0;
}
---
_______________________________________________
Devel mailing list
[email protected]
http://lists.open80211s.org/cgi-bin/mailman/listinfo/devel