/* * Respond to a single RTM_NEWLINK event from the rtnetlink socket. */ static int LinkCatcher(struct nlmsghdr *nlh) { struct ifinfomsg* ifi; #if 0 fprintf(stderr, "nlmsg_type = %d.\n", nlh->nlmsg_type); #endif ifi = NLMSG_DATA(nlh); /* Code is ugly, but sort of works - Jean II */ /* If interface is getting destoyed */ if(nlh->nlmsg_type == RTM_DELLINK) { /* Remove from cache (if in cache) */ iw_del_interface_data(ifi->ifi_index); return 0; } /* Only keep add/change events */ if(nlh->nlmsg_type != RTM_NEWLINK) return 0; /* Check for attributes */ if (nlh->nlmsg_len > NLMSG_ALIGN(sizeof(struct ifinfomsg))) { int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(sizeof(struct ifinfomsg)); struct rtattr *attr = (void *) ((char *) ifi + NLMSG_ALIGN(sizeof(struct ifinfomsg))); while (RTA_OK(attr, attrlen)) { /* Check if the Wireless kind */ if(attr->rta_type == IFLA_WIRELESS) { /* Go to display it */ print_event_stream(ifi->ifi_index, (char *) attr + RTA_ALIGN(sizeof(struct rtattr)), attr->rta_len - RTA_ALIGN(sizeof(struct rtattr))); } attr = RTA_NEXT(attr, attrlen); } } return 0; }
/* * Respond to a single RTM_NEWLINK event from the rtnetlink socket. */ static int LinkCatcher(struct nlmsghdr *nlh) { struct ifinfomsg* ifi; char ifname[IFNAMSIZ + 1]; #if 0 fprintf(stderr, "nlmsg_type = %d.\n", nlh->nlmsg_type); #endif if(nlh->nlmsg_type != RTM_NEWLINK) return 0; ifi = NLMSG_DATA(nlh); /* Get a name... */ index2name(ifi->ifi_index, ifname); #if WIRELESS_EXT > 13 /* Code is ugly, but sort of works - Jean II */ /* Check for attributes */ if (nlh->nlmsg_len > NLMSG_ALIGN(sizeof(struct ifinfomsg))) { int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(sizeof(struct ifinfomsg)); struct rtattr *attr = (void*)ifi + NLMSG_ALIGN(sizeof(struct ifinfomsg)); while (RTA_OK(attr, attrlen)) { /* Check if the Wireless kind */ if(attr->rta_type == IFLA_WIRELESS) { /* Go to display it */ print_event_stream(ifname, (void *)attr + RTA_ALIGN(sizeof(struct rtattr)), attr->rta_len - RTA_ALIGN(sizeof(struct rtattr))); } attr = RTA_NEXT(attr, attrlen); } } #endif /* WIRELESS_EXT > 13 */ return 0; }