php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30057 IPv6 support broken
Submitted: 2004-09-10 22:18 UTC Modified: 2004-09-26 03:18 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: neon at neon-line dot net Assigned:
Status: Closed Package: Sockets related
PHP Version: 5.0.1 OS: FreeBSD 4.10
Private report: No CVE-ID: None
 [2004-09-10 22:18 UTC] neon at neon-line dot net
Description:
------------
Unable to connect to IPv6 addresses or hostnames pointing to an IPv6 address, even though IPv6 is properly configured.
PHP has been configured with --enable-ipv6 option and phpinfo shows that it is indeed enabled.

I checked with telnet utility that these hosts respond and with that they did.

Reproduce code:
---------------
fsockopen("[::1]",80);
echo "--\n";
fsockopen("[fe80:1:1::1]",80);
echo "--\n";
fsockopen("fe80:1:1::1",80);
echo "--\n";
fsockopen("ipv6.host.name",80);

Expected result:
----------------
--
--
--

Actual result:
--------------
Warning: fsockopen(): php_network_getaddresses: gethostbyname failed
Warning: fsockopen(): unable to connect to [::1]:80 (Unknown error)
--
Warning: fsockopen(): php_network_getaddresses: gethostbyname failed
Warning: fsockopen(): unable to connect to [fe80:1:1::1]:80 (Unknown error)
--
Warning: fsockopen(): unable to connect to fe80:1:1::1:80 (Operation timed out)
--
Warning: fsockopen(): php_network_getaddresses: gethostbyname failed
Warning: fsockopen(): unable to connect to ipv6.host.name:80 (Unknown error)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-10 23:56 UTC] pollita@php.net
Do any of these work?

fsockopen('tcp://::1', 80);
fsockopen('tcp://[::1]', 80);
stream_socket_client('tcp://[::1]:80');
 [2004-09-11 11:16 UTC] neon at neon-line dot net
Warning: fsockopen(): unable to connect to tcp://::1:80 (Operation timed out) in /dev/php5-v6/test.php on line 2
Warning: fsockopen(): php_network_getaddresses: gethostbyname failed in /dev/php5-v6/test.php on line 3
Warning: fsockopen(): unable to connect to tcp://[::1]:80 (Unknown error) in /dev/php5-v6/test.php on line 3
Warning: stream_socket_client(): php_network_getaddresses: gethostbyname failed in /dev/php5-v6/test.php on line 4
Warning: stream_socket_client(): unable to connect to tcp://[::1]:80 (Unknown error) in /dev/php5-v6/test.php on line 4

To cut the above in short: no, none of those work.
 [2004-09-11 11:37 UTC] wez@php.net
Check your configure output and config.log for stuff related to IPv6; it looks like PHP isn't actually using IPv6 at all.
(gethostbyname is IPv4; PHP would use getaddrinfo for IPv6)
 [2004-09-11 11:50 UTC] neon at neon-line dot net
Configure command used:
./configure --disable-all  --enable-ipv6 \ --with-apxs2=/path/to/apxs2

grep "IPv6" config.log
configure:16103: checking for IPv6 support
configure:17764: checking whether to enable IPv6 support
phpinfo:
IPv6 Support => enabled

I don't see much more that I could have done in order to enable the IPv6 support.

Maybe the --disable-all statement causes this problem?
 [2004-09-11 18:35 UTC] pollita@php.net
grep HAVE_GETADDRINFO main/php_config.h

 [2004-09-11 18:45 UTC] neon at neon-line dot net
It was:
/* #undef HAVE_GETADDRINFO */

After I added
#define HAVE_GETADDRINFO 1
and removed 
#define HAVE_GETHOSTBYNAME2 1

Everything worked just fine with those modifications, so after all it is a bug in the configure script.
 [2004-09-11 18:45 UTC] pollita@php.net
Scratch that, it'll definately show undefined, the question is why.  Can you just post your config.log file somewhere?  Or email it to me?
 [2004-09-11 19:05 UTC] neon at neon-line dot net
http://www.neon-line.net/dev/config.log
There's not much information about this issue, at least I couldn't find. And the code in configure.in that checks for getaddrinfo seems more or less like glue, but there's propably a reason for it to be that way :)
 [2004-09-12 01:29 UTC] wez@php.net
Please try manually compiling this (slightly altered code from configure.in), running it, and pasting the output here in this bug report; thanks!

1/ Copy the code into v6test.c
2/ cc -o v6test v6test.c
3/ ./v6test

#include <netdb.h>
#include <sys/types.h>
int main(void) {
  struct addrinfo *ai, *pai, hints;
    
  memset(&hints, 0, sizeof(hints));
  hints.ai_flags = AI_NUMERICHOST;

  if (getaddrinfo("127.0.0.1", NULL, &hints, &ai) < 0) {
    printf("FAIL-1\n");
    exit(1);
  }

  if (ai == NULL) {
    printf("FAIL-2\n");
    exit(1);
  }

  pai = ai;
    
  while (pai) {
    if (pai->ai_family != AF_INET) {
      /* 127.0.0.1/NUMERICHOST should only resolve ONE way */
      printf("FAIL-3\n");
      exit(1);
    }
    if (pai->ai_addr->sa_family != AF_INET) {
      /* 127.0.0.1/NUMERICHOST should only resolve ONE way */
      printf("FAIL-4\n");
      exit(1);
    }
    pai = pai->ai_next;
  }
  freeaddrinfo(ai);
  printf("OK!\n");
  exit(0);
}

 [2004-09-12 02:12 UTC] pollita@php.net
I recall the bug that prompted the extended check for ai_family and sa_family (though not the bug# off hand).  It was also in BSD (I want to say it was also FreeBSD4).

Enabling getaddrinfo when this behavior was present caused intermittent segfaults in the reporters build, I'll track down that original bug report, it had some detailed comments.
 [2004-09-12 09:10 UTC] neon at neon-line dot net
wez:
I had to add stdlib.h and sys/sockets.h headers to compile it because NULL is defined in stdlib.h (weird) and constant AF_INET in sys/socket.h.
After those modifications output was "OK!" (as expected).
 [2004-09-12 11:27 UTC] wez@php.net
<sys/sockets.h> or <sys/socket.h> ? (I'd expect the latter to be correct)

It sounds like we need to add that header to our configure check to make it work (and also make IPV6 depend on its presence)
 [2004-09-12 11:33 UTC] neon at neon-line dot net
Sorry, my typo. sys/socket.h is indeed the correct one.
On FreeBSD it works, but will it break on some other OS(s)?
 [2004-09-17 17:47 UTC] wez@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

Please test the next unstable (5.1/HEAD) snapshot to see if things work out ok there; we can then backport the fix.
 [2004-09-17 18:02 UTC] neon at neon-line dot net
Current problem:

configure:16413: checking for getaddrinfo
configure:16425: gcc -o conftest -g -O2   conftest.c -lm  1>&5
configure:16471: gcc -o conftest -g -O2   conftest.c -lm 1>&5
configure: In function `main':
configure:16444: `NULL' undeclared (first use in this function)
configure:16444: (Each undeclared identifier is reported only once
configure:16444: for each function it appears in.)
configure: failed program was:
#line 16431 "configure"

My suggestion to fix this is:

--- configure.in.old    Fri Sep 17 17:30:10 2004
+++ configure.in        Fri Sep 17 18:58:02 2004
@@ -569,6 +569,9 @@
   AC_TRY_RUN([
 #include <netdb.h>
 #include <sys/types.h>
+#ifndef NULL
+# define NULL (void *)0
+#endif
 #ifndef AF_INET
 # include <sys/socket.h>
 #endif

Which will fix the problem at least on those machines that I've tested.
 [2004-09-25 13:14 UTC] neon at neon-line dot net
I'm just curious that has this issue been completely forgotten or abandoned?
 [2004-09-26 03:18 UTC] wez@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Not forgotten, just got busy.
Fixed now in all 3 branches, will show up in the next bunch of snapshots.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC