Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 1
    Great code. Is there a way to only watch a specific interface for a change? Commented Feb 2, 2011 at 16:36
  • 6
    @watain the struct ifaddrmsg has a member ifa_index, which is the interface index of the interface the address is associated with. Commented Feb 11, 2011 at 7:47
  • 2
    It should be noted in the manpage for these netlink API, it is recommended not to use this low level interface, but rather the libnetlink lib ... Which in turn lists the use of this lib as a bug and points to the use of libmnl instead Commented Aug 24, 2015 at 9:16
  • 1
    I found a cleaner version of this code that handles both RTM_NEWADDR and RTM_DELADDR as well as handling both IPv4 and IPv6 cases here Commented Aug 13, 2018 at 21:10
  • 6
    @Vencat, the outer while() is not considering polling because the recv() blocks until there is an event to be processed. The inner 2 while()s are just iterating. Commented May 4, 2021 at 13:19