Using netlink to obtain arp entries only returns stale entries

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2010-05-19T15:39:28Z Indexed on 2010/05/19 15:40 UTC
Read the original article Hit count: 269

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about c

    Related posts about arp