Watt-32 tcp/ip  2.2 dev-rel.10
lookup.c
Go to the documentation of this file.
1 
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 
35 #include "wattcp.h"
36 #include "strings.h"
37 #include "language.h"
38 #include "netaddr.h"
39 #include "misc.h"
40 #include "pcdns.h"
41 #include "ip4_in.h"
42 #include "pcdbug.h"
43 #include "pctcp.h"
44 
45 DWORD W32_CALL lookup_host (const char *host, char *ip_str)
46 {
47  DWORD ip;
48 
49  WATT_ASSERT (host);
50 
51  if (isaddr(host))
52  ip = aton (host);
53  else
54  {
55  outs (_LANG("Resolving "));
56  outs (host);
57  outs ("...");
58  ip = resolve (host);
59  if (ip)
60  {
61  if (dom_cname[0] && debug_on >= 1)
62  {
63  outs ("CNAME ");
64  outs (dom_cname);
65  outs (" ");
66  }
67  outsnl (_inet_ntoa(NULL,ip));
68  }
69  }
70 
71  if (!_ip4_is_loopback_addr(ip) && _ip4_is_multihome_addr(ip))
72  {
73 #if defined(USE_DEBUG)
74  (*_printf) ("Cannot connect to ourself\n");
75 #endif
76  return (0);
77  }
78 
79  if (ip_str)
80  _inet_ntoa (ip_str, ip);
81  return (ip);
82 }
DWORD W32_CALL aton(const char *str)
Converts [a.b.c.d] or a.b.c.d to 32 bit IPv4 address.
Definition: netaddr.c:86
Core definitions.
Definition: ip.h:67
BOOL W32_CALL isaddr(const char *str)
Check if 'str' is simply an ip address.
Definition: netaddr.c:128
char *W32_CALL _inet_ntoa(char *s, DWORD ip)
Convert an IP-address 'ip' into a string.
Definition: netaddr.c:43
DWORD W32_CALL resolve(const char *name)
Convert host name to an address.
Definition: pcdns.c:775