From ab758d7bf41d1d7565e80fe5d2bded0d18160ccb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 17 Oct 2005 18:18:05 +0000 Subject: [PATCH] slightly more comments git-svn-id: file:///home/lennart/svn/public/avahi/trunk@793 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/iface-linux.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/avahi-core/iface-linux.c b/avahi-core/iface-linux.c index 64bb0ae..bc87152 100644 --- a/avahi-core/iface-linux.c +++ b/avahi-core/iface-linux.c @@ -38,6 +38,8 @@ static int netlink_list_items(AvahiNetlink *nl, uint16_t type, unsigned *ret_seq 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; @@ -55,17 +57,23 @@ static int netlink_list_items(AvahiNetlink *nl, uint16_t type, unsigned *ret_seq 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; @@ -140,9 +148,13 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat 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; @@ -155,6 +167,8 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat } 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; @@ -304,13 +318,13 @@ int avahi_interface_monitor_init_osdep(AvahiInterfaceMonitor *m) { 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: -- 2.39.5