static int print_mpp_handler(struct nl_msg *msg, void *arg) { struct nlattr *tb[NL80211_ATTR_MAX + 1]; struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); char dst[20], next_hop[20], dev[20]; nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); /* * TODO: validate the interface and mac address! * Otherwise, there's a race condition as soon as * the kernel starts sending mpath notifications. */ mac_addr_n2a(dst, nla_data(tb[NL80211_ATTR_MAC])); mac_addr_n2a(next_hop, nla_data(tb[NL80211_ATTR_MPATH_NEXT_HOP])); if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); printf("%s %s %s\n", dst, next_hop, dev); return NL_SKIP; }
static int print_iface_handler(struct nl_msg *msg, void *arg) { struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; unsigned int *wiphy = arg; const char *indent = ""; nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); if (wiphy && tb_msg[NL80211_ATTR_WIPHY]) { unsigned int thiswiphy = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]); indent = "\t"; if (*wiphy != thiswiphy) printf("phy#%d\n", thiswiphy); *wiphy = thiswiphy; } if (tb_msg[NL80211_ATTR_IFNAME]) printf("%sInterface %s\n", indent, nla_get_string(tb_msg[NL80211_ATTR_IFNAME])); else printf("%sUnnamed/non-netdev interface\n", indent); if (tb_msg[NL80211_ATTR_IFINDEX]) printf("%s\tifindex %d\n", indent, nla_get_u32(tb_msg[NL80211_ATTR_IFINDEX])); if (tb_msg[NL80211_ATTR_WDEV]) printf("%s\twdev 0x%llx\n", indent, (unsigned long long)nla_get_u64(tb_msg[NL80211_ATTR_WDEV])); if (tb_msg[NL80211_ATTR_MAC]) { char mac_addr[20]; mac_addr_n2a(mac_addr, nla_data(tb_msg[NL80211_ATTR_MAC])); printf("%s\taddr %s\n", indent, mac_addr); } if (tb_msg[NL80211_ATTR_SSID]) { printf("%s\tssid ", indent); print_ssid_escaped(nla_len(tb_msg[NL80211_ATTR_SSID]), nla_data(tb_msg[NL80211_ATTR_SSID])); printf("\n"); } if (tb_msg[NL80211_ATTR_IFTYPE]) printf("%s\ttype %s\n", indent, iftype_name(nla_get_u32(tb_msg[NL80211_ATTR_IFTYPE]))); if (!wiphy && tb_msg[NL80211_ATTR_WIPHY]) printf("%s\twiphy %d\n", indent, nla_get_u32(tb_msg[NL80211_ATTR_WIPHY])); if (tb_msg[NL80211_ATTR_WIPHY_FREQ]) { uint32_t freq = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FREQ]); printf("%s\tchannel %d (%d MHz)", indent, ieee80211_frequency_to_channel(freq), freq); if (tb_msg[NL80211_ATTR_CHANNEL_WIDTH]) { printf(", width: %s", channel_width_name(nla_get_u32(tb_msg[NL80211_ATTR_CHANNEL_WIDTH]))); if (tb_msg[NL80211_ATTR_CENTER_FREQ1]) printf(", center1: %d MHz", nla_get_u32(tb_msg[NL80211_ATTR_CENTER_FREQ1])); if (tb_msg[NL80211_ATTR_CENTER_FREQ2]) printf(", center2: %d MHz", nla_get_u32(tb_msg[NL80211_ATTR_CENTER_FREQ2])); } else if (tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { enum nl80211_channel_type channel_type; channel_type = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); printf(" %s", channel_type_name(channel_type)); } printf("\n"); } return NL_SKIP; }