- 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));
+ /* 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));
+
+ /* Reverse */
+ if (!silc_net_gethostbyname(*hostname, TRUE, host, sizeof(host)))
+ return FALSE;
+
+ if (strcmp(*ip, host))
+ return FALSE;
+ }