+void update_hw_interface(CattaHwInterface *hw)
+{
+ MIB_IF_ROW2 row;
+ DWORD r;
+ size_t n;
+ int multicast; // synthetic flag
+
+ row.InterfaceLuid.Value = 0;
+ row.InterfaceIndex = hw->index;
+ if((r = GetIfEntry2(&row)) != NO_ERROR) {
+ catta_log_error("GetIfEntry2 failed for iface %d (error %u)", hw->index, (unsigned int)r);
+ return;
+ }
+
+ // fill the CattaHwInterface struct with data
+ // notice: this code is essentially duplicated from ip_adapter()
+ // notice: not sure where to find the IP_ADAPTER_NO_MULTICAST flag from an
+ // MIB_IF_ROW2 struct, so try to deduce it otherwise
+ // cf. http://msdn.microsoft.com/en-us/windows/desktop/ff568739(v=vs.100).aspx
+ multicast = row.AccessType == NET_IF_ACCESS_BROADCAST ||
+ row.AccessType == NET_IF_ACCESS_POINT_TO_POINT;
+ hw->flags_ok =
+ (row.OperStatus == IfOperStatusUp) &&
+ !(row.Type == IF_TYPE_SOFTWARE_LOOPBACK) &&
+ multicast &&
+ (hw->monitor->server->config.allow_point_to_point || !(row.Type == IF_TYPE_PPP));
+ // XXX what about IF_TYPE_TUNNEL?
+
+ n = wcstombs(NULL, row.Alias, 0) + 1;
+ catta_free(hw->name);
+ hw->name = catta_new(char, n);
+ wcstombs(hw->name, row.Alias, n);
+
+ hw->mtu = row.Mtu;
+
+ hw->mac_address_size = row.PhysicalAddressLength;
+ if(hw->mac_address_size > CATTA_MAC_ADDRESS_MAX)
+ 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);
+ }
+}
+