]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Win32: Make interface index DWORD consistently
authorFrank Lichtenheld <frank@lichtenheld.com>
Wed, 11 Mar 2026 16:38:45 +0000 (17:38 +0100)
committerGert Doering <gert@greenie.muc.de>
Wed, 11 Mar 2026 16:42:33 +0000 (17:42 +0100)
Previously we had a weird mix of int and DWORD. But the
Win32 APIs seem to be consistent (they have different names,
but NET_IFINDEX is ULONG is DWORD). So use that.

Note that this fixes some smaller issues in surrounding
code that are not strictly related but were found while
scanning the code. Mostly about needlessly converting
all DWORD values to int for printf().

Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1519
Message-Id: <20260311163852.21387-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36021.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
include/openvpn-msg.h
src/openvpn/dns.c
src/openvpn/route.c
src/openvpn/tun.c
src/openvpn/tun.h
src/openvpn/win32.c
src/openvpnserv/interactive.c

index a0cec53a8894bacd72dbc80bbe399802dfb56d06..34f50c861a6432ecf0c790f17b590f8844c655da 100644 (file)
@@ -66,7 +66,8 @@ typedef union
 
 typedef struct
 {
-    int index;
+#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
+    DWORD index;
     char name[256];
 } interface_t;
 
index 4a4bb0c833f385147eefd4efa83f4b4c48e8fcd5..a42d0321112eedc05dd705463421fd8842f8ab5c 100644 (file)
@@ -468,9 +468,10 @@ run_up_down_service(bool add, const struct options *o, const struct tuntap *tt)
     make_domain_list("dns search domains", search_domains, false, nrpt.search_domains,
                      sizeof(nrpt.search_domains));
 
-    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), nrpt.resolve_domains[0] != 0 ? ", resolve domains" : "",
-        nrpt.search_domains[0] != 0 ? ", search domains" : "", nrpt.iface.name, nrpt.iface.index);
+        nrpt.search_domains[0] != 0 ? ", search domains" : "",
+        nrpt.iface.name, nrpt.iface.index);
 
     send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS");
 }
index b1967133758aee768e39a1e2f30618b4885e7892..1cfbf8030ec688dab5f5584f2ad736b5b80b12c7 100644 (file)
@@ -2389,8 +2389,8 @@ get_windows_routing_table(struct gc_arena *gc)
         status = GetIpForwardTable(rt, &size, TRUE);
         if (status != NO_ERROR)
         {
-            msg(D_ROUTE, "NOTE: GetIpForwardTable returned error: %s (code=%u)",
-                strerror_win32(status, gc), (unsigned int)status);
+            msg(D_ROUTE, "NOTE: GetIpForwardTable returned error: %s (code=%lu)",
+                strerror_win32(status, gc), status);
             rt = NULL;
         }
     }
@@ -2470,8 +2470,8 @@ test_routes(const struct route_list *rl, const struct tuntap *tt)
         }
     }
 
-    msg(D_ROUTE, "TEST ROUTES: %d/%d succeeded len=%d ret=%d a=%d u/d=%s", good, count, len,
-        (int)ret, ambig, adapter_up ? "up" : "down");
+    msg(D_ROUTE, "TEST ROUTES: %d/%d succeeded len=%d ret=%u a=%d u/d=%s",
+        good, count, len, ret, ambig, adapter_up ? "up" : "down");
 
     gc_free(&gc);
     return ret;
@@ -2495,9 +2495,9 @@ get_default_gateway_row(const MIB_IPFORWARDTABLE *routes)
             const DWORD index = row->dwForwardIfIndex;
             const DWORD metric = row->dwForwardMetric1;
 
-            dmsg(D_ROUTE_DEBUG, "GDGR: route[%lu] %s/%s i=%d m=%d", i,
+            dmsg(D_ROUTE_DEBUG, "GDGR: route[%lu] %s/%s i=%lu m=%lu", i,
                  print_in_addr_t((in_addr_t)net, 0, &gc), print_in_addr_t((in_addr_t)mask, 0, &gc),
-                 (int)index, (int)metric);
+                 index, metric);
 
             if (!net && !mask && metric < lowest_metric)
             {
@@ -2508,7 +2508,7 @@ get_default_gateway_row(const MIB_IPFORWARDTABLE *routes)
         }
     }
 
-    dmsg(D_ROUTE_DEBUG, "GDGR: best=%d lm=%u", best, (unsigned int)lowest_metric);
+    dmsg(D_ROUTE_DEBUG, "GDGR: best=%d lm=%lu", best, lowest_metric);
 
     gc_free(&gc);
     return ret;
@@ -2537,12 +2537,12 @@ get_best_route(struct gc_arena *gc, SOCKADDR_INET *dest, MIB_IPFORWARD_ROW2 *bes
     status = GetBestInterfaceEx((struct sockaddr *)dest, &best_if_index);
     if (status != NO_ERROR)
     {
-        msg(D_ROUTE, "NOTE: GetBestInterfaceEx returned error: %s (code=%u)",
-            strerror_win32(status, gc), (unsigned int)status);
+        msg(D_ROUTE, "NOTE: GetBestInterfaceEx returned error: %s (code=%lu)",
+            strerror_win32(status, gc), status);
         goto done;
     }
 
-    msg(D_ROUTE_DEBUG, "GetBestInterfaceEx() returned if=%d", (int)best_if_index);
+    msg(D_ROUTE_DEBUG, "GetBestInterfaceEx() returned if=%lu", best_if_index);
 
     /* get the routing information (such as NextHop) for the destination and interface */
     NET_LUID luid;
@@ -2552,8 +2552,8 @@ get_best_route(struct gc_arena *gc, SOCKADDR_INET *dest, MIB_IPFORWARD_ROW2 *bes
     status = GetBestRoute2(&luid, best_if_index, NULL, dest, 0, best_route, &best_src);
     if (status != NO_ERROR)
     {
-        msg(D_ROUTE, "NOTE: GetIpForwardEntry2 returned error: %s (code=%u)",
-            strerror_win32(status, gc), (unsigned int)status);
+        msg(D_ROUTE, "NOTE: GetIpForwardEntry2 returned error: %s (code=%lu)",
+            strerror_win32(status, gc), status);
         goto done;
     }
 
@@ -2647,15 +2647,14 @@ windows_route_find_if_index(const struct route_ipv4 *r, const struct tuntap *tt)
             print_in_addr_t(r->gateway, 0, &gc), count);
     }
 
-    dmsg(D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=%d count=%d index=%d", on_tun, count,
-         (int)ret);
+    dmsg(D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=%d count=%d index=%lu",
+         on_tun, count, ret);
 
     gc_free(&gc);
     return ret;
 }
 
 /* IPv6 implementation using GetBestRoute2()
- *   (TBD: dynamic linking so the binary can still run on XP?)
  * https://msdn.microsoft.com/en-us/library/windows/desktop/aa365922(v=vs.85).aspx
  * https://msdn.microsoft.com/en-us/library/windows/desktop/aa814411(v=vs.85).aspx
  */
@@ -2687,8 +2686,8 @@ get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struct in6_
         print_in6_addr(BestRoute.DestinationPrefix.Prefix.Ipv6.sin6_addr, 0, &gc),
         BestRoute.DestinationPrefix.PrefixLength,
         print_in6_addr(BestRoute.NextHop.Ipv6.sin6_addr, 0, &gc));
-    msg(D_ROUTE, "GDG6: Metric=%d, Loopback=%d, AA=%d, I=%d", (int)BestRoute.Metric,
-        (int)BestRoute.Loopback, (int)BestRoute.AutoconfigureAddress, (int)BestRoute.Immortal);
+    msg(D_ROUTE, "GDG6: Metric=%lu, Loopback=%u, AA=%u, I=%u", BestRoute.Metric,
+        BestRoute.Loopback, BestRoute.AutoconfigureAddress, BestRoute.Immortal);
 
     rgi6->gateway.addr_ipv6 = BestRoute.NextHop.Ipv6.sin6_addr;
     rgi6->adapter_index = BestRoute.InterfaceIndex;
@@ -2753,8 +2752,8 @@ add_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt, DWORD adapt
         else
         {
             /* failed, try increasing the metric to work around Vista issue */
-            const unsigned int forward_metric_limit =
-                2048; /* iteratively retry higher metrics up to this limit */
+            /* iteratively retry higher metrics up to this limit */
+            const DWORD forward_metric_limit = 2048;
 
             for (; fr.dwForwardMetric1 <= forward_metric_limit; ++fr.dwForwardMetric1)
             {
@@ -2767,8 +2766,8 @@ add_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt, DWORD adapt
                     if (status == NO_ERROR)
                     {
                         msg(D_ROUTE,
-                            "ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=%u and dwForwardType=%u",
-                            (unsigned int)fr.dwForwardMetric1, (unsigned int)fr.dwForwardType);
+                            "ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=%lu and dwForwardType=%lu",
+                            fr.dwForwardMetric1, fr.dwForwardType);
                         ret = RTA_SUCCESS;
                         goto doublebreak;
                     }
@@ -2790,8 +2789,8 @@ doublebreak:
                 {
                     msg(M_WARN,
                         "ERROR: route addition failed using CreateIpForwardEntry: "
-                        "%s [status=%u if_index=%u]",
-                        strerror_win32(status, &gc), (unsigned int)status, (unsigned int)if_index);
+                        "%s [status=%lu if_index=%lu]",
+                        strerror_win32(status, &gc), status, if_index);
                 }
             }
         }
@@ -2855,7 +2854,7 @@ do_route_service(const bool add, const route_message_t *rt, const DWORD size, HA
         ret = (ack.error_number == ERROR_OBJECT_ALREADY_EXISTS) ? RTA_EEXIST : RTA_ERROR;
         if (ret == RTA_ERROR)
         {
-            msg(M_WARN, "ERROR: route %s failed using service: %s [status=%u if_index=%d]",
+            msg(M_WARN, "ERROR: route %s failed using service: %s [status=%u if_index=%lu]",
                 (add ? "addition" : "deletion"), strerror_win32(ack.error_number, &gc),
                 ack.error_number, rt->iface.index);
         }
@@ -2869,17 +2868,12 @@ out:
     return ret;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 /* Returns RTA_SUCCESS on success, RTA_EEXIST if route exists, RTA_ERROR on error */
 static int
 do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const struct tuntap *tt)
 {
     DWORD if_index = windows_route_find_if_index(r, tt);
-    if (if_index == ~0)
+    if (if_index == TUN_ADAPTER_INDEX_INVALID)
     {
         return RTA_ERROR;
     }
@@ -3023,10 +3017,6 @@ do_route_ipv6_service(const bool add, const struct route_ipv6 *r, const struct t
     return status;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /* Returns RTA_SUCCESS on success, RTA_EEXIST if route exists, RTA_ERROR on error */
 static int
 add_route_service(const struct route_ipv4 *r, const struct tuntap *tt)
@@ -3057,14 +3047,14 @@ static const char *
 format_route_entry(const MIB_IPFORWARDROW *r, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(256, gc);
-    buf_printf(&out, "%s %s %s p=%d i=%d t=%d pr=%d a=%d h=%d m=%d/%d/%d/%d/%d",
+    buf_printf(&out, "%s %s %s p=%lu i=%lu t=%lu pr=%lu a=%lu h=%lu m=%lu/%lu/%lu/%lu/%lu",
                print_in_addr_t(r->dwForwardDest, IA_NET_ORDER, gc),
                print_in_addr_t(r->dwForwardMask, IA_NET_ORDER, gc),
-               print_in_addr_t(r->dwForwardNextHop, IA_NET_ORDER, gc), (int)r->dwForwardPolicy,
-               (int)r->dwForwardIfIndex, (int)r->dwForwardType, (int)r->dwForwardProto,
-               (int)r->dwForwardAge, (int)r->dwForwardNextHopAS, (int)r->dwForwardMetric1,
-               (int)r->dwForwardMetric2, (int)r->dwForwardMetric3, (int)r->dwForwardMetric4,
-               (int)r->dwForwardMetric5);
+               print_in_addr_t(r->dwForwardNextHop, IA_NET_ORDER, gc), r->dwForwardPolicy,
+               r->dwForwardIfIndex, r->dwForwardType, r->dwForwardProto,
+               r->dwForwardAge, r->dwForwardNextHopAS, r->dwForwardMetric1,
+               r->dwForwardMetric2, r->dwForwardMetric3, r->dwForwardMetric4,
+               r->dwForwardMetric5);
     return BSTR(&out);
 }
 
index 7a173c57f740da19d5d2428a464cafe2b7830c8b..b37a2ea67c16c5b550c1fed5e83585b3a893cdc7 100644 (file)
@@ -158,7 +158,7 @@ do_address_service(const bool add, const short family, const struct tuntap *tt)
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_WARN, "TUN: %s address failed using service: %s [status=%u if_index=%d]",
+        msg(M_WARN, "TUN: %s address failed using service: %s [status=%u if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             addr.iface.index);
         goto out;
@@ -220,7 +220,7 @@ do_dns_domain_service(bool add, const struct tuntap *tt)
         strncpy(dns.domains + dstlen, o->domain_search_list[i], srclen + 1);
     }
 
-    msg(D_LOW, "%s DNS domains on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s DNS domains on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), dns.iface.name, dns.iface.index);
     if (!send_msg_iservice(o->msg_channel, &dns, sizeof(dns), &ack, "TUN"))
     {
@@ -289,7 +289,7 @@ do_dns_service(bool add, const short family, const struct tuntap *tt)
         }
     }
 
-    msg(D_LOW, "%s %s dns servers on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s %s dns servers on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), ip_proto_name, dns.iface.name, dns.iface.index);
 
     if (!send_msg_iservice(pipe, &dns, sizeof(dns), &ack, "TUN"))
@@ -346,7 +346,7 @@ do_wins_service(bool add, const struct tuntap *tt)
         wins.addr[i].ipv4.s_addr = htonl(tt->options.wins[i]);
     }
 
-    msg(D_LOW, "%s WINS servers on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s WINS servers on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), wins.iface.name, wins.iface.index);
 
     if (!send_msg_iservice(pipe, &wins, sizeof(wins), &ack, "TUN"))
@@ -357,8 +357,8 @@ do_wins_service(bool add, const struct tuntap *tt)
     if (ack.error_number != NO_ERROR)
     {
         msg(M_WARN, "TUN: %s WINS failed using service: %s [status=%u if_name=%s]",
-            (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
-            wins.iface.name);
+            (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc),
+            ack.error_number, wins.iface.name);
         goto out;
     }
 
@@ -398,13 +398,13 @@ do_set_mtu_service(const struct tuntap *tt, const short family, const int mtu)
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%d]",
+        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%lu]",
             family_name, strerror_win32(ack.error_number, &gc), ack.error_number,
             mtu_msg.iface.index);
     }
     else
     {
-        msg(M_INFO, "%s MTU set to %d on interface %d using service", family_name, mtu,
+        msg(M_INFO, "%s MTU set to %d on interface %lu using service", family_name, mtu,
             mtu_msg.iface.index);
         ret = true;
     }
@@ -3422,7 +3422,7 @@ get_device_instance_id_interface(struct gc_arena *gc)
     if (dev_info_set == INVALID_HANDLE_VALUE)
     {
         err = GetLastError();
-        msg(M_FATAL, "Error [%u] opening device information set key: %s", (unsigned int)err,
+        msg(M_FATAL, "Error [%lu] opening device information set key: %s", err,
             strerror_win32(err, gc));
     }
 
@@ -4105,7 +4105,7 @@ get_adapter_info_list(struct gc_arena *gc)
 
     if ((status = GetAdaptersInfo(NULL, &size)) != ERROR_BUFFER_OVERFLOW)
     {
-        msg(M_INFO, "GetAdaptersInfo #1 failed (status=%u) : %s", (unsigned int)status,
+        msg(M_INFO, "GetAdaptersInfo #1 failed (status=%lu) : %s", status,
             strerror_win32(status, gc));
     }
     else
@@ -4113,7 +4113,7 @@ get_adapter_info_list(struct gc_arena *gc)
         pi = (PIP_ADAPTER_INFO)gc_malloc(size, false, gc);
         if ((status = GetAdaptersInfo(pi, &size)) != NO_ERROR)
         {
-            msg(M_INFO, "GetAdaptersInfo #2 failed (status=%u) : %s", (unsigned int)status,
+            msg(M_INFO, "GetAdaptersInfo #2 failed (status=%lu) : %s", status,
                 strerror_win32(status, gc));
             pi = NULL;
         }
@@ -4132,19 +4132,19 @@ get_per_adapter_info(const DWORD index, struct gc_arena *gc)
     {
         if ((status = GetPerAdapterInfo(index, NULL, &size)) != ERROR_BUFFER_OVERFLOW)
         {
-            msg(M_INFO, "GetPerAdapterInfo #1 failed (status=%u) : %s", (unsigned int)status,
+            msg(M_INFO, "GetPerAdapterInfo #1 failed (status=%lu) : %s", status,
                 strerror_win32(status, gc));
         }
         else
         {
             pi = (PIP_PER_ADAPTER_INFO)gc_malloc(size, false, gc);
-            if ((status = GetPerAdapterInfo((ULONG)index, pi, &size)) == ERROR_SUCCESS)
+            if ((status = GetPerAdapterInfo(index, pi, &size)) == ERROR_SUCCESS)
             {
                 return pi;
             }
             else
             {
-                msg(M_INFO, "GetPerAdapterInfo #2 failed (status=%u) : %s", (unsigned int)status,
+                msg(M_INFO, "GetPerAdapterInfo #2 failed (status=%lu) : %s", status,
                     strerror_win32(status, gc));
             }
         }
@@ -4161,7 +4161,7 @@ get_interface_info_list(struct gc_arena *gc)
 
     if ((status = GetInterfaceInfo(NULL, &size)) != ERROR_INSUFFICIENT_BUFFER)
     {
-        msg(M_INFO, "GetInterfaceInfo #1 failed (status=%u) : %s", (unsigned int)status,
+        msg(M_INFO, "GetInterfaceInfo #1 failed (status=%lu) : %s", status,
             strerror_win32(status, gc));
     }
     else
@@ -4173,7 +4173,7 @@ get_interface_info_list(struct gc_arena *gc)
         }
         else
         {
-            msg(M_INFO, "GetInterfaceInfo #2 failed (status=%u) : %s", (unsigned int)status,
+            msg(M_INFO, "GetInterfaceInfo #2 failed (status=%lu) : %s", status,
                 strerror_win32(status, gc));
         }
     }
@@ -4450,8 +4450,8 @@ adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count,
         list = list->Next;
     }
 
-    dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=%s nm=%s index=%d count=%d metric=%d",
-         print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, &gc), (int)ret,
+    dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=%s nm=%s index=%lu count=%d metric=%d",
+         print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, &gc), ret,
          count ? *count : -1, lowest_metric);
 
     if (ret == TUN_ADAPTER_INDEX_INVALID && count)
@@ -4520,7 +4520,7 @@ delete_temp_addresses(DWORD index)
             DWORD status;
             const DWORD context = ip->Context;
 
-            if ((status = DeleteIPAddress((ULONG)context)) == NO_ERROR)
+            if ((status = DeleteIPAddress(context)) == NO_ERROR)
             {
                 msg(M_INFO, "Successfully deleted previously set dynamic IP/netmask: %s/%s",
                     ip->IpAddress.String, ip->IpMask.String);
@@ -4531,8 +4531,8 @@ delete_temp_addresses(DWORD index)
                 if (strcmp(ip->IpAddress.String, empty) || strcmp(ip->IpMask.String, empty))
                 {
                     msg(M_INFO,
-                        "NOTE: could not delete previously set dynamic IP/netmask: %s/%s (status=%u)",
-                        ip->IpAddress.String, ip->IpMask.String, (unsigned int)status);
+                        "NOTE: could not delete previously set dynamic IP/netmask: %s/%s (status=%lu)",
+                        ip->IpAddress.String, ip->IpMask.String, status);
                 }
             }
             ip = ip->Next;
@@ -4628,7 +4628,7 @@ static void
 show_adapter(msglvl_t msglevel, const IP_ADAPTER_INFO *a, struct gc_arena *gc)
 {
     msg(msglevel, "%s", a->Description);
-    msg(msglevel, "  Index = %d", (int)a->Index);
+    msg(msglevel, "  Index = %lu", a->Index);
     msg(msglevel, "  GUID = %s", a->AdapterName);
     msg(msglevel, "  IP = %s", format_ip_addr_string(&a->IpAddressList, gc));
     msg(msglevel, "  MAC = %s", format_hex_ex(a->Address, a->AddressLength, 0, 1, ":", gc));
@@ -4804,8 +4804,8 @@ dhcp_release_by_adapter_index(const DWORD adapter_index)
         else
         {
             msg(M_WARN,
-                "NOTE: Release of DHCP-assigned IP address lease on TAP-Windows adapter failed: %s (code=%u)",
-                strerror_win32(status, &gc), (unsigned int)status);
+                "NOTE: Release of DHCP-assigned IP address lease on TAP-Windows adapter failed: %s (code=%lu)",
+                strerror_win32(status, &gc), status);
         }
     }
 
@@ -4845,8 +4845,8 @@ dhcp_renew_by_adapter_index(const DWORD adapter_index)
         else
         {
             msg(M_WARN,
-                "WARNING: Failed to renew DHCP IP address lease on TAP-Windows adapter: %s (code=%u)",
-                strerror_win32(status, &gc), (unsigned int)status);
+                "WARNING: Failed to renew DHCP IP address lease on TAP-Windows adapter: %s (code=%lu)",
+                strerror_win32(status, &gc), status);
         }
     }
     gc_free(&gc);
@@ -5209,12 +5209,12 @@ service_enable_dhcp(const struct tuntap *tt)
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_NONFATAL, "TUN: enabling dhcp using service failed: %s [status=%u if_index=%d]",
+        msg(M_NONFATAL, "TUN: enabling dhcp using service failed: %s [status=%u if_index=%lu]",
             strerror_win32(ack.error_number, &gc), ack.error_number, dhcp.iface.index);
     }
     else
     {
-        msg(M_INFO, "DHCP enabled on interface %d using service", dhcp.iface.index);
+        msg(M_INFO, "DHCP enabled on interface %lu using service", dhcp.iface.index);
         ret = true;
     }
 
@@ -5503,7 +5503,7 @@ tuntap_set_ip_addr(struct tuntap *tt, const char *device_guid, bool dhcp_masq_po
     /* flush arp cache */
     if (tt->backend_driver == WINDOWS_DRIVER_TAP_WINDOWS6 && index != TUN_ADAPTER_INDEX_INVALID)
     {
-        DWORD status = -1;
+        DWORD status = (DWORD)-1;
 
         if (tt->options.msg_channel)
         {
@@ -5527,7 +5527,7 @@ tuntap_set_ip_addr(struct tuntap *tt, const char *device_guid, bool dhcp_masq_po
         {
             msg(M_INFO, "Successful ARP Flush on interface [%lu] %s", index, device_guid);
         }
-        else if (status != -1)
+        else if (status != (DWORD)-1)
         {
             msg(D_TUNTAP_INFO,
                 "NOTE: FlushIpNetTable failed on interface [%lu] %s (status=%lu) : %s", index,
@@ -6221,11 +6221,12 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
     if (tt->ipapi_context_defined)
     {
         DWORD status;
+
         if ((status = DeleteIPAddress(tt->ipapi_context)) != NO_ERROR)
         {
             msg(M_WARN,
-                "Warning: DeleteIPAddress[%u] failed on TAP-Windows adapter, status=%u : %s",
-                (unsigned int)tt->ipapi_context, (unsigned int)status, strerror_win32(status, &gc));
+                "Warning: DeleteIPAddress[%lu] failed on TAP-Windows adapter, status=%lu : %s",
+                tt->ipapi_context, status, strerror_win32(status, &gc));
         }
     }
 
index 4d6dfbb00320a8644d7483f31f6b60a8ac4ea87d..ecb5e88a8510adaa7d21127fdc8cd628889e9430 100644 (file)
@@ -61,8 +61,6 @@ enum tun_driver_type
 
 #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST)
 
-#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
-
 /* time constants for --ip-win32 adaptive */
 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
 #define IPW32_SET_ADAPTIVE_TRY_NETSH    20
@@ -230,7 +228,7 @@ struct tuntap
     in_addr_t adapter_netmask;
 
     /* Windows adapter index for TAP-Windows adapter,
-     * ~0 if undefined */
+     * TUN_ADAPTER_INDEX_INVALID if undefined */
     DWORD adapter_index;
 
     int standby_iter;
index ac449fdf0d07ab9fb61fcd08a2c491a707c66ff4..b2a733196b04f204b9d470aac5877e4be22a5240 100644 (file)
@@ -1185,7 +1185,7 @@ win_wfp_block_service(bool add, bool dns_only, int index, const HANDLE pipe)
     if (ack.error_number != NO_ERROR)
     {
         msg(M_WARN,
-            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%d]",
+            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             data.iface.index);
         goto out;
index 09c709ea2991c23b0b42512b31684ab55db40711..b50aeb34a4198c5f733ecf36a195c9f128d7093c 100644 (file)
@@ -96,7 +96,7 @@ typedef list_item_t *undo_lists_t[_undo_type_max];
 typedef struct
 {
     HANDLE engine;
-    int index;
+    DWORD index;
     int metric_v4;
     int metric_v6;
 } wfp_block_data_t;
@@ -584,7 +584,7 @@ HandleAddressMessage(address_message_t *msg, undo_lists_t *lists)
     addr_row->Address = sockaddr_inet(msg->family, &msg->address);
     addr_row->OnLinkPrefixLength = (UINT8)msg->prefix_len;
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         addr_row->InterfaceIndex = msg->iface.index;
     }
@@ -667,7 +667,7 @@ HandleRouteMessage(route_message_t *msg, undo_lists_t *lists)
     fwd_row->DestinationPrefix.PrefixLength = (UINT8)msg->prefix_len;
     fwd_row->NextHop = sockaddr_inet(msg->family, &msg->gateway);
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         fwd_row->InterfaceIndex = msg->iface.index;
     }
@@ -1010,7 +1010,7 @@ HandleRegisterDNSMessage(void)
  * if action = "set" then "static" is added before $addr
  */
 static DWORD
-netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr)
+netsh_wins_cmd(const wchar_t *action, DWORD if_index, const wchar_t *addr)
 {
     DWORD err = 0;
     int timeout = 30000; /* in msec */
@@ -1036,7 +1036,7 @@ netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr)
     /* cmd template:
      * netsh interface ip $action wins $if_name $static $addr
      */
-    const wchar_t *fmt = L"netsh interface ip %ls wins %d %ls %ls";
+    const wchar_t *fmt = L"netsh interface ip %ls wins %lu %ls %ls";
 
     /* max cmdline length in wchars -- include room for worst case and some */
     size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr)
@@ -2984,7 +2984,7 @@ HandleWINSConfigMessage(const wins_cfg_message_t *msg, undo_lists_t *lists)
          */
     }
 
-    int *if_index = malloc(sizeof(msg->iface.index));
+    PDWORD if_index = malloc(sizeof(msg->iface.index));
     if (if_index)
     {
         *if_index = msg->iface.index;
@@ -3017,7 +3017,7 @@ HandleEnableDHCPMessage(const enable_dhcp_message_t *dhcp)
     /* cmd template:
      * netsh interface ipv4 set address name=$if_index source=dhcp
      */
-    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%d\" source=dhcp";
+    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%lu\" source=dhcp";
 
     /* max cmdline length in wchars -- include room for if index:
      * 10 chars for 32 bit int in decimal and +1 for NUL
@@ -3250,7 +3250,7 @@ Undo(undo_lists_t *lists)
                     break;
 
                 case undo_wins:
-                    netsh_wins_cmd(L"delete", *(int *)item->data, NULL);
+                    netsh_wins_cmd(L"delete", *(PDWORD)item->data, NULL);
                     break;
 
                 case wfp_block: