bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] use getaddrinfo from gnulib?


From: Simon Josefsson
Subject: [bug-inetutils] use getaddrinfo from gnulib?
Date: Wed, 13 Jan 2010 10:59:24 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1 (gnu/linux)

This actually _reduces_ code, yay.  Thoughts?  Not well tested yet, but
asking first if there are general objections or comments.

There is plenty more places where we can use gnulib modules in
inetutils, but aspects like getaddrinfo are more important than some
others because typically there are IPv4 assumptions in non-getaddrinfo
code.

/Simon

diff --git a/ChangeLog b/ChangeLog
index 0455c1d..bba3738 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-01-12  Simon Josefsson  <address@hidden>
+
+       * whois/whois.c (openconn) [!HAVE_GETADDRINFO]: Remove variables
+       hostinfo, servinfo, and saddr and supporting code.
+       * src/inetd.c (servtab): Remove !HAVE_GETADDRINFO support.
+       (setup) [!HAVE_GETADDRINFO]: Remove.
+       (expand_enter) [!HAVE_GETADDRINFO]: Remove.
+       * configure.ac: Remove HAVE_GETADDRINFO variable.  Don't check for
+       getaddrinfo.
+       * bootstrap.conf (gnulib_modules): Add getaddrinfo.
+
 2010-01-13  Simon Josefsson  <address@hidden>
 
        * TODO: Update.
diff --git a/bootstrap.conf b/bootstrap.conf
index fca66cd..5483dbe 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -34,6 +34,7 @@ exitfail
 extensions
 fdl-1.3
 filemode
+getaddrinfo
 getcwd
 getline
 getopt-gnu
diff --git a/configure.ac b/configure.ac
index cfb8ef1..d234487 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,12 +329,6 @@ if test ! "X$ipv6" = "Xno" -a "X$working_ipv6" = "Xyes"; 
then
   AC_CHECK_TYPE(struct addrinfo, , working_ipv6=no, [#include <netdb.h>])
 fi
 
-AH_TEMPLATE([HAVE_GETADDRINFO],[Define to 1 if you have getaddrinfo(3)])
-AC_CHECK_FUNC(getaddrinfo,
-              [AC_DEFINE([HAVE_GETADDRINFO],1)],
-             [working_ipv6=no
-              AC_DEFINE([HAVE_GETADDRINFO],0)], [#include <netdb.h>])
-
 if test ! "X$ipv6" = "Xno" -a "X$working_ipv6" = "Xyes"; then
   AC_CHECK_FUNC(getnameinfo, ,working_ipv6=no, [#include <netdb.h>])
 fi
diff --git a/src/inetd.c b/src/inetd.c
index 72e232f..aa98a2c 100644
--- a/src/inetd.c
+++ b/src/inetd.c
@@ -267,11 +267,7 @@ struct servtab
   int se_type;                 /* type */
   sa_family_t se_family;       /* address family of the socket */
   char se_v4mapped;            /* 1 = accept v4mapped connection, 0 = don't */
-#if HAVE_GETADDRINFO
   struct sockaddr_storage se_ctrladdr; /* bound address */
-#else
-  struct sockaddr_in se_ctrladdr;      /* bound address */
-#endif
   unsigned se_refcnt;
   int se_count;                        /* number started since se_time */
   struct timeval se_time;      /* start of se_count */
@@ -550,7 +546,6 @@ print_service (const char *action, struct servtab *sep)
 
 
 /* Configuration */
-#if HAVE_GETADDRINFO
 int
 setup (struct servtab *sep)
 {
@@ -631,56 +626,6 @@ setup (struct servtab *sep)
     }
   return 0;
 }
-#else
-void
-setup (struct servtab *sep)
-{
-  int err;
-  const int on = 1;
-
-  sep->se_fd = socket (sep->se_family, sep->se_socktype, 0);
-  if (sep->se_fd < 0)
-    {
-      if (debug)
-       fprintf (stderr, "socket failed on %s/%s: %s\n",
-                sep->se_service, sep->se_proto, strerror (errno));
-      syslog (LOG_ERR, "%s/%s: socket: %m", sep->se_service, sep->se_proto);
-      return 1;
-    }
-
-  if (strncmp (sep->se_proto, "tcp", 3) == 0 && (options & SO_DEBUG))
-    {
-      err = setsockopt (sep->se_fd, SOL_SOCKET, SO_DEBUG,
-                       (char *) &on, sizeof (on));
-      if (err < 0)
-       syslog (LOG_ERR, "setsockopt (SO_DEBUG): %m");
-    }
-
-  err = setsockopt (sep->se_fd, SOL_SOCKET, SO_REUSEADDR,
-                   (char *) &on, sizeof (on));
-  if (err < 0)
-    syslog (LOG_ERR, "setsockopt (SO_REUSEADDR): %m");
-
-  err = bind (sep->se_fd, (struct sockaddr *) &sep->se_ctrladdr,
-             sizeof (sep->se_ctrladdr));
-  if (err < 0)
-    {
-      if (debug)
-       fprintf (stderr, "bind failed on %s/%s: %s\n",
-                sep->se_service, sep->se_proto, strerror (errno));
-      syslog (LOG_ERR, "%s/%s: bind: %m", sep->se_service, sep->se_proto);
-      close (sep->se_fd);
-      sep->se_fd = -1;
-      if (!timingout)
-       {
-         timingout = 1;
-         alarm (RETRYTIME);
-       }
-      return 1;
-    }
-  return 0;
-}
-#endif
 
 void
 servent_setup (struct servtab *sep)
@@ -802,7 +747,6 @@ enter (struct servtab *cp)
   return sep;
 }
 
-#if HAVE_GETADDRINFO
 int
 inetd_getaddrinfo (struct servtab *sep, int proto, struct addrinfo **result)
 {
@@ -879,67 +823,6 @@ expand_enter (struct servtab *sep)
 
   return 0;
 }
-#else
-int
-expand_enter (struct servtab *sep)
-{
-  struct servent *sp;
-
-  sp = getservbyname (sep->se_service, sep->se_proto);
-  if (sp == 0)
-    {
-      static struct servent servent;
-      char *p;
-      unsigned long val;
-      unsigned short port;
-
-      val = strtoul (sep->se_service, &p, 0);
-      if (*p || (port = val) != val)
-       {
-         syslog (LOG_ERR, "%s/%s: unknown service",
-                 sep->se_service, sep->se_proto);
-         sep->se_checked = 0;
-         return 1;
-       }
-      servent.s_port = htons (port);
-      sp = &servent;
-    }
-  if (sp->s_port != sep->se_ctrladdr.sin_port)
-    {
-      sep->se_ctrladdr.sin_family = AF_INET;
-      sep->se_ctrladdr.sin_port = sp->s_port;
-    }
-  if (sep->se_node == NULL)
-    {
-      cp = enter (sep);
-      servent_setup (cp);
-    }
-  else
-    {
-      char    **p;
-      struct hostent *host = gethostbyname (sep->se_node);
-      if (!host)
-       {
-         syslog (LOG_ERR, "%s/%s: unknown host %s",
-                 sep->se_service, sep->se_proto, sep->se_node);
-         return 1;
-       }
-      if (host->h_addrtype != AF_INET)
-       {
-         syslog (LOG_ERR, "%s/%s: unsupported address family %d",
-                 sep->se_service, sep->se_proto, host->h_addrtype);
-         return 1;
-       }
-      for (p = host->h_addr_list; *p; p++)
-       {
-         memcpy (&sep->se_ctrladdr.sin_addr.s_addr, *p, host->h_length);
-         cp = enter (sep);
-         servent_setup (cp);
-       }
-    }
-  return 0;
-}
-#endif
 
 
 /* Configuration parser */
diff --git a/whois/whois.c b/whois/whois.c
index 9552564..0152d72 100644
--- a/whois/whois.c
+++ b/whois/whois.c
@@ -558,16 +558,9 @@ int
 openconn (const char *server, const char *port)
 {
   int fd;
-#ifdef HAVE_GETADDRINFO
   int i;
   struct addrinfo hints, *res, *ressave;
-#else
-  struct hostent *hostinfo;
-  struct servent *servinfo;
-  struct sockaddr_in saddr;
-#endif
 
-#ifdef HAVE_GETADDRINFO
   memset (&hints, 0, sizeof (struct addrinfo));
   hints.ai_family = AF_UNSPEC;
   hints.ai_socktype = SOCK_STREAM;
@@ -588,27 +581,6 @@ openconn (const char *server, const char *port)
   if (!res)
     err_sys ("connect");
   freeaddrinfo (ressave);
-#else
-  if ((hostinfo = gethostbyname (server)) == NULL)
-    err_quit (_("Host %s not found."), server);
-  if ((fd = socket (PF_INET, SOCK_STREAM, IPPROTO_IP)) < 0)
-    err_sys ("socket");
-  memset (&saddr, 0, sizeof (saddr));
-  saddr.sin_addr = *(struct in_addr *) hostinfo->h_addr;
-  saddr.sin_family = AF_INET;
-  if (!port)
-    {
-      saddr.sin_port = htons (43);
-    }
-  else if ((saddr.sin_port = htons (atoi (port))) == 0)
-    {
-      if ((servinfo = getservbyname (port, "tcp")) == NULL)
-       err_quit (_("%s/tcp: unknown service"), port);
-      saddr.sin_port = servinfo->s_port;
-    }
-  if (connect (fd, &saddr, sizeof (saddr)) < 0)
-    err_sys ("connect");
-#endif
   return (fd);
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]