From b06a1fa3af9c3025f95fa59f26c1b29a5df8ced1 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 10 Apr 2001 11:39:38 +0000 Subject: [PATCH] updates. --- CHANGES | 5 +++++ apps/silcd/server.c | 20 ++++++++++++-------- lib/silcutil/silcnet.c | 24 +++++++++++++++--------- lib/silcutil/silcnet.h | 2 +- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index 3932d767..0bc13386 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,11 @@ Tue Apr 10 16:20:34 EEST 2001 Pekka Riikonen * Do not send re-key packets immediately but through packet queue. Affected file silcd/protocol.c and lib/silcclient/protocol.c. + * Changed silc_net_check_host_by_sock to return FALSE if the + IP/DNS could not be resolved. Though, it returns the IP address + now even if it could not resolve it (but returns also FALSE). + Affected file lib/silcutil/silcnet.[ch]. + Mon Apr 9 21:54:44 EEST 2001 Pekka Riikonen * Added silc_pkcs_decode_identifier to decode the public key's diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 533d46ae..6962409d 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -960,15 +960,19 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection) process. Either we have to do our own resolver stuff or in the future we can use threads. */ /* Perform name and address lookups for the remote host. */ - silc_net_check_host_by_sock(sock, &newsocket->hostname, &newsocket->ip); - if ((server->params->require_reverse_mapping && !newsocket->hostname) || - !newsocket->ip) { - SILC_LOG_ERROR(("IP/DNS lookup failed")); - server->stat.conn_failures++; - return; + if (!silc_net_check_host_by_sock(sock, &newsocket->hostname, + &newsocket->ip)) { + if ((server->params->require_reverse_mapping && !newsocket->hostname) || + !newsocket->ip) { + SILC_LOG_ERROR(("IP/DNS lookup failed %s", + newsocket->hostname ? newsocket->hostname : + newsocket->ip ? newsocket->ip : "")); + server->stat.conn_failures++; + return; + } + if (!newsocket->hostname) + newsocket->hostname = strdup(newsocket->ip); } - if (!newsocket->hostname) - newsocket->hostname = strdup(newsocket->ip); newsocket->port = silc_net_get_remote_port(sock); SILC_LOG_INFO(("Incoming connection from %s (%s)", newsocket->hostname, diff --git a/lib/silcutil/silcnet.c b/lib/silcutil/silcnet.c index cc09a130..71fd0667 100644 --- a/lib/silcutil/silcnet.c +++ b/lib/silcutil/silcnet.c @@ -237,7 +237,7 @@ int silc_net_is_ip(const char *addr) /* Performs lookups for remote name and IP address. This peforms reverse lookup as well to verify that the IP has FQDN. */ -void silc_net_check_host_by_sock(int sock, char **hostname, char **ip) +bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip) { struct sockaddr_in remote; struct hostent *dest; @@ -255,13 +255,20 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip) len = sizeof(remote); rval = getpeername(sock, (struct sockaddr *)&remote, &len); if (rval < 0) - return; + return FALSE; + + host_ip = inet_ntoa(remote.sin_addr); + if (!host_ip) + return FALSE; + + *ip = silc_calloc(strlen(host_ip) + 1, sizeof(char)); + memcpy(*ip, host_ip, strlen(host_ip)); /* Get host by address */ dest = gethostbyaddr((char *)&remote.sin_addr, sizeof(struct in_addr), AF_INET); if (!dest) - return; + return FALSE; /* Get same host by name to see that the remote host really is the who it says it is */ @@ -274,7 +281,7 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip) dest = gethostbyname(host_name); if (!dest) - return; + return FALSE; /* Find the address from list */ for (i = 0; dest->h_addr_list[i]; i++) @@ -282,15 +289,14 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip) sizeof(struct in_addr))) break; if (!dest->h_addr_list[i]) - return; - - host_ip = inet_ntoa(remote.sin_addr); - if (!host_ip) - return; + return FALSE; + silc_free(*ip); *ip = silc_calloc(strlen(host_ip) + 1, sizeof(char)); memcpy(*ip, host_ip, strlen(host_ip)); SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip)); + + return TRUE; } /* Return remote port by socket. */ diff --git a/lib/silcutil/silcnet.h b/lib/silcutil/silcnet.h index 3d314405..8445d141 100644 --- a/lib/silcutil/silcnet.h +++ b/lib/silcutil/silcnet.h @@ -31,7 +31,7 @@ int silc_net_accept_connection(int sock); int silc_net_set_socket_nonblock(int sock); int silc_net_set_socket_opt(int sock, int level, int option, int on); int silc_net_is_ip(const char *addr); -void silc_net_check_host_by_sock(int sock, char **hostname, char **ip); +bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip); uint16 silc_net_get_remote_port(int sock); uint16 silc_net_get_local_port(int sock); char *silc_net_localhost(); -- 2.24.0