Commit 2f0eb176 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Successful DNS resolution on Windows.

parent 08c044be
...@@ -141,7 +141,7 @@ case "$target_os" in ...@@ -141,7 +141,7 @@ case "$target_os" in
;; ;;
*mingw*) *mingw*)
CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x0501" CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x0501"
LIBS="$LIBS -lws2_32" LIBS="$LIBS -lws2_32 -liphlpapi"
LDFLAGS="$LDFLAGS -Wl,--export-all-symbols" LDFLAGS="$LDFLAGS -Wl,--export-all-symbols"
;; ;;
esac esac
......
...@@ -123,7 +123,14 @@ static unsigned int belle_sip_source_get_revents(belle_sip_source_t *s,belle_sip ...@@ -123,7 +123,14 @@ static unsigned int belle_sip_source_get_revents(belle_sip_source_t *s,belle_sip
} }
static int belle_sip_poll(belle_sip_pollfd_t *pfd, int count, int duration){ static int belle_sip_poll(belle_sip_pollfd_t *pfd, int count, int duration){
DWORD ret=WaitForMultipleObjectsEx(count,pfd,FALSE,duration,FALSE); DWORD ret;
if (count == 0) {
Sleep(duration);
return 0;
}
ret=WaitForMultipleObjectsEx(count,pfd,FALSE,duration,FALSE);
if (ret==WAIT_FAILED){ if (ret==WAIT_FAILED){
belle_sip_error("WaitForMultipleObjectsEx() failed."); belle_sip_error("WaitForMultipleObjectsEx() failed.");
return -1; return -1;
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
static struct dns_resolv_conf *resconf(belle_sip_resolver_context_t *ctx) { static struct dns_resolv_conf *resconf(belle_sip_resolver_context_t *ctx) {
#ifndef _WIN32
const char *path; const char *path;
#endif
int error; int error;
if (ctx->resconf) if (ctx->resconf)
...@@ -36,6 +38,9 @@ static struct dns_resolv_conf *resconf(belle_sip_resolver_context_t *ctx) { ...@@ -36,6 +38,9 @@ static struct dns_resolv_conf *resconf(belle_sip_resolver_context_t *ctx) {
return NULL; return NULL;
} }
#ifdef _WIN32
error = dns_resconf_loadwin(ctx->resconf);
#else
path = "/etc/resolv.conf"; path = "/etc/resolv.conf";
error = dns_resconf_loadpath(ctx->resconf, path); error = dns_resconf_loadpath(ctx->resconf, path);
if (error) { if (error) {
...@@ -49,6 +54,7 @@ static struct dns_resolv_conf *resconf(belle_sip_resolver_context_t *ctx) { ...@@ -49,6 +54,7 @@ static struct dns_resolv_conf *resconf(belle_sip_resolver_context_t *ctx) {
belle_sip_error("%s dns_nssconf_loadpath error [%s]: %s", __FUNCTION__, path, dns_strerror(error)); belle_sip_error("%s dns_nssconf_loadpath error [%s]: %s", __FUNCTION__, path, dns_strerror(error));
return NULL; return NULL;
} }
#endif
return ctx->resconf; return ctx->resconf;
} }
......
...@@ -68,10 +68,12 @@ ...@@ -68,10 +68,12 @@
#if _WIN32 #if _WIN32
#ifndef FD_SETSIZE #ifndef FD_SETSIZE
#define FD_SETSIZE 256 #define FD_SETSIZE 512
#endif #endif
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <IPHlpApi.h>
#pragma comment(lib, "IPHLPAPI.lib")
#else #else
#include <sys/types.h> /* FD_SETSIZE socklen_t */ #include <sys/types.h> /* FD_SETSIZE socklen_t */
#include <sys/select.h> /* FD_ZERO FD_SET fd_set select(2) */ #include <sys/select.h> /* FD_ZERO FD_SET fd_set select(2) */
...@@ -3571,7 +3573,11 @@ struct dns_hosts *dns_hosts_local(int *error_) { ...@@ -3571,7 +3573,11 @@ struct dns_hosts *dns_hosts_local(int *error_) {
if (!(hosts = dns_hosts_open(&error))) if (!(hosts = dns_hosts_open(&error)))
goto error; goto error;
#ifdef _WIN32
if ((error = dns_hosts_loadpath(hosts, "C:/Windows/System32/drivers/etc/hosts")))
#else
if ((error = dns_hosts_loadpath(hosts, "/etc/hosts"))) if ((error = dns_hosts_loadpath(hosts, "/etc/hosts")))
#endif
goto error; goto error;
return hosts; return hosts;
...@@ -4272,6 +4278,43 @@ int dns_resconf_loadpath(struct dns_resolv_conf *resconf, const char *path) { ...@@ -4272,6 +4278,43 @@ int dns_resconf_loadpath(struct dns_resolv_conf *resconf, const char *path) {
} /* dns_resconf_loadpath() */ } /* dns_resconf_loadpath() */
#ifdef _WIN32
int dns_resconf_loadwin(struct dns_resolv_conf *resconf) {
FIXED_INFO *pFixedInfo;
ULONG ulOutBufLen;
DWORD dwRetVal;
IP_ADDR_STRING *pIPAddr;
unsigned sa_count = 0;
int error;
pFixedInfo = (FIXED_INFO *) malloc(sizeof(FIXED_INFO));
if (pFixedInfo == NULL) {
return -1;
}
ulOutBufLen = sizeof(FIXED_INFO);
if (GetNetworkParams(pFixedInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
free(pFixedInfo);
pFixedInfo = (FIXED_INFO *) malloc(ulOutBufLen);
if (pFixedInfo == NULL) {
return -1;
}
}
if ((dwRetVal = GetNetworkParams(pFixedInfo, &ulOutBufLen)) == NO_ERROR) {
memset(resconf->search, '\0', sizeof resconf->search);
memcpy(resconf->search[0], pFixedInfo->DomainName, sizeof pFixedInfo->DomainName);
pIPAddr = &pFixedInfo->DnsServerList;
do {
error = dns_resconf_pton(&resconf->nameserver[sa_count], pIPAddr->IpAddress.String);
pIPAddr = pIPAddr->Next;
} while (!error && pIPAddr && (sa_count < lengthof(resconf->nameserver)));
}
return 0;
}
#endif /* dns_resconf_loadwin() */
struct dns_anyconf { struct dns_anyconf {
char *token[16]; char *token[16];
unsigned count; unsigned count;
......
...@@ -908,6 +908,10 @@ int dns_resconf_loadfile(struct dns_resolv_conf *, FILE *); ...@@ -908,6 +908,10 @@ int dns_resconf_loadfile(struct dns_resolv_conf *, FILE *);
int dns_resconf_loadpath(struct dns_resolv_conf *, const char *); int dns_resconf_loadpath(struct dns_resolv_conf *, const char *);
#ifdef _WIN32
int dns_resconf_loadwin(struct dns_resolv_conf *);
#endif
int dns_nssconf_loadfile(struct dns_resolv_conf *, FILE *); int dns_nssconf_loadfile(struct dns_resolv_conf *, FILE *);
int dns_nssconf_loadpath(struct dns_resolv_conf *, const char *); int dns_nssconf_loadpath(struct dns_resolv_conf *, const char *);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment