X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fiface-windows.c;h=7be73f07d97631dcbce958fce70a00a0fba60a32;hb=HEAD;hp=c62e96a31f7c980ff56bb9d1944701e8a2c7e721;hpb=fa43d5a814f153ffcfd6296e77f6f0df5c597cf9;p=catta diff --git a/src/iface-windows.c b/src/iface-windows.c index c62e96a..7be73f0 100644 --- a/src/iface-windows.c +++ b/src/iface-windows.c @@ -23,8 +23,10 @@ #include // wcstombs #include #include +#include #include #include +#include "compat/windows/wincompat.h" #include "hashmap.h" #include "util.h" // catta_format_mac_address #include "fdutil.h" // catta_set_nonblock @@ -103,17 +105,6 @@ static void ip_adapter_unicast_address(CattaInterfaceMonitor *m, } set_global_scope_flag(ifaddr, &addr); - - // XXX debugging, remove - { - char s[CATTA_ADDRESS_STR_MAX]; - catta_log_debug(" address: %s\n" - " global_scope: %d\n" - " flags: 0x%.4x", - catta_address_snprint(s, sizeof(s), &addr), - ifaddr->global_scope, - (unsigned int)a->Flags); - } } // integrate the information from an IP_ADAPTER_ADDRESSES structure @@ -173,36 +164,10 @@ static void ip_adapter(CattaInterfaceMonitor *m, IP_ADAPTER_ADDRESSES *p) hw->mac_address_size = CATTA_MAC_ADDRESS_MAX; memcpy(hw->mac_address, p->PhysicalAddress, hw->mac_address_size); - // XXX debugging, remove - { - char mac[256]; - catta_log_debug(" name: %s\n" - " index: %d\n" - " IfIndex: %u\n" - " Ipv6IfIndex: %u\n" - " mtu: %d\n" - " mac: %s\n" - " flags_ok: %d\n" - " type: %u\n" - " status: %u\n" - " multicast: %d\n" - " flags: 0x%.4x", - hw->name, hw->index, - (unsigned int)p->IfIndex, (unsigned int)p->Ipv6IfIndex, - hw->mtu, - catta_format_mac_address(mac, sizeof(mac), hw->mac_address, hw->mac_address_size), - hw->flags_ok, - (unsigned int)p->IfType, - (unsigned int)p->OperStatus, - !(p->Flags & IP_ADAPTER_NO_MULTICAST), - (unsigned int)p->Flags); - } - // process addresses // XXX remove addresses that are no longer in the list for(a=p->FirstUnicastAddress; a; a=a->Next) ip_adapter_unicast_address(m, hw, a); - catta_log_debug("====="); } @@ -217,8 +182,7 @@ static void queue_event(CattaInterfaceMonitor *m, ChangeEvent *ev) if(!pthread_mutex_lock(&m->osdep.mutex)) { // queue the event - // XXX event ordering!! - CATTA_LLIST_PREPEND(ChangeEvent, event, m->osdep.events, ev); + CATTA_LLIST_APPEND(ChangeEvent, event, m->osdep.events, ev); // wake the handler writepipe(m->osdep.pipefd[1], &c, sizeof(c)); @@ -298,27 +262,6 @@ static void update_hw_interface(CattaHwInterface *hw) hw->mac_address_size = CATTA_MAC_ADDRESS_MAX; memcpy(hw->mac_address, row.PhysicalAddress, hw->mac_address_size); - // XXX debugging, remove - { - char mac[256]; - catta_log_debug(" name: %s\n" - " mtu: %d\n" - " mac: %s\n" - " flags_ok: %d\n" - " type: %u\n" - " status: %u\n" - " multicast: %d\n" - " access type: %d", - hw->name, - hw->mtu, - catta_format_mac_address(mac, sizeof(mac), hw->mac_address, hw->mac_address_size), - hw->flags_ok, - (unsigned int)row.Type, - (unsigned int)row.OperStatus, - multicast, - (int)row.AccessType); - } - catta_hw_interface_check_relevant(hw); catta_hw_interface_update_rrs(hw, 0); } @@ -331,20 +274,6 @@ static void handle_iface_event(CattaInterfaceMonitor *m, MIB_IPINTERFACE_ROW *ro CattaInterface *iface; CattaHwInterface *hw; - // XXX debug, remove - { - const char *typestr = NULL; - - switch(type) { - case MibParameterNotification: typestr = "ParameterNotification"; break; - case MibAddInstance: typestr = "AddInstance"; break; - case MibDeleteInstance: typestr = "DeleteInstance"; break; - default: typestr = "Unknown"; - } - - catta_log_debug("interface %s on iface %d for %s", typestr, idx, protostr); - } - // see if we know this interface iface = catta_interface_monitor_get_interface(m, idx, proto); hw = iface ? iface->hardware : catta_interface_monitor_get_hw_interface(m, idx); @@ -420,24 +349,6 @@ static void handle_addr_event(CattaInterfaceMonitor *m, MIB_UNICASTIPADDRESS_ROW addr.proto = catta_af_to_proto(row->Address.si_family); protostr = catta_proto_to_string(addr.proto); - // XXX debug, remove - { - const char *typestr = NULL; - char buf[CATTA_ADDRESS_STR_MAX]; - - switch(type) { - case MibParameterNotification: typestr = "ParameterNotification"; break; - case MibAddInstance: typestr = "AddInstance"; break; - case MibDeleteInstance: typestr = "DeleteInstance"; break; - default: typestr = "Unknown"; - } - - catta_log_debug("%s for %s address %s on iface %d", - typestr, protostr, - catta_address_snprint(buf, sizeof(buf), &addr), - idx); - } - // see if we know this address/interface iface = catta_interface_monitor_get_interface(m, idx, addr.proto); ifaddr = iface ? catta_interface_monitor_get_address(m, iface, &addr) : NULL; @@ -493,7 +404,6 @@ static void handle_addr_event(CattaInterfaceMonitor *m, MIB_UNICASTIPADDRESS_ROW assert(ifaddr != NULL); set_global_scope_flag(ifaddr, &addr); - catta_log_debug(" global_scope: %d", ifaddr->global_scope); // XXX debugging, remove break; case MibDeleteInstance: if(ifaddr) @@ -563,8 +473,12 @@ int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m) catta_log_error("pipe() in catta_interface_monitor_init_osdep failed"); return -1; } - catta_set_nonblock(m->osdep.pipefd[0]); - catta_set_nonblock(m->osdep.pipefd[1]); + if(catta_set_nonblock(m->osdep.pipefd[0]) < 0 || + catta_set_nonblock(m->osdep.pipefd[1]) < 0) + { + catta_log_error(__FILE__": catta_set_nonblock failed: %s", errnostrsocket()); + goto fail; + } m->osdep.icnhandle = NULL; m->osdep.acnhandle = NULL; @@ -577,7 +491,7 @@ int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m) m); if(!m->osdep.watch) { catta_log_error(__FILE__": Failed to create watch."); - return -1; + goto fail; } // request async notification on interface changes @@ -597,6 +511,11 @@ int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m) catta_log_error("NotifyUnicastIpAddressChange failed: %u", (unsigned int)r); return 0; + +fail: + closesocket(m->osdep.pipefd[0]); + closesocket(m->osdep.pipefd[1]); + return -1; } void catta_interface_monitor_free_osdep(CattaInterfaceMonitor *m)