I'm using libnl3
and nl80211.h
to get the available bands for a connected wireless interface.
When I try to compile I get error: invalid conversion from ‘void*’ to ‘nlattr*’
. The IDE (CLion) is also complaining about the line nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
and says incompatible pointer type 'nlattr *' and 'void *'
.
What is being seen as void *
, is it pos = nla_data(nla)
from /usr/include/libnl3/netlink/attr.h
that is considered void *
?
Compile Error:
/home/username/Documents/Development/appname/fs_nl80211Class.cpp: In function ‘int callback(nl_msg*, void*)’:
/usr/include/libnl3/netlink/attr.h:328:21: error: invalid conversion from ‘void*’ to ‘nlattr*’ [-fpermissive]
for (pos = nla_data(nla), rem = nla_len(nla);
^
The macro from the libnl3/netlink/attr.h
file:
#define nla_for_each_nested(pos, nla, rem) \
for (pos = nla_data(nla), rem = nla_len(nla); \
nla_ok(pos, rem); \
pos = nla_next(pos, &(rem)))
My Code:
static int callback(struct nl_msg *msg, void *arg) {
genlmsghdr *gnlh = (genlmsghdr *) nlmsg_data(nlmsg_hdr(msg));
struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
struct nlattr *nl_band;
int rem_band;
static int last_band = -1;
static bool band_had_freq = false;
nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
if (tb_msg[NL80211_ATTR_WIPHY_BANDS]) {
// macro from libnl3/netlink/attr.h
nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
if (last_band != nl_band->nla_type) {
cout << ("Band %d:", nl_band->nla_type) << endl;
band_had_freq = false;
}
last_band = nl_band->nla_type;
nla_parse(tb_band,
NL80211_BAND_ATTR_MAX,
nla_data(nl_band),
nla_len(nl_band), NULL);
if (tb_band[NL80211_BAND_ATTR_FREQS]) {
if (!band_had_freq) {
cout << "Frequencies:" << endl;
band_had_freq = true;
}
}
}
}
//nl_msg_dump(msg, stdout);
return NL_SKIP;
}