diff --git a/libtransmission/blocklist.c b/libtransmission/blocklist.c index ae2c00d01..73897006a 100644 --- a/libtransmission/blocklist.c +++ b/libtransmission/blocklist.c @@ -18,6 +18,8 @@ #include #define WINVER WindowsXP #include + #define PROT_READ PAGE_READONLY + #define MAP_PRIVATE FILE_MAP_COPY #endif #ifndef WIN32 diff --git a/libtransmission/net.c b/libtransmission/net.c index eccb673e2..0e244c6ee 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -64,8 +64,8 @@ const tr_address tr_in6addr_any = { TR_AF_INET6, { IN6ADDR_ANY_INIT } }; const tr_address tr_inaddr_any = { TR_AF_INET, { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } }; #ifdef WIN32 -static const char * -inet_ntop( int af, const void *src, char *dst, socklen_t cnt ) +const char * +inet_ntop( int af, const void * src, char * dst, socklen_t cnt ) { if (af == AF_INET) { @@ -90,34 +90,48 @@ inet_ntop( int af, const void *src, char *dst, socklen_t cnt ) return NULL; } -static int -inet_pton(int af, const char *src, void *dst) +int +inet_pton( int af, const char * src, void * dst ) { - struct addrinfo hints; - struct addrinfo *res; - struct addrinfo *ressave; + struct addrinfo hints, *res, *ressave; + struct sockaddr_in * s4; + struct sockaddr_in6 * s6; - memset(&hints, 0, sizeof(struct addrinfo)); + memset( &hints, 0, sizeof( struct addrinfo )); hints.ai_family = af; + hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(src, NULL, &hints, &res) != 0) - return -1; + if( getaddrinfo( src, NULL, &hints, &res ) ) { + if( WSAGetLastError() == WSAHOST_NOT_FOUND ) + return 0; + else { + errno = EAFNOSUPPORT; + return -1; + } + } ressave = res; - - while (res) - { - memcpy(dst, res->ai_addr, res->ai_addrlen); + while( res ) { + switch (res->ai_family) { + case AF_INET: + s4 = (struct sockaddr_in *) res->ai_addr; + memcpy( dst, &s4->sin_addr, sizeof( struct in_addr ) ); + break; + case AF_INET6: + s6 = (struct sockaddr_in6 *) res->ai_addr; + memcpy( dst, &s6->sin6_addr, sizeof( struct in6_addr ) ); + break; + default: /* AF_UNSPEC, AF_NETBIOS */ + break; + } res = res->ai_next; } freeaddrinfo(ressave); - return 0; + return 1; } - #endif - void tr_netInit( void ) { diff --git a/libtransmission/net.h b/libtransmission/net.h index 286ae9b99..8b1b1fda6 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -124,5 +124,13 @@ void tr_netInit( void ); const unsigned char *tr_globalIPv6( void ); +#if defined( WIN32) && !defined(QT_DLL) +/* The QT exclusion is because something clashes whith the next include */ +#include /* socklen_t */ + +/** @brief Missing in Windows and Mingw */ +const char *inet_ntop( int af, const void *src, char *dst, socklen_t cnt ); +int inet_pton(int af, const char *src, void *dst); +#endif #endif /* _TR_NET_H_ */ diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index baa02cd41..f7be7a377 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -11,6 +11,7 @@ */ #include +#include /* error codes ERANGE, ... */ #include /* memcpy, memcmp, strstr */ #include /* qsort */ diff --git a/libtransmission/trevent.c b/libtransmission/trevent.c index 1378d986f..5619c97f5 100644 --- a/libtransmission/trevent.c +++ b/libtransmission/trevent.c @@ -226,7 +226,6 @@ static void libeventThreadFunc( void * veh ) { tr_event_handle * eh = veh; - tr_dbg( "Starting libevent thread" ); #ifndef WIN32 /* Don't exit when writing on a broken socket */ diff --git a/libtransmission/web.c b/libtransmission/web.c index 20112f481..2e7b7d586 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -10,7 +10,11 @@ * $Id$ */ -#include +#ifdef WIN32 + #include +#else + #include +#endif #include #include @@ -306,12 +310,12 @@ tr_webThreadFunc( void * vsession ) #ifdef WIN32 /* see ticket #3311, comments 16-18 */ - if( !r_fd_set.fd_count && !w_fd.set.fd_count && !c_fd_set.fd_count ) - tr_wait( msec ); + if( !r_fd_set.fd_count && !w_fd_set.fd_count && !c_fd_set.fd_count ) + tr_wait_msec( msec ); else select( 0, r_fd_set.fd_count ? &r_fd_set : NULL, - w_fd.set.fd_count ? &w_fd_set : NULL, - c_fd.set.fd_count ? &c_fd_set : NULL, &t ); + w_fd_set.fd_count ? &w_fd_set : NULL, + c_fd_set.fd_count ? &c_fd_set : NULL, &t ); #else select( max_fd+1, &r_fd_set, &w_fd_set, &c_fd_set, &t ); #endif