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