]> sjero.net Git - wget/commitdiff
[svn] Various IPv6 fixes.
authorhniksic <devnull@localhost>
Fri, 25 Jan 2002 03:34:23 +0000 (19:34 -0800)
committerhniksic <devnull@localhost>
Fri, 25 Jan 2002 03:34:23 +0000 (19:34 -0800)
Submitted in <sxsd6zz2jf7.fsf@florida.arsdigita.de>.

src/ChangeLog
src/connect.c
src/connect.h
src/ftp.h
src/host.c
src/init.c
src/options.h

index 115dba6bd68fd87f1ac1aa0f1d48a0873de37138..e37619fb908d6d76e44669145b8a557468565e82 100644 (file)
@@ -1,3 +1,13 @@
+2002-01-24  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * connect.c (resolve_bind_address): New function.
+       (connect_to_one): Use it.
+       (bindport): Ditto.
+
+       * init.c: Don't resolve bind-address here.
+
+       * host.c (wget_sockaddr_set_address): Would bug out with ADDR == NULL.
+
 2002-01-24  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * host.c (lookup_host): Use sizeof(ip4_address) to calculate the
@@ -8,7 +18,8 @@
 
 2002-01-24  Hrvoje Niksic  <hniksic@arsdigita.com>
 
-       * source: Integrated IPv6 support by Thomas Lussnig.
+       * source: Integrated IPv6 support.
+       Written by Thomas Lussnig <thomas.lussnig@bewegungsmelder.de>.
 
 2002-01-15  Ian Abbott  <abbotti@mev.co.uk>
 
index 43ed0083512c06364365116c89dc968ea9b2e3ab..110f5cef6e53565249c37ce62c98806fb143fecc 100644 (file)
@@ -1,5 +1,5 @@
 /* Establishing and handling network connections.
-   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
 
@@ -48,8 +48,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #endif /* HAVE_SYS_SELECT_H */
 
 #include "wget.h"
-#include "connect.h"
 #include "host.h"
+#include "connect.h"
 
 #ifndef errno
 extern int errno;
@@ -59,6 +59,32 @@ extern int errno;
 static int msock = -1;
 static struct sockaddr *addr;
 
+static ip_address bind_address;
+static int bind_address_resolved;
+
+static void
+resolve_bind_address (void)
+{
+  struct address_list *al;
+
+  if (bind_address_resolved || opt.bind_address == NULL)
+    /* Nothing to do. */
+    return;
+
+  al = lookup_host (opt.bind_address, 1);
+  if (!al)
+    {
+      logprintf (LOG_NOTQUIET,
+                _("Unable to convert `%s' to a bind address.  Reverting to ANY.\n"),
+                opt.bind_address);
+      return;
+    }
+
+  address_list_copy_one (al, 0, &bind_address);
+  address_list_release (al);
+  bind_address_resolved = 1;
+}
+
 /* A kludge, but still better than passing the host name all the way
    to connect_to_one.  */
 static const char *connection_host_name;
@@ -101,10 +127,13 @@ connect_to_one (ip_address *addr, unsigned short port, int silent)
   if (sock < 0)
     goto out;
 
-  if (opt.bind_address)
+  resolve_bind_address ();
+  if (bind_address_resolved)
     {
       /* Bind the client side to the requested address. */
-      if (bind (sock, (struct sockaddr *)opt.bind_address, sockaddr_len ()))
+      wget_sockaddr bsa;
+      wget_sockaddr_set_address (&bsa, ip_default_family, 0, &bind_address);
+      if (bind (sock, &bsa.sa, sockaddr_len ()))
        {
          close (sock);
          sock = -1;
@@ -218,11 +247,9 @@ bindport (unsigned short *port, int family)
                  (char *)&optval, sizeof (optval)) < 0)
     return CONSOCKERR;
 
-  if (opt.bind_address == NULL)
-    wget_sockaddr_set_address (&srv, ip_default_family, htons (*port), NULL);
-  else
-    srv = *opt.bind_address;
-  wget_sockaddr_set_port (&srv, *port);
+  resolve_bind_address ();
+  wget_sockaddr_set_address (&srv, ip_default_family, htons (*port),
+                            bind_address_resolved ? &bind_address : NULL);
   if (bind (msock, &srv.sa, sockaddr_len ()) < 0)
     {
       CLOSE (msock);
index 4b637ea0e5a18738bab71ec205838402afede2d7..67bc05b5454a7d45b59af8cd396b15df3ae653c6 100644 (file)
@@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #ifndef CONNECT_H
 #define CONNECT_H
 
-struct address_list;
+#include "host.h"
 
 /* Function declarations */
 
index 0da39a36ec6a5c03ea3c1565bbf0677eb0aa50da..7e17f29ca69fb1936402c524d3a4d8bf33db9fa5 100644 (file)
--- a/src/ftp.h
+++ b/src/ftp.h
@@ -23,6 +23,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Need it for struct rbuf.  */
 #include "rbuf.h"
 
+#include "host.h"
+
 /* System types. */
 enum stype
 {
index df9655fe015b9e9e3e12b9dc29c326b5a6373b88..23685f96d7b170818c93abd4b870db4c1950d6f0 100644 (file)
@@ -101,7 +101,7 @@ address_list_get_bounds (struct address_list *al, int *start, int *end)
 void
 address_list_copy_one (struct address_list *al, int index, ip_address *ip_store)
 {
-  assert (index >= al->faulty && index < al->count && ip_store!=NULL );
+  assert (index >= al->faulty && index < al->count);
   memcpy (ip_store, al->addresses + index, sizeof (ip_address));
 }
 
@@ -267,16 +267,18 @@ wget_sockaddr_set_address (wget_sockaddr *sa,
 {
   if (ip_family == AF_INET) 
     {
-      ip4_address addr4;
-      if (!map_ip_to_ipv4 (addr, &addr4))
-       /* should the callers have prevented this? */
-       abort ();
       sa->sin.sin_family = ip_family;
       sa->sin.sin_port = htons (port);
       if (addr == NULL) 
        memset (&sa->sin.sin_addr, 0,      sizeof(ip4_address));
-      else      
-       memcpy (&sa->sin.sin_addr, &addr4, sizeof(ip4_address));
+      else
+       {
+         ip4_address addr4;
+         if (!map_ip_to_ipv4 (addr, &addr4))
+           /* should the callers have prevented this? */
+           abort ();
+         memcpy (&sa->sin.sin_addr, &addr4, sizeof(ip4_address));
+       }
       return;
     }
 #ifdef INET6
index 20bbc6a29ccb06f8de6e00210ecdc508eec7daab..14b5c4b74de9a3fe538dfc93b8b30e044c833fc7 100644 (file)
@@ -70,7 +70,6 @@ static int enable_tilde_expansion;
 #define CMD_DECLARE(func) static int func \
   PARAMS ((const char *, const char *, void *))
 
-CMD_DECLARE (cmd_address);
 CMD_DECLARE (cmd_boolean);
 CMD_DECLARE (cmd_bytes);
 CMD_DECLARE (cmd_directory_vector);
@@ -108,7 +107,7 @@ static struct {
   { "backupconverted", &opt.backup_converted,  cmd_boolean },
   { "backups",         &opt.backups,           cmd_number },
   { "base",            &opt.base_href,         cmd_string },
-  { "bindaddress",     &opt.bind_address,      cmd_address },
+  { "bindaddress",     &opt.bind_address,      cmd_string },
   { "cache",           &opt.allow_cache,       cmd_boolean },
   { "continue",                &opt.always_rest,       cmd_boolean },
   { "convertlinks",    &opt.convert_links,     cmd_boolean },
@@ -513,45 +512,6 @@ setval (const char *com, const char *val)
 
 static int myatoi PARAMS ((const char *s));
 
-/* Interpret VAL as an Internet address (a hostname or a dotted-quad
-   IP address), and write it (in network order) to a malloc-allocated
-   address.  That address gets stored to the memory pointed to by
-   CLOSURE.  COM is ignored, except for error messages.
-
-   #### IMHO it's a mistake to do this kind of work so early in the
-   process (before any download even started!)  opt.bind_address
-   should simply remember the provided value as a string.  Another
-   function should do the lookup, when needed, and cache the
-   result.  --hniksic  */
-static int
-cmd_address (const char *com, const char *val, void *closure)
-{
-  struct address_list *al;
-  wget_sockaddr sa;
-  wget_sockaddr **target = (wget_sockaddr **)closure;
-
-  memset (&sa, '\0', sizeof (sa));
-
-  al = lookup_host (val, 1);
-  if (!al)
-    {
-      fprintf (stderr, _("%s: %s: Cannot convert `%s' to an IP address.\n"),
-              exec_name, com, val);
-      return 0;
-    }
-  sa.sa.sa_family = ip_default_family;
-  wget_sockaddr_set_port (&sa, 0);
-  address_list_copy_one (al, 0, wget_sockaddr_get_addr (&sa));
-  address_list_release (al);
-
-  FREE_MAYBE (*target);
-
-  *target = xmalloc (sizeof (sa));
-  memcpy (*target, &sa, sizeof (sa));
-
-  return 1;
-}
-
 /* Store the boolean value from VAL to CLOSURE.  COM is ignored,
    except for error messages.  */
 static int
index a07c641e96b57b72b9b4fe35e968b80ac82ee593..d330021868fcea7f99c962622292ce1411aec594 100644 (file)
@@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 /* Needed for FDP.  */
 #include <stdio.h>
-#include "host.h"
 
 struct options
 {
@@ -153,7 +152,7 @@ struct options
 
   int page_requisites;         /* Whether we need to download all files
                                   necessary to display a page properly. */
-  wget_sockaddr *bind_address;  /* What local IP address to bind to. */
+  char *bind_address;          /* What local IP address to bind to. */
 #ifdef HAVE_SSL
   char *sslcertfile;           /* external client cert to use. */
   char *sslcertkey;            /* the keyfile for this certificate