Ask for link and address data on the same socket.
Tilman Baumann
tilman at baumann.name
Thu Jul 18 12:15:55 EDT 2013
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;
}
memset(&ifinfo_req, 0, sizeof(ifinfo_req));
ifinfo_req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
ifinfo_req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
ifinfo_req.n.nlmsg_type = RTM_GETLINK;
status = send(netlinkfd, &ifinfo_req, ifinfo_req.n.nlmsg_len, 0);
if (status < 0) {
perror("[Listener] send");
return 1;
}
return 1;
}
More information about the libnl
mailing list