Bug#27427: resolveip fails on hostnames with a leading digit

Patch by Kasper Dupont.  No CLA required for this size of patch.

"resolveip" program produces incorrect result if given a hostname
starting with a digit.  Someone seems to have thought that names 
can not have digits at the beginning.

Instead, use the resolver library to work out the rules of hostnames, 
as it will undoubtedly be better at it than we are.
parent 9777809b
...@@ -838,6 +838,8 @@ AC_CHECK_FUNC(p2open, , AC_CHECK_LIB(gen, p2open)) ...@@ -838,6 +838,8 @@ AC_CHECK_FUNC(p2open, , AC_CHECK_LIB(gen, p2open))
AC_CHECK_FUNC(bind, , AC_CHECK_LIB(bind, bind)) AC_CHECK_FUNC(bind, , AC_CHECK_LIB(bind, bind))
# Check if crypt() exists in libc or libcrypt, sets LIBS if needed # Check if crypt() exists in libc or libcrypt, sets LIBS if needed
AC_SEARCH_LIBS(crypt, crypt, AC_DEFINE(HAVE_CRYPT, 1, [crypt])) AC_SEARCH_LIBS(crypt, crypt, AC_DEFINE(HAVE_CRYPT, 1, [crypt]))
# See if we need a library for address lookup.
AC_SEARCH_LIBS(inet_aton, [socket nsl resolv])
# For the sched_yield() function on Solaris # For the sched_yield() function on Solaris
AC_CHECK_FUNC(sched_yield, , AC_CHECK_LIB(posix4, sched_yield)) AC_CHECK_FUNC(sched_yield, , AC_CHECK_LIB(posix4, sched_yield))
......
...@@ -116,11 +116,13 @@ int main(int argc, char **argv) ...@@ -116,11 +116,13 @@ int main(int argc, char **argv)
while (argc--) while (argc--)
{ {
struct in_addr addr;
ip = *argv++; ip = *argv++;
if (my_isdigit(&my_charset_latin1,ip[0])) /* Not compatible with IPv6! Probably should use getnameinfo(). */
if (inet_aton(ip, &addr) != 0)
{ {
taddr = inet_addr(ip); taddr= addr.s_addr;
if (taddr == htonl(INADDR_BROADCAST)) if (taddr == htonl(INADDR_BROADCAST))
{ {
puts("Broadcast"); puts("Broadcast");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment