On 27.06.2018 21:24, Richard Hipp wrote:
> If anybody can suggest patches that will get this routine
> (https://fossil-scm.org/fossil/info/5e083abf6?ln=47) to compile and
> work on windows, that would really be helpful.  Thanks.
> 

Sample Windows program, needs the dnsapi.lib for linking:

#include <windows.h>  /* Windows */
#include <windns.h>   /* DNS API's */
#include <winsock.h>  /* Windows sockets */
#include <string.h>   /* For strdup() */
#include <stdio.h>    /* Standard I/O */

char *smtp_mx_host(const char *zDomain){
  DNS_STATUS status;               /* Return status */
  PDNS_RECORD pDnsRecord, p;       /* Pointer to DNS_RECORD structure */
  int iBestPriority = 9999999;     /* Best priority */
  unsigned 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.wPreference<iBestPriority ){
      iBestPriority = p->Data.MX.wPreference;
      pBest = p->Data.MX.pNameExchange;
    }
    p = p->pNext;
  }
  if( pBest ){
    pBest = strdup(pBest);
  }
  DnsRecordListFree(pDnsRecord, DnsFreeRecordListDeep);
  return pBest;
}



int main(int argc, char *argv[]){
  int i;

  for(i=1; i<argc; i++){
    char *z = smtp_mx_host(argv[i]);
    printf("%s: %s\n", argv[i], z);
    free(z);
  }
  return 0;
}


-- 
Thomas Schnurrenberger
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to