Re: --inet6-only option

2003-11-17 Thread Hrvoje Niksic
Hrvoje Niksic <[EMAIL PROTECTED]> writes:

> * If the machine doesn't support AI_ADDRCONFIG and Wget sets -4
>   behind your back, then you shouldn't be allowed to specify -6
>   because it clearly contradicts with the automagically set -4.
>
>   (But even then you can still use `--no-inet4-only -6', which will
>   make Wget resolve IPv6 addresses only, and fail to connect to any
>   host.

After thinking about this some more, I decided to redo the last part.
The "feature" of being able to undo the implicit `-4' is not that
useful because it's unavailable on machines with AI_ADDRCONFIG, which
we expect to become ubiquitous.  The whole thing degrades into an ugly
and unnecessary special case.

I decided to implement (in part) your suggestion to move the socket
check to lookup_host.  The code now no longer automatically sets
--inet4; instead, it does the following:

* If -4 is specified, request AF_INET family from getaddrinfo.

* If -6 is specified, request AF_INET6 family from getaddrinfo.

* Otherwise, request AF_UNSPEC family with the AI_ADDRCONFIG flag.

  If AI_ADDRCONFIG is not available, simulate it with an explicitly
  check whether an AF_INET6 socket can be created.  If not, simply
  request AF_INET instead of AF_UNSPEC.  And if yes, keep using
  AF_UNSPEC.

This should cause systems without AI_ADDRCONFIG to behave exactly the
same as systems that support it.  (The only exception would be
hypothetical IPv6-only systems that actually cannot create AF_INET
sockets.  If such were to exist, I assume that they will support
AI_ADDRCONFIG.)


Re: --inet6-only option

2003-11-15 Thread Hrvoje Niksic
Hrvoje Niksic <[EMAIL PROTECTED]> writes:

> "Gisle Vanem" <[EMAIL PROTECTED]> writes:
>
>> Running "wget -6 url.." on a machine with no IPv6 installed
>> silently uses IPv4. A warning with fallback to IPv4 is IMHO
>> okay. Or an exit?

I gave this question some more thought.  Here are some conclusions.

* -4 and -6 are host lookup options.  If you specify -6 on an
  IPv4-only host, you get what you asked for -- no addresses will
  resolve.  Tough luck.

* If the machine doesn't support AI_ADDRCONFIG and Wget sets -4 behind
  your back, then you shouldn't be allowed to specify -6 because it
  clearly contradicts with the automagically set -4.

  (But even then you can still use `--no-inet4-only -6', which will
  make Wget resolve IPv6 addresses only, and fail to connect to any
  host.  Again, tough luck.)

* Furthermore, -4 and -6 don't mix in general.  Report an error when
  both are present.  But the error needs to be different when -4 was
  set behind your back from when it was set by the user.

The above sounds complex when stated, but is in fact quite simple
because it explicitly disallows the `-4 -6' which doesn't make sense
anyway, and because it removes the possibility of a "silent fallback
to IPv4" that you observed.

Here is a patch:

2003-11-16  Hrvoje Niksic  <[EMAIL PROTECTED]>

* main.c (main): Don't allow setting of both opt.ipv4_only and
opt.ipv6_only.

* init.c (defaults): Mark opt.ipv4_only specially when set
automatically.

Index: src/init.c
===
RCS file: /pack/anoncvs/wget/src/init.c,v
retrieving revision 1.83
diff -u -r1.83 init.c
--- src/init.c  2003/11/15 01:49:52 1.83
+++ src/init.c  2003/11/16 00:12:27
@@ -321,7 +321,8 @@
   {
 int sock = socket (AF_INET6, SOCK_STREAM, 0);
 if (sock < 0)
-  opt.ipv4_only = 1;
+  opt.ipv4_only = -1;  /* special value -1 because the option
+  was not specified by the user.  */
 else
   close (sock);
   }
Index: src/main.c
===
RCS file: /pack/anoncvs/wget/src/main.c,v
retrieving revision 1.102
diff -u -r1.102 main.c
--- src/main.c  2003/11/15 02:05:21 1.102
+++ src/main.c  2003/11/16 00:12:31
@@ -806,6 +806,18 @@
   print_usage ();
   exit (1);
 }
+  if (opt.ipv4_only && opt.ipv6_only)
+{
+  if (opt.ipv4_only == -1)
+   /* ipv4_only was set automatically because the system doesn't
+  support IPv6.  */
+   printf (_("Cannot use --inet6-only on a system without IPv6 support.\n"));
+  else
+   printf (_("Cannot specify both --inet4-only and --inet6-only.\n"));
+  print_usage ();
+  exit (1);
+}
+
   nurl = argc - optind;
   if (!nurl && !opt.input_filename)
 {



Re: --inet6-only option

2003-11-15 Thread Hrvoje Niksic
"Gisle Vanem" <[EMAIL PROTECTED]> writes:

> Running "wget -6 url.." on a machine with no IPv6 installed silently
> uses IPv4. A warning with fallback to IPv4 is IMHO okay. Or an exit?

If you don't have IPv6 installed, the effect is as if `-4' were
prepended to options.  What should Wget do when `-4 -6' is
encountered?  Currently it works as if neither were present, which is
why you see silent use of IPv4.

There should probably at least be a warning.

> Not sure about the rationale behind '--inet6-only', but the problem
> seems to be in defaults(); when socket() fails, 'opt.ipv4_only=1' is
> forced before the cmd-line is parsed. So lookup_host() uses
> AF_UNSPEC in the hints.
>
> My suggestion is to move the "socket(AF_INET?)" test to host.c and
> call it once from lookup_host().

Putting the check to defaults() allows you to undo it, in case you
just want to look at the resolved addresses (or debug IPv6 or whatever
else).



--inet6-only option

2003-11-15 Thread Gisle Vanem
MingW version compiled with ENABLE_IPV6, HAVE_GETADDRINFO etc.
but no HAVE_GETADDRINFO_AI_ADDRCONFIG.

Running "wget -6 url.." on a machine with no IPv6 installed silently
uses IPv4. A warning with fallback to IPv4 is IMHO okay. Or an exit?

Not sure about the rationale behind '--inet6-only', but the problem seems 
to be in defaults(); when socket() fails, 'opt.ipv4_only=1' is forced before 
the cmd-line is parsed. So lookup_host() uses AF_UNSPEC in the hints.

My suggestion is to move the "socket(AF_INET?)" test to host.c and
call it once from lookup_host(). Take action (exit?) if 'opt.ipv?_only' 
doesn't match returned 'res.ai_family'.

Similarily, on a machine with only IPv6 (it they really exist?),
'--inet4-only' should also fail or give a warning.

Gisle V.

# rm /bin/laden 
/bin/laden: Not found