summaryrefslogtreecommitdiff
path: root/src/ivysocket.c
diff options
context:
space:
mode:
authorfcolin2010-11-30 17:39:22 +0000
committerfcolin2010-11-30 17:39:22 +0000
commit4d2f14d5e0ef1477b64f5214af535b6dd358c3b8 (patch)
tree560795b34b8c981544d481d45005cc9cefc70917 /src/ivysocket.c
parenta7117dc569920436cf08d4954fe02b6ccd560c74 (diff)
downloadivy-c-4d2f14d5e0ef1477b64f5214af535b6dd358c3b8.zip
ivy-c-4d2f14d5e0ef1477b64f5214af535b6dd358c3b8.tar.gz
ivy-c-4d2f14d5e0ef1477b64f5214af535b6dd358c3b8.tar.bz2
ivy-c-4d2f14d5e0ef1477b64f5214af535b6dd358c3b8.tar.xz
remove reverse DNS resolution in CheckConnected
Diffstat (limited to 'src/ivysocket.c')
-rw-r--r--src/ivysocket.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/ivysocket.c b/src/ivysocket.c
index cf39275..bc7a03a 100644
--- a/src/ivysocket.c
+++ b/src/ivysocket.c
@@ -24,6 +24,7 @@
#include <Ws2tcpip.h>
#include <windows.h>
#endif
+
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
@@ -78,6 +79,7 @@ struct _client {
char app_uuid[128];
int ipv6;
struct sockaddr_storage from; // IPV6 ou IPV4
+ socklen_t from_len;
SocketInterpretation interpretation;
void (*handle_delete)(Client client, const void *data);
void (*handle_decongestion)(Client client, const void *data);
@@ -154,7 +156,7 @@ static void HandleSocket (Channel channel, HANDLE fd, void *data)
long nb_to_read = 0;
long nb;
long nb_occuped;
- socklen_t len;
+ long len;
/* limitation taille buffer */
nb_occuped = client->ptr - client->buffer;
@@ -171,8 +173,8 @@ static void HandleSocket (Channel channel, HANDLE fd, void *data)
nb_to_read = client->buffer_size - nb_occuped;
client->ptr = client->buffer + nb_occuped;
}
- len = sizeof (client->from );
- nb = recvfrom (fd, client->ptr, nb_to_read, 0, (struct sockaddr*)&client->from, &len);
+ client->from_len = sizeof (client->from );
+ nb = recvfrom (fd, client->ptr, nb_to_read, 0, (struct sockaddr*)&(client->from), &(client->from_len));
if (nb < 0) {
perror(" Read Socket ");
IvyChannelRemove (client->channel );
@@ -257,6 +259,7 @@ static void HandleServer(Channel channel, HANDLE fd, void *data)
client->terminator = '\n';
client->ipv6 = server->ipv6;
client->from = remote;
+ client->from_len = addrlen;
client->fd = ns;
client->ifb = NULL;
strcpy (client->app_uuid, "init by HandleServer");
@@ -486,8 +489,14 @@ void SocketGetRemoteHost (Client client, char **hostptr, unsigned short *port )
if (!client)
return;
-
- err = getnameinfo((struct sockaddr*)&client->from, sizeof(client->from), host, sizeof( host), serv, sizeof( serv ), NI_NOFQDN );
+ if( client->from_len == 0 )
+ {
+ fprintf(stderr, "SocketGetRemoteHost :: getnameinfo bad Addr Len\n" );
+ *hostptr = "unknown";
+ *port = 0;
+ return;
+ }
+ err = getnameinfo((struct sockaddr*)&client->from, client->from_len, host, sizeof( host), serv, sizeof( serv ), NI_NOFQDN );
if (err != 0 )
@@ -504,7 +513,7 @@ void SocketGetRemoteHost (Client client, char **hostptr, unsigned short *port )
}
}
#else
- fprintf(stderr, "SocketGetRemoteHost :: getnameinfo %s\n", hstrerror( err ) );
+ fprintf(stderr, "SocketGetRemoteHost :: getnameinfo (%d) %s\n", err, hstrerror( err ) );
#endif
*hostptr = "unknown";
}