From a4fdccfa707a8e9bfff4dee7abaa561a2c797646 Mon Sep 17 00:00:00 2001 From: fcolin Date: Wed, 20 Oct 2010 14:32:41 +0000 Subject: portage IPV6 Windows --- src/ivy.c | 11 ++++++----- src/ivysocket.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/ivy.c b/src/ivy.c index c9b7828..11e1ffa 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -25,6 +25,7 @@ #include #ifdef WIN32 +#include #include #define snprintf _snprintf #else @@ -494,19 +495,19 @@ static RWIvyClientPtr CheckConnected( Client sclnt ) /* client different mais port identique */ if ((iclient->client != sclnt) && (remoteport == iclient->app_port)) { + int same_addr = 0; /* et meme machine */ addr1 = SocketGetRemoteAddr( iclient->client ); addr2 = SocketGetRemoteAddr( sclnt ); - int same = 0; if ( ipv6 ) { - same = memcmp( &((struct sockaddr_in6 *)addr1)->sin6_addr, &( (struct sockaddr_in6 *)addr2)->sin6_addr, sizeof( struct in6_addr) )== 0 ; + same_addr = memcmp( &((struct sockaddr_in6 *)addr1)->sin6_addr, &( (struct sockaddr_in6 *)addr2)->sin6_addr, sizeof( struct in6_addr) )== 0 ; } else { - same = ( (struct sockaddr_in *)addr1)->sin_addr.s_addr == ( (struct sockaddr_in *)addr2)->sin_addr.s_addr; + same_addr = ( (struct sockaddr_in *)addr1)->sin_addr.s_addr == ( (struct sockaddr_in *)addr2)->sin_addr.s_addr; } - if ( same ) + if ( same_addr ) { TRACE ("DBG> CheckConnected " "clnt->app_uuid[%s] et iclient->app_uuid[%s] %s\n", @@ -995,7 +996,7 @@ void IvyStart (const char* bus) if ( ipv6 ) { char dst[1024]; - char * bcast_addr = inet_ntop(AF_INET6, &ipv6addr, + const char * bcast_addr = inet_ntop(AF_INET6, &ipv6addr, dst, sizeof(dst) ); if ( bcast_addr ) { diff --git a/src/ivysocket.c b/src/ivysocket.c index 4cfa4a2..ad9a876 100644 --- a/src/ivysocket.c +++ b/src/ivysocket.c @@ -21,6 +21,7 @@ #endif #ifdef WIN32 +#include #include #endif #include @@ -428,7 +429,7 @@ char *SocketGetPeerHost (Client client ) socklen_t len = sizeof(name); err = getpeername (client->fd, (struct sockaddr *)&name, &len ); if (err < 0 ) return "can't get peer"; - host = gethostbyaddr (&name.sin6_addr,sizeof(name.sin6_addr),name.sin6_family); + host = gethostbyaddr ((const char*)&name.sin6_addr,sizeof(name.sin6_addr),name.sin6_family); } else { @@ -436,12 +437,25 @@ char *SocketGetPeerHost (Client client ) socklen_t len = sizeof(name); err = getpeername (client->fd, (struct sockaddr *)&name, &len ); if (err < 0 ) return "can't get peer"; - host = gethostbyaddr (&name.sin_addr,sizeof(name.sin_addr),name.sin_family); + host = gethostbyaddr ((const char*)&name.sin_addr,sizeof(name.sin_addr),name.sin_family); } if (host == NULL ) { +#ifdef WIN32 + DWORD dwError = WSAGetLastError(); + if (dwError != 0) { + if (dwError == WSAHOST_NOT_FOUND) { + fprintf(stderr, "SocketGetPeerHost :: gethostbyaddr Host not found\n"); + } else if (dwError == WSANO_DATA) { + fprintf(stderr, "SocketGetPeerHost :: gethostbyaddr No data record found\n"); + } else { + fprintf(stderr, "SocketGetPeerHost :: gethostbyaddr Function failed with error: %ld\n", dwError); + } + } +#else fprintf(stderr, "SocketGetPeerHost :: gethostbyaddr %s\n", hstrerror( h_errno) ); +#endif return "can't translate addr"; } return host->h_name; @@ -499,7 +513,20 @@ void SocketGetRemoteHost (Client client, char **host, unsigned short *port ) if (hostp == NULL ) { +#ifdef WIN32 + DWORD dwError = WSAGetLastError(); + if (dwError != 0) { + if (dwError == WSAHOST_NOT_FOUND) { + fprintf(stderr, "SocketGetRemoteHost :: gethostbyaddr Host not found\n"); + } else if (dwError == WSANO_DATA) { + fprintf(stderr, "SocketGetRemoteHost :: gethostbyaddr No data record found\n"); + } else { + fprintf(stderr, "SocketGetRemoteHost :: gethostbyaddr Function failed with error: %ld\n", dwError); + } + } +#else fprintf(stderr, "SocketGetRemoteHost :: gethostbyaddr %s\n", hstrerror( h_errno) ); +#endif *host = "unknown"; } else *host = hostp->h_name; -- cgit v1.1