]> sjero.net Git - wget/blobdiff - src/init.c
[svn] Manually applied Rob Mayoff <mayoff@dqd.com>'s patch (vs. 1.5.3, not 1.5.3...
[wget] / src / init.c
index b1169b23d8fd8ecce1b6daa0adbac15e00680de3..9e11944551dbd18cc2ead4e2175672627eccea9f 100644 (file)
@@ -33,6 +33,14 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #endif
 #include <errno.h>
 
+#ifdef WINDOWS
+# include <winsock.h>
+#else
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
+
 #ifdef HAVE_PWD_H
 #include <pwd.h>
 #endif
@@ -52,6 +60,7 @@ extern int errno;
 #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);
@@ -87,6 +96,7 @@ static struct {
   { "background",      &opt.background,        cmd_boolean },
   { "backupconverted", &opt.backup_converted,  cmd_boolean },
   { "backups",         &opt.backups,           cmd_number },
+  { "bindaddress",     &opt.bind_address,      cmd_address },
   { "base",            &opt.base_href,         cmd_string },
   { "cache",           &opt.proxy_cache,       cmd_boolean },
   { "continue",                &opt.always_rest,       cmd_boolean },
@@ -475,6 +485,35 @@ setval (const char *com, const char *val)
 
 static int myatoi PARAMS ((const char *s));
 
+/* Store the address (specified as hostname or dotted-quad IP address) from VAL
+   to CLOSURE.  COM is ignored, except for error messages.  */
+static int
+cmd_address (const char *com, const char *val, void *closure)
+{
+    struct sockaddr_in *sin;
+    
+    sin = (struct sockaddr_in *) malloc(sizeof *sin);
+    if (sin == NULL)
+    {
+       fprintf (stderr, _("%s: Out of memory.\n"), exec_name);
+       return 0;
+    }
+    
+    if (!store_hostaddress ((unsigned char *)&sin->sin_addr, val))
+    {
+       fprintf (stderr, _("%s: %s: Cannot convert `%s' to an IP address.\n"),
+                exec_name, com, val);
+       return 0;
+    }
+    
+    sin->sin_family = AF_INET;
+    sin->sin_port = 0;
+    
+    * (struct sockaddr_in **) closure = sin;
+    
+    return 1;
+}
+
 /* Store the boolean value from VAL to CLOSURE.  COM is ignored,
    except for error messages.  */
 static int