netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: JH <jupiter.hce@gmail.com>
To: JH <jupiter.hce@gmail.com>,
	netfilter-devel <netfilter-devel@vger.kernel.org>
Subject: Re: Calling mnl_socket_sendto caused error of netlink attribute type 1 has an invalid length
Date: Thu, 2 Jan 2020 18:59:18 +1100	[thread overview]
Message-ID: <CAA=hcWRrCDHqu_vGVds==9Rzve_LUxJ0XRcB=k1fmZr9w-DoOg@mail.gmail.com> (raw)
In-Reply-To: <20191231003259.GA1179@dimstar.local.net>

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@optusnet.com.au> 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.
>

      reply	other threads:[~2020-01-02  7:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-30  8:50 Calling mnl_socket_sendto caused error of netlink attribute type 1 has an invalid length JH
2019-12-31  0:32 ` Duncan Roe
2020-01-02  7:59   ` JH [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA=hcWRrCDHqu_vGVds==9Rzve_LUxJ0XRcB=k1fmZr9w-DoOg@mail.gmail.com' \
    --to=jupiter.hce@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).