Index: src/makemake.tcl ================================================================== --- src/makemake.tcl +++ src/makemake.tcl @@ -939,10 +939,14 @@ LIB += -lnetapi32 -lkernel32 -luser32 -ladvapi32 -lws2_32 endif else LIB += -lkernel32 -lws2_32 endif + +#### Library required for DNS lookups. +# +LIB += ldnsapi #### Tcl shell for use in running the fossil test suite. This is only # used for testing. # TCLSH = tclsh @@ -1313,11 +1317,11 @@ SSL = CFLAGS = -o BCC = $(DMDIR)\bin\dmc $(CFLAGS) TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL) -LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 +LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi } writeln "SQLITE_OPTIONS = [join $SQLITE_OPTIONS { }]\n" writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS { }]\n" writeln -nonewline "SRC =" foreach s [lsort $src] { @@ -1705,11 +1709,11 @@ BCC = $(CC) $(CFLAGS) TCC = $(CC) /c $(CFLAGS) $(MSCDEF) $(INCL) RCC = $(RC) /D_WIN32 /D_MSC_VER $(MSCDEF) $(INCL) MTC = mt -LIBS = ws2_32.lib advapi32.lib +LIBS = ws2_32.lib advapi32.lib dnsapi.lib LIBDIR = !if $(FOSSIL_DYNAMIC_BUILD)!=0 TCC = $(TCC) /DFOSSIL_DYNAMIC_BUILD=1 RCC = $(RCC) /DFOSSIL_DYNAMIC_BUILD=1 @@ -2098,11 +2102,11 @@ WINDIR=$(B)/win/ ZLIBSRCDIR=../../zlib/ # define linker command and options LINK=$(PellesCDir)/bin/polink.exe -LINKFLAGS=-subsystem:console -machine:$(TARGETMACHINE_LN) /LIBPATH:$(PellesCDir)\lib\win$(TARGETEXTEND) /LIBPATH:$(PellesCDir)\lib kernel32.lib advapi32.lib delayimp$(TARGETEXTEND).lib Wsock32.lib Crtmt$(TARGETEXTEND).lib +LINKFLAGS=-subsystem:console -machine:$(TARGETMACHINE_LN) /LIBPATH:$(PellesCDir)\lib\win$(TARGETEXTEND) /LIBPATH:$(PellesCDir)\lib kernel32.lib advapi32.lib delayimp$(TARGETEXTEND).lib Wsock32.lib dnsapi.lib Crtmt$(TARGETEXTEND).lib # define standard C-compiler and flags, used to compile # the fossil binary. Some special definitions follow for # special files follow CC=$(PellesCDir)\bin\pocc.exe Index: src/smtp.c ================================================================== --- src/smtp.c +++ src/smtp.c @@ -19,21 +19,22 @@ ** to RFC 5321. */ #include "config.h" #include "smtp.h" #include - -#ifdef __linux__ -# define FOSSIL_ENABLE_DNS_LOOKUP -#endif - -#if defined(FOSSIL_ENABLE_DNS_LOOKUP) +#if defined(__linux__) # include # include # include # include -#endif /* defined(FOSSIL_ENABLE_DNS_LOOKUP) */ +# define FOSSIL_UNIX_STYLE_DNS 1 +#endif +#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__) +# include +# include +# define FOSSIL_WINDOWS_STYLE_DNS 1 +#endif /* ** Find the hostname for receiving email for the domain given ** in zDomain. Return NULL if not found or not implemented. @@ -42,11 +43,11 @@ ** ** The returned string is obtained from fossil_malloc() ** and should be released using fossil_free(). */ char *smtp_mx_host(const char *zDomain){ -#if defined(FOSSIL_ENABLE_DNS_LOOKUP) +#if defined(FOSSIL_UNIX_STYLE_DNS) int nDns; /* Length of the DNS reply */ int rc; /* Return code from various APIs */ int i; /* Loop counter */ int iBestPriority = 9999999; /* Best priority */ int nRec; /* Number of answers */ @@ -80,12 +81,41 @@ if( pBest ){ ns_name_uncompress(aDns, aDns+nDns, pBest+2, zHostname, sizeof(zHostname)); return fossil_strdup(zHostname); } -#endif /* defined(FOSSIL_ENABLE_DNS_LOOKUP) */ + return 0; +#elif defined(FOSSIL_WINDOWS_STYLE_DNS) + DNS_STATUS status; /* Return status */ + PDNS_RECORDA pDnsRecord, p; /* Pointer to DNS_RECORD structure */ + int iBestPriority = 9999999; /* Best priority */ + char *pBest = 0; /* RDATA for the best answer */ + + status = DnsQuery_UTF8(zDomain, /* Domain name */ + DNS_TYPE_MX, /* DNS record type */ + DNS_QUERY_STANDARD, /* Query options */ + NULL, /* List of DNS servers */ + &pDnsRecord, /* Query results */ + NULL); /* Reserved */ + if( status ) return NULL; + + p = pDnsRecord; + while( p ){ + if( p->Data.MX.wPreferenceData.MX.wPreference; + pBest = p->Data.MX.pNameExchange; + } + p = p->pNext; + } + if( pBest ){ + pBest = fossil_strdup(pBest); + } + DnsRecordListFree(pDnsRecord, DnsFreeRecordListDeep); + return pBest; +#else return 0; +#endif /* defined(FOSSIL_WINDOWS_STYLE_DNS) */ } /* ** COMMAND: test-find-mx ** @@ -94,11 +124,11 @@ ** Do a DNS MX lookup to find the hostname for sending email for ** DOMAIN. */ void test_find_mx(void){ int i; - if( g.argc<2 ){ + if( g.argc<=2 ){ usage("DOMAIN ..."); } for(i=2; i