]> git.meshlink.io Git - catta/blobdiff - src/iface-windows.c
fix flags_ok computation (IfType and OperStatus are ordinals, not flags)
[catta] / src / iface-windows.c
index e3ca771b212c02dc8af671b72c48fa14d2774558..9fe4ffeb66f1d66f01f48081eee1ba7765536daf 100644 (file)
@@ -20,6 +20,7 @@
 #include "iface-windows.h"
 #include "iface.h"
 
+#include <stdlib.h> // wcstombs
 #include <catta/malloc.h>
 #include <catta/log.h>
 #include <iphlpapi.h>
@@ -76,6 +77,7 @@ static void ip_adapter_address(CattaInterfaceMonitor *m, IP_ADAPTER_ADDRESSES *p
 {
     CattaIfIndex idx;
     CattaHwInterface *hw;
+    size_t n;
 
     // look up the interface index by LUID
     if((idx = find_ifindex(m, p->Luid)) < 0) {
@@ -93,20 +95,22 @@ static void ip_adapter_address(CattaInterfaceMonitor *m, IP_ADAPTER_ADDRESSES *p
 
     // fill the CattaHwInterface struct with data
     hw->flags_ok =
-        (p->OperStatus & IfOperStatusUp) &&
-        !(p->IfType & IF_TYPE_SOFTWARE_LOOPBACK) &&
+        (p->OperStatus == IfOperStatusUp) &&
+        !(p->IfType == IF_TYPE_SOFTWARE_LOOPBACK) &&
         !(p->Flags & IP_ADAPTER_NO_MULTICAST) &&
-        (m->server->config.allow_point_to_point || !(p->IfType & IF_TYPE_PPP));
+        (m->server->config.allow_point_to_point || !(p->IfType == IF_TYPE_PPP));
             // XXX what about IF_TYPE_TUNNEL?
 
+    n = wcstombs(NULL, p->FriendlyName, 0) + 1;
     catta_free(hw->name);
-    hw->name = catta_strdup(p->AdapterName);
+    hw->name = catta_new(char, n);
+    wcstombs(hw->name, p->FriendlyName, n);
 
     hw->mtu = p->Mtu;
 
     hw->mac_address_size = p->PhysicalAddressLength;
-    if (hw->mac_address_size > CATTA_MAC_ADDRESS_MAX)
-      hw->mac_address_size = CATTA_MAC_ADDRESS_MAX;
+    if(hw->mac_address_size > CATTA_MAC_ADDRESS_MAX)
+        hw->mac_address_size = CATTA_MAC_ADDRESS_MAX;
     memcpy(hw->mac_address, p->PhysicalAddress, hw->mac_address_size);
 
     // XXX process addresses
@@ -114,11 +118,15 @@ static void ip_adapter_address(CattaInterfaceMonitor *m, IP_ADAPTER_ADDRESSES *p
     // XXX debugging, remove
    { 
      char mac[256]; 
-     catta_log_debug("======\n name: %s\n index:%d\n mtu:%d\n mac:%s\n flags_ok:%d\n======",  
+     catta_log_debug("======\n name: %s\n index:%d\n mtu:%d\n mac:%s\n type:%u\n status:%u\n multicast:%d\n flags:0x%.4x\n flags_ok:%d\n======",  
                    hw->name, hw->index,  
                    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,
+            hw->flags_ok); 
    } 
 }