Using netlink to obtain arp entries only returns stale entries
- by Ben
I'm currently trying to retrieve reachable neighbors from the arp table in a user space program written in c. I've looked through the source code to the "ip neigh" command (ipneigh.c) and it appears that I should use the flag NUD_REACHABLE.
struct {
struct nlmsghdr n;
struct ndmsg r;
} req;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
req.n.nlmsg_type = RTM_GETNEIGH;
req.r.ndm_state = NUD_REACHABLE;
However, when I look at the data returned from the kernel, I only have stale entries. In fact, no matter what I put for req.r.ndm_state it seems to return only entries marked as stale by ip neigh. The remainder of my code is modeled after this example: http://linux-hacks.blogspot.com/2009/01/sample-code-to-learn-netlink.html