How to bundle requests?

Tilman Baumann tilman.baumann at grandeye.com
Wed Oct 26 12:46:09 EDT 2011


On 26/10/11 08:49, Thomas Graf wrote:
> On Tue, Oct 25, 2011 at 10:50:52AM +0100, Tilman Baumann wrote:
>> Hi,
>>
>> I need IP address information and link mac addresses in my programme.
>>
>> I thought I can combine requests with nlmsg_flags = NLM_F_MULTI but
>> it seems like this does not really work at all.
>> Or I'm doing it wrong.
>>
>> I'm not constantly listening on the socket. I just send a request
>> and do one recv(). I could imagine that this is bad practice. If you
>> tell me how it is better done I would appreciate this very much.
>>
>> Sorry about the line breaks. I did not take care of max line length.
>> I will attach the file as well, to make it more readable.
>>
>>
>> Below code works if I just send one RTM_GETADDR or RTM_GETLINK
>> packet. But the combined request like below does only return GETADDR
>> data.
>>
>>
>> Am I doing the NLM_F_MULTI request right? Should it work and how
>> should I use it do make it work.
>
> You do not need NLM_F_MULTI for this.
>
> The behaviour depends on the netlink family. In this specific case,
> rtnetlink will parse any message in sequential order and process
> them one by one:


> With regards to libnl, you will have to call the receiver() procedure
> twice to catch both reply sequences.

Is that the same as calling recv() twice on the socket?

Because if I do that, I get only a very tiny response at the second recv().

// RTM_GETADDR
memset(buf, 0,  sizeof(buf));
status = send(fd, ifaddr_hdr, ifaddr_nlmsg_len, 0);
sleep(1);
status = recv(fd, buf, sizeof(buf), 0);
printf("received %db\n", status);

// RTM_GETLINK
memset(buf, 0,  sizeof(buf));
status = send(fd, ifinfo_hdr, ifinfo_nlmsg_len, 0);
sleep(1);
status = recv(fd, buf, sizeof(buf), 0);
printf("received %db\n", status);


received 168b
received 20b

If I do just one of them, then I get a full response. 1204b even for 
RTM_GETLINK

-- 
Tilman Baumann
Grandeye Limited
6 Huxley Road, Surrey Research Park
Guildford, GU2 7RE, United Kingdom



More information about the libnl mailing list