39 |
int resolve_hostnames = 1; |
int resolve_hostnames = 1; |
40 |
|
|
41 |
/* |
/* |
42 |
|
* Check for valid IP address in standard dot notation. |
43 |
|
*/ |
44 |
|
static int |
45 |
|
good_ipaddr(const char *addr) |
46 |
|
{ |
47 |
|
int dot_count; |
48 |
|
int digit_count; |
49 |
|
|
50 |
|
dot_count = 0; |
51 |
|
digit_count = 0; |
52 |
|
while (*addr != 0 && *addr != ' ') { |
53 |
|
if (*addr == '.') { |
54 |
|
if (++dot_count > 3) |
55 |
|
break; |
56 |
|
digit_count = 0; |
57 |
|
} else if (!(isdigit(*addr) && ++digit_count <= 3)) { |
58 |
|
return -1; |
59 |
|
} |
60 |
|
addr++; |
61 |
|
} |
62 |
|
|
63 |
|
return (dot_count != 3); |
64 |
|
} |
65 |
|
|
66 |
|
/* |
67 |
* Return a printable host name (or IP address in dot notation) |
* Return a printable host name (or IP address in dot notation) |
68 |
* for the supplied IP address. |
* for the supplied IP address. |
69 |
*/ |
*/ |
97 |
* name or address in dot notation. |
* name or address in dot notation. |
98 |
*/ |
*/ |
99 |
UINT4 |
UINT4 |
100 |
ip_gethostaddr(char *host) |
ip_gethostaddr(const char *host) |
101 |
{ |
{ |
102 |
struct hostent *hp, hent; |
struct hostent *hp, hent; |
103 |
char buffer[512]; |
char buffer[512]; |
113 |
} |
} |
114 |
|
|
115 |
/* |
/* |
|
* Check for valid IP address in standard dot notation. |
|
|
*/ |
|
|
int |
|
|
good_ipaddr(char *addr) |
|
|
{ |
|
|
int dot_count; |
|
|
int digit_count; |
|
|
|
|
|
dot_count = 0; |
|
|
digit_count = 0; |
|
|
while (*addr != 0 && *addr != ' ') { |
|
|
if (*addr == '.') { |
|
|
if (++dot_count > 3) |
|
|
break; |
|
|
digit_count = 0; |
|
|
} else if (!(isdigit(*addr) && ++digit_count <= 3)) { |
|
|
return -1; |
|
|
} |
|
|
addr++; |
|
|
} |
|
|
|
|
|
return (dot_count != 3); |
|
|
} |
|
|
|
|
|
/* |
|
116 |
* Return an IP address in standard dot notation for the |
* Return an IP address in standard dot notation for the |
117 |
* provided address in host long notation. |
* provided address in host long notation. |
118 |
*/ |
*/ |
132 |
* one supplied in standard dot notation. |
* one supplied in standard dot notation. |
133 |
*/ |
*/ |
134 |
UINT4 |
UINT4 |
135 |
ip_strtoip(char *ip_str) |
ip_strtoip(const char *ip_str) |
136 |
#ifdef HAVE_INET_ATON |
#ifdef HAVE_INET_ATON |
137 |
{ |
{ |
138 |
struct in_addr in; |
struct in_addr in; |
178 |
#endif |
#endif |
179 |
|
|
180 |
int |
int |
181 |
ip_getnetaddr(char *str, NETDEF *netdef) |
ip_getnetaddr(const char *str, NETDEF *netdef) |
182 |
{ |
{ |
183 |
char *p = strchr(str, '/'); |
char *p = strchr(str, '/'); |
184 |
if (!p) { |
if (!p) { |
212 |
} |
} |
213 |
|
|
214 |
int |
int |
215 |
ip_addr_in_net_p(NETDEF *netdef, UINT4 ipaddr) |
ip_addr_in_net_p(const NETDEF *netdef, UINT4 ipaddr) |
216 |
{ |
{ |
217 |
return netdef->ipaddr == (ipaddr & netdef->netmask); |
return netdef->ipaddr == (ipaddr & netdef->netmask); |
218 |
} |
} |