Fix Watt-32 compilation support (#781)

Watt-32 (https://www.watt-32.net/) support has been broken for a long
time. Patch c-ares to fix Watt-32 support and also gets rid of the
`WIN32` macro which adds confusion, only use `USE_WINSOCK` macro.

Add a CI/CD task to build c-ares on Windows using MSVC with Watt-32.

Fixes Issue: #780
Fix By: Brad House (@bradh352)
pull/775/head
Brad House 6 months ago committed by GitHub
parent 9d36fd2030
commit f527554c7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      .github/workflows/coverity.yml
  2. 7
      .github/workflows/watcom.yml
  3. 51
      .github/workflows/watt32.yml
  4. 2
      Makefile.Watcom
  5. 13
      Makefile.msvc
  6. 25
      include/ares.h
  7. 4
      src/lib/ares__addrinfo2hostent.c
  8. 7
      src/lib/ares__addrinfo_localhost.c
  9. 4
      src/lib/ares__buf.c
  10. 4
      src/lib/ares__buf.h
  11. 2
      src/lib/ares__hosts_file.c
  12. 2
      src/lib/ares__socket.c
  13. 2
      src/lib/ares__timeval.c
  14. 4
      src/lib/ares_event_configchg.c
  15. 4
      src/lib/ares_event_thread.c
  16. 2
      src/lib/ares_event_win32.c
  17. 5
      src/lib/ares_getaddrinfo.c
  18. 4
      src/lib/ares_gethostbyaddr.c
  19. 5
      src/lib/ares_init.c
  20. 2
      src/lib/ares_library_init.c
  21. 4
      src/lib/ares_platform.c
  22. 2
      src/lib/ares_platform.h
  23. 10
      src/lib/ares_private.h
  24. 12
      src/lib/ares_setup.h
  25. 9
      src/lib/ares_sysconfig.c
  26. 15
      src/lib/config-win32.h
  27. 5
      src/lib/setup_once.h
  28. 2
      src/lib/windows_port.c
  29. 5
      src/tools/adig.c
  30. 2
      src/tools/ahost.c

@ -13,8 +13,6 @@ jobs:
steps:
- name: Checkout Source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: apt dependencies
run: sudo apt-get install cmake ninja-build
- name: Download Coverity Build Tool

@ -3,11 +3,8 @@
name: OpenWatcom
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: windows-latest
@ -15,8 +12,6 @@ jobs:
- uses: open-watcom/setup-watcom@v0
- name: Checkout Source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: configure
run: buildconf.bat
shell: cmd

@ -0,0 +1,51 @@
# Copyright (C) The c-ares project and its contributors
# SPDX-License-Identifier: MIT
name: WATT32
on:
push:
pull_request:
jobs:
build:
runs-on: windows-latest
env:
WATT_ROOT: "${{ github.workspace }}\\watt-32"
steps:
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86
- name: Checkout c-ares
uses: actions/checkout@v4
- name: Checkout Watt-32
uses: actions/checkout@v4
with:
repository: gvanem/Watt-32
path: watt-32
- name: "Watt-32: Make sure lang.c timestamp is ahead of checkout time so it doesn't try to rebuild and fail"
run: (Get-ChildItem "watt-32/src/lang.c").LastWriteTime = Get-Date
- name: Build Watt-32
run: |
cd watt-32\src
& .\configur.bat visualc
echo "Configured"
nmake -nologo -f visualc-release_32.mak
# Powershell doesn't preserve environment variables set by configur.bat
env:
MKMAKE: ..\util\win32\mkmake.exe
MKDEP: ..\util\win32\mkdep.exe
HC_ERR: ..\util\win32\hc_err.exe
WC_ERR: ..\util\win32\wc_err.exe
BCC_ERR: ..\util\win32\bcc_err.exe
W32_BIN2C: ..\util\win32\bin2c.exe
W32_BIN2C_: ../util/win32/bin2c.exe
W32_NASM: ..\util\win32\nasm.exe
W32_NASM_: ../util/win32/nasm.exe
DJ_ERR: ..\util\win32\dj_err.exe
- name: Build c-ares
run: |
Copy-Item "include\ares_build.h.dist" -Destination "include\ares_build.h"
nmake USE_WATT32=1 CFG=dll-release /NOLOGO /f .\Makefile.msvc
nmake USE_WATT32=1 CFG=lib-release /NOLOGO /f .\Makefile.msvc

@ -42,7 +42,7 @@ RD = rmdir /q /s 2>NUL
CP = copy
CFLAGS = -3r -mf -hc -zff -zgf -zq -zm -zc -s -fr=con -w2 -fpi -oilrtfm -aa &
-wcd=201 -bt=nt -d+ -dWIN32 -dCARES_BUILDING_LIBRARY &
-wcd=201 -bt=nt -d+ -dCARES_BUILDING_LIBRARY &
-dNTDDI_VERSION=0x06020000 -I. -I.\include -I.\src\lib $(SYS_INCL)
LFLAGS = option quiet, map, caseexact, eliminate

@ -71,7 +71,9 @@ RTLIBD = /MTd
# otherwise Winsock tcp/ip stack will be used as default.
# --------------------------------------------------------
!IFNDEF USE_WATT32
USE_WATT32 = 0
!ENDIF
# --------------------------------------------------------
# Detect compiler version.
@ -176,11 +178,14 @@ PROG3_OBJDIR = $(PROG3_OUTDIR)\obj
# -------------------------------------
!IF "$(USE_WATT32)" == "1"
CFLAGS = /UWIN32 /DWATT32 /I$(WATT_ROOT)\inc
EX_LIBS_REL = $(WATT_ROOT)\lib\wattcpvc_imp.lib
EX_LIBS_DBG = $(WATT_ROOT)\lib\wattcpvc_imp_d.lib
CFLAGS = /D_WIN32_WINNT=0x0602 /DWATT32 /I$(WATT_ROOT)\inc
! IFNDEF PLATFORM
PLATFORM = x86
! ENDIF
EX_LIBS_REL = $(WATT_ROOT)\lib\$(PLATFORM)\wattcpvc_imp.lib advapi32.lib
EX_LIBS_DBG = $(WATT_ROOT)\lib\$(PLATFORM)\wattcpvc_imp_d.lib advapi32.lib
!ELSE
CFLAGS = /DWIN32 /D_WIN32_WINNT=0x0602
CFLAGS = /D_WIN32_WINNT=0x0602
EX_LIBS_REL = ws2_32.lib advapi32.lib kernel32.lib iphlpapi.lib
EX_LIBS_DBG = ws2_32.lib advapi32.lib kernel32.lib iphlpapi.lib
!ENDIF

@ -32,15 +32,6 @@
#include "ares_build.h" /* c-ares build definitions */
#include "ares_rules.h" /* c-ares rules enforcement */
/*
* Define WIN32 when build target is Win32 API
*/
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && \
!defined(__SYMBIAN32__)
# define WIN32
#endif
#include <sys/types.h>
/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
@ -56,20 +47,20 @@
# include <sys/bsdskt.h>
#endif
#if defined(_WIN32)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
#endif
#if defined(WATT32)
# include <netinet/in.h>
# include <sys/socket.h>
# include <tcp.h>
#elif defined(_WIN32_WCE)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <winsock.h>
#elif defined(WIN32)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
#elif defined(_WIN32)
# include <windows.h>
# include <winsock2.h>
# include <ws2tcpip.h>
@ -315,7 +306,7 @@ typedef enum {
*/
#ifndef ares_socket_typedef
# ifdef WIN32
# if defined(_WIN32) && !defined(WATT32)
typedef SOCKET ares_socket_t;
# define ARES_SOCKET_BAD INVALID_SOCKET
# else

@ -39,8 +39,6 @@
# include <arpa/inet.h>
#endif
#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
@ -50,8 +48,6 @@
#endif
#include "ares.h"
#include "ares_dns.h"
#include "ares_inet_net_pton.h"
#include "ares_private.h"
ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,

@ -37,11 +37,10 @@
# include <arpa/inet.h>
#endif
#if defined(_WIN32) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
#if defined(USE_WINSOCK)
# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
# include <ws2ipdef.h>
# endif
#if defined(USE_WINSOCK)
# if defined(HAVE_IPHLPAPI_H)
# include <iphlpapi.h>
# endif
@ -137,7 +136,7 @@ static ares_status_t
ares__system_loopback_addrs(int aftype, unsigned short port,
struct ares_addrinfo_node **nodes)
{
#if defined(_WIN32) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && \
#if defined(USE_WINSOCK) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && \
!defined(__WATCOMC__)
PMIB_UNICASTIPADDRESS_TABLE table;
unsigned int i;

@ -229,9 +229,9 @@ ares_status_t ares__buf_append(ares__buf_t *buf, const unsigned char *data,
return ARES_SUCCESS;
}
ares_status_t ares__buf_append_byte(ares__buf_t *buf, unsigned char byte)
ares_status_t ares__buf_append_byte(ares__buf_t *buf, unsigned char b)
{
return ares__buf_append(buf, &byte, 1);
return ares__buf_append(buf, &b, 1);
}
ares_status_t ares__buf_append_be16(ares__buf_t *buf, unsigned short u16)

@ -85,10 +85,10 @@ ares_status_t ares__buf_append(ares__buf_t *buf, const unsigned char *data,
/*! Append a single byte to the dynamic buffer object
*
* \param[in] buf Initialized buffer object
* \param[in] byte Single byte to append to buffer object.
* \param[in] b Single byte to append to buffer object.
* \return ARES_SUCCESS or one of the c-ares error codes
*/
ares_status_t ares__buf_append_byte(ares__buf_t *buf, unsigned char byte);
ares_status_t ares__buf_append_byte(ares__buf_t *buf, unsigned char b);
/*! Append a null-terminated string to the dynamic buffer object
*

@ -658,7 +658,7 @@ static ares_status_t ares__hosts_path(const ares_channel_t *channel,
}
if (!path_hosts) {
#ifdef WIN32
#if defined(USE_WINSOCK)
char PATH_HOSTS[MAX_PATH] = "";
char tmp[MAX_PATH];
HKEY hkeyHosts;

@ -145,7 +145,7 @@ static int setsocknonblock(ares_socket_t sockfd, /* operate on this */
#endif
}
#if defined(IPV6_V6ONLY) && defined(WIN32)
#if defined(IPV6_V6ONLY) && defined(USE_WINSOCK)
/* It makes support for IPv4-mapped IPv6 addresses.
* Linux kernel, NetBSD, FreeBSD and Darwin: default is off;
* Windows Vista and later: default is on;

@ -28,7 +28,7 @@
#include "ares.h"
#include "ares_private.h"
#if defined(WIN32) && !defined(MSDOS)
#if defined(_WIN32) && !defined(MSDOS)
ares_timeval_t ares__tvnow(void)
{

@ -173,7 +173,7 @@ done:
return status;
}
#elif defined(_WIN32)
#elif defined(USE_WINSOCK)
# include <winsock2.h>
# include <iphlpapi.h>
@ -388,7 +388,7 @@ done:
return status;
}
#elif defined(HAVE_STAT)
#elif defined(HAVE_STAT) && !defined(_WIN32)
# ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif

@ -355,7 +355,7 @@ static const ares_event_sys_t *ares_event_fetch_sys(ares_evsys_t evsys)
{
switch (evsys) {
case ARES_EVSYS_WIN32:
#if defined(_WIN32)
#if defined(USE_WINSOCK)
return &ares_evsys_win32;
#else
return NULL;
@ -391,7 +391,7 @@ static const ares_event_sys_t *ares_event_fetch_sys(ares_evsys_t evsys)
/* case ARES_EVSYS_DEFAULT: */
default:
#if defined(_WIN32)
#if defined(USE_WINSOCK)
return &ares_evsys_win32;
#elif defined(HAVE_KQUEUE)
return &ares_evsys_kqueue;

@ -33,7 +33,7 @@
# include <limits.h>
#endif
#ifdef _WIN32
#if defined(USE_WINSOCK)
/* IMPLEMENTATION NOTES
* ====================

@ -60,10 +60,7 @@
#include "ares_private.h"
#include "ares_dns.h"
#ifdef WATT32
# undef WIN32
#endif
#ifdef WIN32
#ifdef _WIN32
# include "ares_platform.h"
#endif

@ -44,10 +44,6 @@
#include "ares_platform.h"
#include "ares_private.h"
#ifdef WATT32
# undef WIN32
#endif
struct addr_query {
/* Arguments passed to ares_gethostbyaddr() */
ares_channel_t *channel;

@ -67,11 +67,6 @@
#include "ares_private.h"
#include "ares_event.h"
#ifdef WATT32
# undef WIN32 /* Redefined in MingW/MSVC headers */
#endif
int ares_init(ares_channel_t **channelptr)
{
return ares_init_options(channelptr, NULL, 0);

@ -55,7 +55,7 @@ static void *default_malloc(size_t size)
return malloc(size);
}
#if defined(WIN32)
#if defined(_WIN32)
/* We need indirections to handle Windows DLL rules. */
static void *default_realloc(void *p, size_t size)
{

@ -31,7 +31,7 @@
#include "ares_platform.h"
#include "ares_private.h"
#if defined(WIN32) && !defined(MSDOS)
#if defined(_WIN32) && !defined(MSDOS)
# define V_PLATFORM_WIN32s 0
# define V_PLATFORM_WIN32_WINDOWS 1
@ -78,7 +78,7 @@ win_platform ares__getplatform(void)
}
}
#endif /* WIN32 && ! MSDOS */
#endif /* _WIN32 && ! MSDOS */
#if defined(_WIN32_WCE)

@ -29,7 +29,7 @@
#include "ares_setup.h"
#if defined(WIN32) && !defined(MSDOS)
#if defined(_WIN32) && !defined(MSDOS)
typedef enum {
WIN_UNKNOWN,

@ -27,14 +27,6 @@
#ifndef __ARES_PRIVATE_H
#define __ARES_PRIVATE_H
/*
* Define WIN32 when build target is Win32 API
*/
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
@ -56,7 +48,7 @@
*/
#define CARES_INADDR_CAST(type, var) ((type)((void *)var))
#if defined(WIN32) && !defined(WATT32)
#if defined(USE_WINSOCK)
# define WIN_NS_9X "System\\CurrentControlSet\\Services\\VxD\\MSTCP"
# define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters"

@ -26,14 +26,6 @@
#ifndef HEADER_CARES_SETUP_H
#define HEADER_CARES_SETUP_H
/*
* Define WIN32 when build target is Win32 API
*/
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
/*
* Include configuration script results or hand-crafted
* configuration file for platforms which lack config tool.
@ -43,7 +35,7 @@
# include "ares_config.h"
#else
# ifdef WIN32
# ifdef _WIN32
# include "config-win32.h"
# endif
@ -163,7 +155,7 @@
# define HAVE_UNISTD_H 1
# endif
# if !defined(HAVE_SYS_UIO_H) && !defined(WIN32) && !defined(MSDOS)
# if !defined(HAVE_SYS_UIO_H) && !defined(_WIN32) && !defined(MSDOS)
# define HAVE_SYS_UIO_H
# endif

@ -71,12 +71,7 @@
#include "ares_platform.h"
#include "ares_private.h"
#ifdef WATT32
# undef WIN32 /* Redefined in MingW/MSVC headers */
#endif
#ifdef WIN32
#if defined(USE_WINSOCK)
/*
* get_REG_SZ()
*
@ -1074,7 +1069,7 @@ ares_status_t ares__init_by_sysconfig(ares_channel_t *channel)
memset(&sysconfig, 0, sizeof(sysconfig));
#ifdef _WIN32
#if defined(USE_WINSOCK)
status = ares__init_sysconfig_windows(&sysconfig);
#elif defined(__MVS__)
status = ares__init_sysconfig_mvs(&sysconfig);

@ -88,7 +88,7 @@
#define HAVE_IPHLPAPI_H 1
/* Define if you have <netioapi.h> header file */
#ifndef __WATCOMC__
#if !defined(__WATCOMC__) && !defined(WATT32)
# define HAVE_NETIOAPI_H 1
#endif
@ -207,7 +207,12 @@
/* Specifics for the Watt-32 tcp/ip stack. */
#ifdef WATT32
# define SOCKET int
# undef RECV_TYPE_ARG1
# define RECV_TYPE_ARG1 int
# undef SEND_TYPE_ARG1
# define SEND_TYPE_ARG1 int
# undef RECVFROM_TYPE_ARG1
# define RECVFROM_TYPE_ARG1 int
# define NS_INADDRSZ 4
# define HAVE_ARPA_NAMESER_H 1
# define HAVE_ARPA_INET_H 1
@ -219,9 +224,12 @@
# define HAVE_PF_INET6 1
# define HAVE_STRUCT_IN6_ADDR 1
# define HAVE_STRUCT_SOCKADDR_IN6 1
# define HAVE_WRITEV 1
# undef HAVE_WINSOCK_H
# undef HAVE_WINSOCK2_H
# undef HAVE_WS2TCPIP_H
# undef HAVE_IPHLPAPI_H
# undef HAVE_NETIOAPI_H
#endif
/* Threading support enabled */
@ -342,7 +350,8 @@
# define HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID 1
#endif
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) && !defined(__WATCOMC__)
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) && \
!defined(__WATCOMC__) && !defined(WATT32)
/* Define if you have if_nametoindex() */
# define HAVE_IF_NAMETOINDEX 1
/* Define if you have if_indextoname() */

@ -75,11 +75,6 @@
# include <time.h>
#endif
#ifdef WIN32
# include <io.h>
# include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

@ -11,7 +11,7 @@
/* only do the following on windows
*/
#if (defined(WIN32) || defined(WATT32)) && !defined(MSDOS)
#if defined(_WIN32) && !defined(MSDOS)
# ifdef __WATCOMC__
/*

@ -62,11 +62,6 @@
#include "ares_getopt.h"
#ifdef WATT32
# undef WIN32 /* Redefined in MingW headers */
#endif
typedef struct {
ares_bool_t is_help;
struct ares_options options;

@ -27,7 +27,7 @@
#include "ares_setup.h"
#if !defined(WIN32) || defined(WATT32)
#if !defined(_WIN32) || defined(WATT32)
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>

Loading…
Cancel
Save