Index: config.h.in ================================================================== --- config.h.in +++ config.h.in @@ -21,10 +21,16 @@ /* Define to 1 if you have fopen_net from libopennet */ #undef HAVE_LIBOPENNET /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETDB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IN_H /* Define to 1 if you have the header file. */ #undef HAVE_OPENNET_H /* Define to 1 if you have the header file. */ Index: configure ================================================================== --- configure +++ configure @@ -16646,11 +16646,13 @@ -for ac_header in ctype.h dirent.h pwd.h stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h time.h unistd.h + + +for ac_header in ctype.h dirent.h pwd.h stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h time.h unistd.h netdb.h netinet/in.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then echo "$as_me:$LINENO: checking for $ac_header" >&5 echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 @@ -16794,10 +16796,11 @@ _ACEOF fi done + echo "$as_me:$LINENO: checking whether time.h and sys/time.h may both be included" >&5 echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6 if test "${ac_cv_header_time+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -32,11 +32,12 @@ dnl changed later (by AC_REPLACE_FUNCS, for example) you must call dnl DC_SYNC_SHLIBOBJS again. DC_GET_SHOBJFLAGS dnl This stuff has to come after the shobjtest to verify that it is correct -AC_CHECK_HEADERS(ctype.h dirent.h pwd.h stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h time.h unistd.h) +AC_CHECK_HEADERS(ctype.h dirent.h pwd.h stdio.h stdlib.h string.h sys/stat.h sys/time.h sys/types.h time.h unistd.h netdb.h netinet/in.h) + AC_HEADER_TIME AC_REPLACE_FUNCS(strsep strtoll getuid) AC_CHECK_FUNCS(getpwuid) Index: libconfig.c ================================================================== --- libconfig.c +++ libconfig.c @@ -33,10 +33,14 @@ #endif #ifdef HAVE_PWD_H #include #endif + +#ifdef HAVE_NETDB_H +#include +#endif struct lc_varhandler_st *varhandlers = NULL; lc_err_t lc_errno = LC_ERR_NONE; const char *lc_err_usererrmsg = NULL; const char *lc_errfile = NULL; @@ -58,60 +62,116 @@ static int lc_process_var_cidr(void *data, const char *value, const char **endptr) { return(-1); } -static int lc_process_var_addr4(uint32_t *data, const char *value, const char **endptr) { - return(-1); -} - -static int lc_process_var_addr6(void *data, const char *value, const char **endptr) { - return(-1); -} - static int lc_process_var_hostname4(uint32_t *data, const char *value, const char **endptr) { - return(-1); + struct hostent *ghbn_ret; + + ghbn_ret = gethostbyname(value); + if (ghbn_ret == NULL) { + return(-1); + } + + if (ghbn_ret->h_length != 4) { + return(-1); + } + + memcpy(data, ghbn_ret->h_addr_list[0], sizeof(*data)); + + *data = ntohl(*data); + + return(0); } static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) { return(-1); } + +static int lc_process_var_ip4(uint32_t *data, const char *value, const char **endptr) { + uint32_t ipval = 0, curr_ipval = 0; + const char *valptr; + int retval = 0; + int dotcount = 0; + + for (valptr = value; *valptr; valptr++) { + if (!isdigit(*valptr)) { + if (*valptr == '.' || *valptr == ',') { + dotcount++; + if (dotcount >= 4) { + retval = -1; + break; + } + + if (curr_ipval > 255) { + retval = -1; + break; + } + + ipval <<= 8; + ipval |= curr_ipval; + curr_ipval = 0; + + /* For lists */ + if (*valptr == ',') { + break; + } + + continue; + } else { + retval = -1; + break; + } + } + + curr_ipval *= 10; + curr_ipval += *valptr - '0'; + } + + if (retval == 0) { + ipval <<= 8; + ipval |= curr_ipval; + + *data = ipval; + } + + return(retval); +} static int lc_process_var_ip6(void *data, const char *value, const char **endptr) { return(-1); } -static int lc_process_var_ip4(uint32_t *data, const char *value, const char **endptr) { - const char *dotptr = NULL; - int tmpval = -1, retval = 0; - - dotptr = value; - - while (1) { - tmpval = atoi(dotptr); - if (tmpval < 0) { - break; - } - - retval <<= 8; - retval |= tmpval; - - dotptr = strpbrk(dotptr, "./ \t"); - if (dotptr == NULL) { - break; - } - if (*dotptr != '.') { - break; - } - dotptr++; - } - - *data = retval; - - *endptr = (char *) dotptr; - - return(0); +static int lc_process_var_addr4(uint32_t *data, const char *value, const char **endptr) { + int lc_pv_ret; + + lc_pv_ret = lc_process_var_ip4(data, value, endptr); + if (lc_pv_ret == 0) { + return(lc_pv_ret); + } + + lc_pv_ret = lc_process_var_hostname4(data, value, endptr); + if (lc_pv_ret == 0) { + return(lc_pv_ret); + } + + return(-1); +} + +static int lc_process_var_addr6(void *data, const char *value, const char **endptr) { + int lc_pv_ret; + + lc_pv_ret = lc_process_var_ip6(data, value, endptr); + if (lc_pv_ret == 0) { + return(lc_pv_ret); + } + + lc_pv_ret = lc_process_var_hostname6(data, value, endptr); + if (lc_pv_ret == 0) { + return(lc_pv_ret); + } + return(-1); } static int lc_process_var_longlong(long long *data, const char *value, const char **endptr) { *data = strtoll(value, (char **) endptr, 10);