updates.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 10 Apr 2001 11:39:38 +0000 (11:39 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 10 Apr 2001 11:39:38 +0000 (11:39 +0000)
CHANGES
apps/silcd/server.c
lib/silcutil/silcnet.c
lib/silcutil/silcnet.h

diff --git a/CHANGES b/CHANGES
index 3932d767506c5c4e4a1df597c682a3535ceb0225..0bc13386744882574a39dd94196b91d89075d98a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,11 @@ Tue Apr 10 16:20:34 EEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
        * 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 <priikone@poseidon.pspt.fi>
 
        * Added silc_pkcs_decode_identifier to decode the public key's
index 533d46ae615186481bf0d7b0db5ce4e06da60c3d..6962409d84774e37b7a4e484e2105fe4ba5386c6 100644 (file)
@@ -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,
index cc09a130ed00f19a1e7c14b715a5bcbcc35dcd22..71fd0667394add250c398e0461b1172690db5657 100644 (file)
@@ -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. */
index 3d3144057cc65ccb017636cce7d61921a5b84e90..8445d1413138cf1050bdd1e72613d951ef075cf3 100644 (file)
@@ -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();