struct nlmsghdr *n;
struct rtgenmsg *gen;
uint8_t req[1024];
+
+ /* Issue a wild dump NETLINK request */
memset(&req, 0, sizeof(req));
n = (struct nlmsghdr*) req;
static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdata) {
AvahiInterfaceMonitor *m = userdata;
+
+ /* This routine is called for every RTNETLINK response packet */
assert(m);
assert(n);
assert(m->osdep.netlink == nl);
if (n->nlmsg_type == RTM_NEWLINK) {
+
+ /* A new interface appeared or an existing one has been modified */
+
struct ifinfomsg *ifinfomsg = NLMSG_DATA(n);
AvahiHwInterface *hw;
struct rtattr *a = NULL;
size_t l;
-
+
+ /* A (superfluous?) sanity check */
if (ifinfomsg->ifi_family != AF_UNSPEC)
return;
/* Fill in hardware (MAC) address */
hw->mac_address_size = RTA_PAYLOAD(a);
- if (hw->mac_address_size > AVAHI_MAX_MAC_ADDRESS)
- hw->mac_address_size = AVAHI_MAX_MAC_ADDRESS;
+ if (hw->mac_address_size > AVAHI_MAC_ADDRESS_MAX)
+ hw->mac_address_size = AVAHI_MAC_ADDRESS_MAX;
memcpy(hw->mac_address, RTA_DATA(a), hw->mac_address_size);
break;
avahi_hw_interface_update_rrs(hw, 0);
} else if (n->nlmsg_type == RTM_DELLINK) {
+
+ /* An interface has been removed */
+
struct ifinfomsg *ifinfomsg = NLMSG_DATA(n);
AvahiHwInterface *hw;
+ /* A (superfluous?) sanity check */
if (ifinfomsg->ifi_family != AF_UNSPEC)
return;
} else if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) {
+ /* An address has been added, modified or removed */
+
struct ifaddrmsg *ifaddrmsg = NLMSG_DATA(n);
AvahiInterface *i;
struct rtattr *a = NULL;
if (!(m->osdep.netlink = avahi_netlink_new(m->server->poll_api, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, netlink_callback, m)))
goto fail;
+ /* Set the initial state. */
+ m->osdep.list = LIST_IFACE;
+
/* Start the wild dump for the interfaces */
if (netlink_list_items(m->osdep.netlink, RTM_GETLINK, &m->osdep.query_link_seq) < 0)
goto fail;
- /* Set the initial state. */
- m->osdep.list = LIST_IFACE;
-
return 0;
fail:
/* Let's handle netlink events until we are done with wild
* dumping */
- while (m->osdep.list != LIST_DONE) {
+ while (!m->list_complete)
if (!avahi_netlink_work(m->osdep.netlink, 1) == 0)
break;
- }
/* At this point Avahi knows about all local interfaces and
* addresses in existance. */