44 "@(#)util.c 1.5 Copyright 1992 Livingston Enterprises Inc\n"
45 " 2.1 Copyright 1997 Cistron Internet Services B.V.";
55#include <sys/socket.h>
58#include <netinet/in.h>
77 while (*addr !=
'\0' && *addr !=
' ') {
81 }
else if (!isdigit(*addr)) {
85 if (digit_count > 3) {
111 ipaddr = (uint32_t)0;
112 for (i = 0; i < 4; ++i) {
116 while (*ip_str !=
'.' && *ip_str !=
'\0' && count < 4) {
117 if (!isdigit(*ip_str)) {
125 if (count >= 4 || count == 0) {
129 cur_byte = atoi(buf);
130 if (cur_byte < 0 || cur_byte > 255) {
134 ipaddr = ipaddr << 8 | (uint32_t)cur_byte;
149 }
else if ((hp = gethostbyname(host)) == (
struct hostent *)
nullptr) {
152 return(ntohl(*(uint32_t *)hp->h_addr));
static int good_ipaddr(char *addr)
uint32_t get_ipaddr(char *host)
static uint32_t ipstr2long(char *ip_str)