/* Looks up the name of the host by its ip-address. Verifies that the address returned by the name servers also has the original ip address. Calls the callback with either error or success. The callback should copy the returned name. This uses the system resolver. */ SshOperationHandle ssh_tcp_get_host_by_addr_system(const unsigned char *addr, SshLookupCallback callback, void *context) { unsigned char *name; name = ssh_tcp_get_host_by_addr_sync(addr); if (name) { callback(SSH_TCP_OK, name, context); ssh_free(name); } else callback(SSH_TCP_NO_ADDRESS, NULL, context); return NULL; }
int main(int ac, char **av) { char *addrs, *addr, *name, *oname; if (ac < 2) name = oname = "www.ssh.fi"; else name = oname = av[1]; /* map name to address; then map the address back to the name */ addrs = ssh_tcp_get_host_addrs_by_name_sync(oname); if (addrs) { fprintf(stderr, "++ NAME=%s, ADDRS=%s\n", name, addrs); addr = strtok(addrs, ","); while (addr) { name = ssh_tcp_get_host_by_addr_sync(addr); if (name) { fprintf(stderr, "++ ADDR=%s NAME=%s\n", addr, name); ssh_xfree(name); } else fprintf(stderr, "-- ADDR=%s NAME=none\n", addr); addr = strtok(NULL, ","); } ssh_xfree(addrs); } else fprintf(stderr, "-- NAME=%s, ADDRS=none\n", name); /* do the same using the asyncronous interface */ ssh_tcp_get_host_addrs_by_name(oname, byaddr_cb, oname); return 0; }