diff --git a/acinclude.m4 b/acinclude.m4 index 62009432..6492e615 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -243,6 +243,7 @@ AC_DEFUN([ACX_CHECK_INET_ATON], [ LIBS="$save_LIBS" AC_MSG_RESULT($acx_inet_aton_ok) if test x"$acx_inet_aton_ok" = xyes; then + AC_DEFINE(HAVE_INET_ATON,1,[Define if you have the \`inet_aton\' function.]) break; fi INET_ATON_LIBS="" diff --git a/lib/arch/CArchNetworkBSD.cpp b/lib/arch/CArchNetworkBSD.cpp index bfdcf20f..fa7f7ebe 100644 --- a/lib/arch/CArchNetworkBSD.cpp +++ b/lib/arch/CArchNetworkBSD.cpp @@ -51,6 +51,29 @@ static const int s_type[] = { SOCK_STREAM }; +#if !HAVE_INET_ATON +// parse dotted quad addresses. we don't bother with the weird BSD'ism +// of handling octal and hex and partial forms. +static +in_addr_t +inet_aton(const char* cp, struct in_addr* inp) +{ + unsigned int a, b, c, d; + if (sscanf(cp, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) { + return 0; + } + if (a >= 256 || b >= 256 || c >= 256 || d >= 256) { + return 0; + } + unsigned char* incp = (unsigned char*)inp; + incp[0] = (unsigned char)(a & 0xffu); + incp[1] = (unsigned char)(b & 0xffu); + incp[2] = (unsigned char)(c & 0xffu); + incp[3] = (unsigned char)(d & 0xffu); + return inp->s_addr; +} +#endif + // // CArchNetworkBSD //