Skip to content

Commit

Permalink
xp fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bradh352 committed Jan 8, 2025
1 parent 620dc2b commit d7ad10e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
10 changes: 10 additions & 0 deletions src/lib/ares_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ struct addrinfo {
# define NS_INT16SZ 2
#endif

/* Windows XP Compatibility with later MSVC/Mingw versions */
#if defined(_WIN32)
# if !defined(IF_MAX_STRING_SIZE)
# define IF_MAX_STRING_SIZE 256 /* =256 in <ifdef.h> */
# endif
# if !defined(NDIS_IF_MAX_STRING_SIZE)
# define NDIS_IF_MAX_STRING_SIZE IF_MAX_STRING_SIZE /* =256 in <ifdef.h> */
# endif
#endif

#ifndef IF_NAMESIZE
# ifdef IFNAMSIZ
# define IF_NAMESIZE IFNAMSIZ
Expand Down
34 changes: 18 additions & 16 deletions src/lib/ares_sysconfig_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ static int compareAddresses(const void *arg1, const void *arg2)
return 0;
}

#if defined(HAVE_GETBESTROUTE2) && !defined(__WATCOMC__)
/* There can be multiple routes to "the Internet". And there can be different
* DNS servers associated with each of the interfaces that offer those routes.
* We have to assume that any DNS server can serve any request. But, some DNS
Expand Down Expand Up @@ -213,21 +214,6 @@ static ULONG getBestRouteMetric(IF_LUID * const luid, /* Can't be const :( */
const SOCKADDR_INET * const dest,
const ULONG interfaceMetric)
{
/* On this interface, get the best route to that destination. */
# if !defined(HAVE_GETBESTROUTE2) || defined(__WATCOMC__)
(void)luid;
(void)dest;
(void)interfaceMetric;
/* OpenWatcom's builtin Windows SDK does not have a definition for
* MIB_IPFORWARD_ROW2, and also does not allow the usage of SOCKADDR_INET
* as a variable. Let's work around this by returning the worst possible
* metric, but only when using the OpenWatcom compiler.
* It may be worth investigating using a different version of the Windows
* SDK with OpenWatcom in the future, though this may be fixed in OpenWatcom
* 2.0.
*/
return (ULONG)-1;
# else
MIB_IPFORWARD_ROW2 row;
SOCKADDR_INET ignored;
if (GetBestRoute2(/* The interface to use. The index is ignored since we are
Expand Down Expand Up @@ -260,8 +246,8 @@ static ULONG getBestRouteMetric(IF_LUID * const luid, /* Can't be const :( */
* which describes the combination as a "sum".
*/
return row.Metric + interfaceMetric;
# endif
}
#endif

/*
* get_DNS_Windows()
Expand Down Expand Up @@ -382,9 +368,21 @@ static ares_bool_t get_DNS_Windows(char **outptr)
addressesSize = newSize;
}

# if defined(HAVE_GETBESTROUTE2) && !defined(__WATCOMC__)
/* OpenWatcom's builtin Windows SDK does not have a definition for
* MIB_IPFORWARD_ROW2, and also does not allow the usage of SOCKADDR_INET
* as a variable. Let's work around this by returning the worst possible
* metric, but only when using the OpenWatcom compiler.
* It may be worth investigating using a different version of the Windows
* SDK with OpenWatcom in the future, though this may be fixed in OpenWatcom
* 2.0.
*/
addresses[addressesIndex].metric = getBestRouteMetric(
&ipaaEntry->Luid, (SOCKADDR_INET *)((void *)(namesrvr.sa)),
ipaaEntry->Ipv4Metric);
# else
addresses[addressesIndex].metric = (ULONG)-1;
# endif

/* Record insertion index to make qsort stable */
addresses[addressesIndex].orig_idx = addressesIndex;
Expand Down Expand Up @@ -426,9 +424,13 @@ static ares_bool_t get_DNS_Windows(char **outptr)
ll_scope = ipaaEntry->Ipv6IfIndex;
}

# if defined(HAVE_GETBESTROUTE2) && !defined(__WATCOMC__)
addresses[addressesIndex].metric = getBestRouteMetric(
&ipaaEntry->Luid, (SOCKADDR_INET *)((void *)(namesrvr.sa)),
ipaaEntry->Ipv6Metric);
# else
addresses[addressesIndex].metric = (ULONG)-1;
# endif

/* Record insertion index to make qsort stable */
addresses[addressesIndex].orig_idx = addressesIndex;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/event/ares_event_configchg.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,13 +722,16 @@ void ares_event_configchg_destroy(ares_event_configchg_t *configchg)
ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg,
ares_event_thread_t *e)
{
(void)configchg;
(void)e;
/* No ability */
return ARES_ENOTIMP;
}

void ares_event_configchg_destroy(ares_event_configchg_t *configchg)
{
/* No-op */
(void)configchg;
}

#endif
7 changes: 6 additions & 1 deletion src/lib/util/ares_iface_ips.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,13 @@ static ares_status_t ares_iface_ips_enumerate(ares_iface_ips_t *ips,
}

status = ares_iface_ips_add(ips, addrflag, ifname, &addr,
#if _WIN32_WINNT >= 0x0600
ipaddr->OnLinkPrefixLength /* netmask */,
address->Ipv6IfIndex /* ll_scope */);
address->Ipv6IfIndex /* ll_scope */
#else
32, 0
#endif
);

if (status != ARES_SUCCESS) {
goto done;
Expand Down
2 changes: 1 addition & 1 deletion test/ares-fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#ifdef _WIN32
# include <io.h>
#else
# include <unistd.h>
Expand Down

0 comments on commit d7ad10e

Please sign in to comment.