Thanks Duncan, you are right, it was the wrong type and fixed. Thank you and appreciate your helps. Cheers. - jh On 12/31/19, Duncan Roe <duncan_roe@xxxxxxxxxxxxxxx> wrote: > On Mon, Dec 30, 2019 at 07:50:56PM +1100, JH wrote: >> Hi, >> >> I have following error of attribute type 1 has an invalid length when >> calling following mnl_socket_sendto(channel->mnlSocket, nlh, >> nlh->nlmsg_len), I cannot see what was wrong about it, the >> nlh->nlmsg_len = 40 which is from libnml, is that wrong? Please advise >> how to fix it. >> >> [ 3240.939609] netlink: 'wifi_signal': attribute type 1 has an invalid >> length. I have a WiFi function using nml API: >> >> typedef struct { >> struct mnl_socket *mnlSocket; >> char buf[BUFFER_SIZE]; >> uint16_t channelId; >> uint32_t interfaceIndex; >> uint32_t sequence; >> void *context; >> } __attribute__ ((packed)) Netlink80211Channel_t; >> >> void WiFiScan::Send80211Message(struct nlmsghdr *nlh, >> Netlink80211Channel_t *channel) { >> if (mnl_socket_sendto(channel->mnlSocket, nlh, nlh->nlmsg_len) < 0) { >> std::cout << "Failed to send socket" << std::endl; >> } >> } >> >> Thank you. >> >> - jh >> > The kernel is complaining about the content of the message, rather than the > length. The message you send should consist of a header followed by a series > of > attributes. Attributes are of the form <type> <length> <data>. <type> is > always > uint8_t. The kernel has seen the an attribute of type 1 (NLA_U8) but the > following lenth byte was not 1 as it should have been. Quite possibly the > message is garbage. > > The error message you see is output by function validate_nla() in file > lib/nlattr.c at line 178. > > To get a more helpful answer, you would need to post a lot more code. Is it > on > gitbub? > > Cheers ... Duncan. >