All of lore.kernel.org
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio@meshcoding.com>
To: The list for a Better Approach To Mobile Ad-hoc Networking
	<b.a.t.m.a.n@lists.open-mesh.org>
Subject: Re: [B.A.T.M.A.N.] [PATCH next 1/3] batctl: introduce rtnl_open() helper function
Date: Sun, 05 Jan 2014 20:45:29 +0100	[thread overview]
Message-ID: <52C9B659.8040400@meshcoding.com> (raw)
In-Reply-To: <2648905.iCJy0vMviH@diderot>

[-- Attachment #1: Type: text/plain, Size: 1516 bytes --]

On 05/01/14 15:04, Marek Lindner wrote:
> On Sunday 05 January 2014 09:59:52 Antonio Quartulli wrote:
>> @@ -528,7 +526,7 @@ static int resolve_mac_from_cache_open(int ai_family)
>>         if (ret < 0)
>>                 goto outclose;
>>  
>> -       ret = send(socknl, &nlreq, nlreq.hdr.nlmsg_len, 0);
>> +       ret = send(socknl, req, len, 0);
>>         if (ret < 0)
>>                 goto outclose;
>>  out:
>> @@ -538,6 +536,22 @@ outclose:
>>         return ret;
>>  }
>>  
>> +static int resolve_mac_from_cache_open(int ai_family)
>> +{
>> +       struct {
>> +               struct nlmsghdr hdr;
>> +               struct ndmsg msg;
>> +       } nlreq;
>> +
>> +       memset(&nlreq, 0, sizeof(nlreq));
>> +       nlreq.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(nlreq.msg));
>> +       nlreq.hdr.nlmsg_type = RTM_GETNEIGH;
>> +       nlreq.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
>> +       nlreq.msg.ndm_family = ai_family;
>> +
>> +       return rtnl_open(&nlreq, sizeof(nlreq), NETLINK_ROUTE);
>> +}
> 
> Is 'sizeof(nlreq)' equal to 'nlreq.hdr.nlmsg_len' ? It seems not ...

It is because the macro NLMSG_LENGTH adds NLMSG_HDRLEN to the value
passed as argument (in this case it is sizeof(nlreq.msg)) and therefore
what we store in nlreq.hdr.nlmsg_len is sizeof(nlreq) (plus some
possible alignment bytes).

I think I can make it more clear and always pass nlreq.hdr.nlmsg_len to
send().


Thanks!

v2 is coming!


Cheers,


-- 
Antonio Quartulli


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

      reply	other threads:[~2014-01-05 19:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-05  8:59 [B.A.T.M.A.N.] [PATCH next 1/3] batctl: introduce rtnl_open() helper function Antonio Quartulli
2014-01-05  8:59 ` [B.A.T.M.A.N.] [PATCH next 2/3] batctl: implement vlan-to-link helper functions Antonio Quartulli
2014-01-05 19:07   ` Marek Lindner
2014-01-05 19:33     ` Antonio Quartulli
2014-01-05  8:59 ` [B.A.T.M.A.N.] [PATCH next 3/3] batctl: add sys framework for VLAN support Antonio Quartulli
2014-01-05 14:04 ` [B.A.T.M.A.N.] [PATCH next 1/3] batctl: introduce rtnl_open() helper function Marek Lindner
2014-01-05 19:45   ` Antonio Quartulli [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=52C9B659.8040400@meshcoding.com \
    --to=antonio@meshcoding.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.