Ask for link and address data on the same socket.
Tilman Baumann
tilman at baumann.name
Fri Jul 19 05:24:34 EDT 2013
On 18/07/13 18:28, Thomas Graf wrote:
> On 07/18/13 at 05:15pm, Tilman Baumann wrote:
>> On 11/07/13 20:32, Thomas Graf wrote:
>>> On 07/10/13 at 03:48pm, Tilman Baumann wrote:
>>>> On 04/07/13 20:55, Thomas Graf wrote:
>>>>
>>>> The parse part can deal with both types of responses very well.
>>>> Do you mean I should send the requests individually via send() and with
>>>> NLMSG_DONE?
>>>> Or assemble the request chain how I did with NLMSG_NEXT() and a empty or
>>>> rtgenmsg request with NLMSG_DONE at the end?
>>> The kernel is not ready to handle that.
>>>
>>> I suggest that you use individual send() calls to send the RTM_GETADDR
>>> and RTM_GETLINK requests so you don't need to send a NLMSG_DONE
>>> message at all.
>> Thanks again for taking your time.
>>
>> I simplified the code a bit. Too much cargo cult going on. (Still the
>> case, but I think I grokk it)
>>
>> I assemble two messages, one RTM_GETLINK and one RTM_GETADDR, and send
>> them individually.
>> But my receive function again only receives the first one.
>>
>> I think I'm still missing a clue here.
>> If you like I can send you my receive function.
>>
>> My request function now:
>> {
>> int status;
>> struct {
>> struct nlmsghdr n;
>> struct ifaddrmsg r;
>> } ifaddr_req;
>>
>> struct {
>> struct nlmsghdr n;
>> struct ifinfomsg r;
>> } ifinfo_req;
>>
>> memset(&ifaddr_req, 0, sizeof(ifaddr_req));
>> ifaddr_req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
>> ifaddr_req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
>> ifaddr_req.n.nlmsg_type = RTM_GETADDR;
>>
>> status = send(netlinkfd, &ifaddr_req, ifaddr_req.n.nlmsg_len, 0);
>> if (status < 0) {
>> perror("[Listener] send");
>> return 1;
>> }
> You should receive the answer to the first request here.
Well, perhaps I have some wrong expectations again.
I only collect the responses after I had send both requests. I suppose I
can have two responses 'in flight' for a while?
After my send function finished, some time later my programme will get
to a epoll_wait() and loop over that.
>
>> memset(&ifinfo_req, 0, sizeof(ifinfo_req));
>> ifinfo_req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
> ^^^^^^^^^^^^^^
Oh, thanks. My bad. But did not really change anything.
More information about the libnl
mailing list