X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcnet.c;h=a77311cde20b4b2aca836d6fe62a3415d898c040;hb=d1e71f42379e8b5cd0748a7aeae8561b02cfe53d;hp=c25637c08021c4966430656984ec6ece6ea6406f;hpb=05e42fd7b315f9a6e195287c78d93445d25a5c1a;p=silc.git diff --git a/lib/silcutil/silcnet.c b/lib/silcutil/silcnet.c index c25637c0..a77311cd 100644 --- a/lib/silcutil/silcnet.c +++ b/lib/silcutil/silcnet.c @@ -8,8 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -292,7 +291,8 @@ bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip) struct sockaddr_storage remote; char s[NI_MAXHOST]; - *hostname = NULL; + if (hostname) + *hostname = NULL; *ip = NULL; SILC_LOG_DEBUG(("Resolving remote hostname and IP address")); @@ -315,7 +315,8 @@ bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip) struct sockaddr_in remote; char *host_ip; - *hostname = NULL; + if (hostname) + *hostname = NULL; *ip = NULL; SILC_LOG_DEBUG(("Resolving remote hostname and IP address")); @@ -335,19 +336,22 @@ bool silc_net_check_host_by_sock(int sock, char **hostname, char **ip) return FALSE; #endif - /* Get host by address */ - if (!silc_net_gethostbyaddr(*ip, host, sizeof(host))) - return FALSE; + /* Do reverse lookup if we want hostname too. */ + if (hostname) { + /* Get host by address */ + if (!silc_net_gethostbyaddr(*ip, host, sizeof(host))) + return FALSE; - *hostname = silc_memdup(host, strlen(host)); - SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname)); + *hostname = silc_memdup(host, strlen(host)); + SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname)); - /* Reverse */ - if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host))) - return FALSE; + /* Reverse */ + if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host))) + return FALSE; - if (strcmp(*ip, host)) - return FALSE; + if (strcmp(*ip, host)) + return FALSE; + } SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip)); return TRUE; @@ -365,7 +369,8 @@ bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip) struct sockaddr_storage local; char s[NI_MAXHOST]; - *hostname = NULL; + if (hostname) + *hostname = NULL; *ip = NULL; SILC_LOG_DEBUG(("Resolving local hostname and IP address")); @@ -388,7 +393,8 @@ bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip) struct sockaddr_in local; char *host_ip; - *hostname = NULL; + if (hostname) + *hostname = NULL; *ip = NULL; SILC_LOG_DEBUG(("Resolving local hostname and IP address")); @@ -408,19 +414,22 @@ bool silc_net_check_local_by_sock(int sock, char **hostname, char **ip) return FALSE; #endif - /* Get host by address */ - if (!silc_net_gethostbyaddr(*ip, host, sizeof(host))) - return FALSE; + /* Do reverse lookup if we want hostname too. */ + if (hostname) { + /* Get host by address */ + if (!silc_net_gethostbyaddr(*ip, host, sizeof(host))) + return FALSE; - *hostname = silc_memdup(host, strlen(host)); - SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname)); + *hostname = silc_memdup(host, strlen(host)); + SILC_LOG_DEBUG(("Resolved hostname `%s'", *hostname)); - /* Reverse */ - if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host))) - return FALSE; + /* Reverse */ + if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host))) + return FALSE; - if (strcmp(*ip, host)) - return FALSE; + if (strcmp(*ip, host)) + return FALSE; + } SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip)); return TRUE;