Пример #1
0
/* Looks up all ip-addresses of the host, returning them as a
   comma-separated list when calling the callback.  The host name may
   already be an ip address, in which case it is returned directly. This uses
   the system resolver.  */
SshOperationHandle
ssh_tcp_get_host_addrs_by_name_system(const unsigned char *name,
				      SshLookupCallback callback,
				      void *context)
{
  unsigned char *addrs;

  addrs = ssh_tcp_get_host_addrs_by_name_sync(name);
  if (addrs)
    {
      callback(SSH_TCP_OK, addrs, context);
      ssh_free(addrs);
    }
  else
    callback(SSH_TCP_NO_ADDRESS, NULL, context);
  return NULL;
}
Пример #2
0
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;
}