Skip to content

Commit dbb152b

Browse files
committed
Detect and enable IPv6 support under win32.
The ws2tcpip.h header links to IPv6 functions dynamically and the generated binary will run on win98 and later.
1 parent 190d8e8 commit dbb152b

File tree

7 files changed

+54
-30
lines changed

7 files changed

+54
-30
lines changed

ext/ftp/ftp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv)
714714
memset(&ftp->pasvaddr, 0, n);
715715
sa = (struct sockaddr *) &ftp->pasvaddr;
716716

717-
#ifdef HAVE_IPV6
717+
#if HAVE_IPV6
718718
if (getpeername(ftp->fd, sa, &n) < 0) {
719719
return 0;
720720
}
@@ -1454,7 +1454,7 @@ ftp_getdata(ftpbuf_t *ftp TSRMLS_DC)
14541454

14551455
data->listener = fd;
14561456

1457-
#ifdef HAVE_IPV6
1457+
#if HAVE_IPV6
14581458
if (sa->sa_family == AF_INET6) {
14591459
/* need to use EPRT */
14601460
char eprtarg[INET6_ADDRSTRLEN + sizeof("|x||xxxxx|")];

ext/sockets/sockets.c

+17-17
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,20 @@ static char *php_strerror(int error TSRMLS_DC)
357357
return (buf ? (char *) buf : "");
358358
}
359359

360-
#ifdef HAVE_IPV6
360+
#if HAVE_IPV6
361361
/* Sets addr by hostname, or by ip in string form (AF_INET6) */
362362
static int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock TSRMLS_DC)
363363
{
364364
struct in6_addr tmp;
365-
#ifdef HAVE_GETADDRINFO
365+
#if HAVE_GETADDRINFO
366366
struct addrinfo hints;
367367
struct addrinfo *addrinfo = NULL;
368368
#endif
369369

370370
if (inet_pton(AF_INET6, string, &tmp)) {
371371
memcpy(&(sin6->sin6_addr.s6_addr), &(tmp.s6_addr), sizeof(struct in6_addr));
372372
} else {
373-
#ifdef HAVE_GETADDRINFO
373+
#if HAVE_GETADDRINFO
374374

375375
memset(&hints, 0, sizeof(struct addrinfo));
376376
hints.ai_family = PF_INET6;
@@ -450,7 +450,7 @@ PHP_MINIT_FUNCTION(sockets)
450450

451451
REGISTER_LONG_CONSTANT("AF_UNIX", AF_UNIX, CONST_CS | CONST_PERSISTENT);
452452
REGISTER_LONG_CONSTANT("AF_INET", AF_INET, CONST_CS | CONST_PERSISTENT);
453-
#ifdef HAVE_IPV6
453+
#if HAVE_IPV6
454454
REGISTER_LONG_CONSTANT("AF_INET6", AF_INET6, CONST_CS | CONST_PERSISTENT);
455455
#endif
456456
REGISTER_LONG_CONSTANT("SOCK_STREAM", SOCK_STREAM, CONST_CS | CONST_PERSISTENT);
@@ -871,7 +871,7 @@ PHP_FUNCTION(socket_getsockname)
871871
php_socket *php_sock;
872872
struct sockaddr *sa;
873873
struct sockaddr_in *sin;
874-
#ifdef HAVE_IPV6
874+
#if HAVE_IPV6
875875
struct sockaddr_in6 *sin6;
876876
char addr6[INET6_ADDRSTRLEN+1];
877877
#endif
@@ -892,7 +892,7 @@ PHP_FUNCTION(socket_getsockname)
892892
}
893893

894894
switch (sa->sa_family) {
895-
#ifdef HAVE_IPV6
895+
#if HAVE_IPV6
896896
case AF_INET6:
897897
sin6 = (struct sockaddr_in6 *) sa;
898898
inet_ntop(AF_INET6, &sin6->sin6_addr, addr6, INET6_ADDRSTRLEN);
@@ -947,7 +947,7 @@ PHP_FUNCTION(socket_getpeername)
947947
php_socket *php_sock;
948948
struct sockaddr *sa;
949949
struct sockaddr_in *sin;
950-
#ifdef HAVE_IPV6
950+
#if HAVE_IPV6
951951
struct sockaddr_in6 *sin6;
952952
char addr6[INET6_ADDRSTRLEN+1];
953953
#endif
@@ -968,7 +968,7 @@ PHP_FUNCTION(socket_getpeername)
968968
}
969969

970970
switch (sa->sa_family) {
971-
#ifdef HAVE_IPV6
971+
#if HAVE_IPV6
972972
case AF_INET6:
973973
sin6 = (struct sockaddr_in6 *) sa;
974974
inet_ntop(AF_INET6, &sin6->sin6_addr, addr6, INET6_ADDRSTRLEN);
@@ -1029,7 +1029,7 @@ PHP_FUNCTION(socket_create)
10291029
}
10301030

10311031
if (arg1 != AF_UNIX
1032-
#ifdef HAVE_IPV6
1032+
#if HAVE_IPV6
10331033
&& arg1 != AF_INET6
10341034
#endif
10351035
&& arg1 != AF_INET) {
@@ -1063,7 +1063,7 @@ PHP_FUNCTION(socket_connect)
10631063
zval *arg1;
10641064
php_socket *php_sock;
10651065
struct sockaddr_in sin;
1066-
#ifdef HAVE_IPV6
1066+
#if HAVE_IPV6
10671067
struct sockaddr_in6 sin6;
10681068
#endif
10691069
struct sockaddr_un s_un;
@@ -1078,7 +1078,7 @@ PHP_FUNCTION(socket_connect)
10781078
ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket);
10791079

10801080
switch(php_sock->type) {
1081-
#ifdef HAVE_IPV6
1081+
#if HAVE_IPV6
10821082
case AF_INET6:
10831083
if (argc != 3) {
10841084
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Socket of type AF_INET6 requires 3 arguments");
@@ -1189,7 +1189,7 @@ PHP_FUNCTION(socket_bind)
11891189
retval = bind(php_sock->bsd_socket, (struct sockaddr *)sa, sizeof(struct sockaddr_in));
11901190
break;
11911191
}
1192-
#ifdef HAVE_IPV6
1192+
#if HAVE_IPV6
11931193
case AF_INET6:
11941194
{
11951195
struct sockaddr_in6 *sa = (struct sockaddr_in6 *) sock_type;
@@ -1298,7 +1298,7 @@ PHP_FUNCTION(socket_recvfrom)
12981298
php_socket *php_sock;
12991299
struct sockaddr_un s_un;
13001300
struct sockaddr_in sin;
1301-
#ifdef HAVE_IPV6
1301+
#if HAVE_IPV6
13021302
struct sockaddr_in6 sin6;
13031303
char addr6[INET6_ADDRSTRLEN];
13041304
#endif
@@ -1361,7 +1361,7 @@ PHP_FUNCTION(socket_recvfrom)
13611361
ZVAL_STRING(arg5, address ? address : "0.0.0.0", 1);
13621362
ZVAL_LONG(arg6, ntohs(sin.sin_port));
13631363
break;
1364-
#ifdef HAVE_IPV6
1364+
#if HAVE_IPV6
13651365
case AF_INET6:
13661366
slen = sizeof(sin6);
13671367
memset(&sin6, 0, slen);
@@ -1407,7 +1407,7 @@ PHP_FUNCTION(socket_sendto)
14071407
php_socket *php_sock;
14081408
struct sockaddr_un s_un;
14091409
struct sockaddr_in sin;
1410-
#ifdef HAVE_IPV6
1410+
#if HAVE_IPV6
14111411
struct sockaddr_in6 sin6;
14121412
#endif
14131413
int retval, buf_len, addr_len;
@@ -1445,7 +1445,7 @@ PHP_FUNCTION(socket_sendto)
14451445

14461446
retval = sendto(php_sock->bsd_socket, buf, (len > buf_len) ? buf_len : len, flags, (struct sockaddr *) &sin, sizeof(sin));
14471447
break;
1448-
#ifdef HAVE_IPV6
1448+
#if HAVE_IPV6
14491449
case AF_INET6:
14501450
if (argc != 6) {
14511451
WRONG_PARAM_COUNT;
@@ -1647,7 +1647,7 @@ PHP_FUNCTION(socket_create_pair)
16471647
php_sock[1] = (php_socket*)emalloc(sizeof(php_socket));
16481648

16491649
if (domain != AF_INET
1650-
#ifdef HAVE_IPV6
1650+
#if HAVE_IPV6
16511651
&& domain != AF_INET6
16521652
#endif
16531653
&& domain != AF_UNIX) {

ext/standard/info.c

+5
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
467467
php_info_print_table_row(2, "Thread Safety", "disabled" );
468468
#endif
469469

470+
#if HAVE_IPV6
471+
php_info_print_table_row(2, "IPv6 Support", "enabled" );
472+
#else
473+
php_info_print_table_row(2, "IPv6 Support", "disabled" );
474+
#endif
470475
{
471476
HashTable *url_stream_wrappers_hash;
472477
char *stream_protocol, *stream_protocols_buf = NULL;

main/network.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int inet_aton(const char *, struct in_addr *);
103103
# define PHP_TIMEOUT_ERROR_VALUE ETIMEDOUT
104104
#endif
105105

106-
#ifdef HAVE_GETADDRINFO
106+
#if HAVE_GETADDRINFO
107107
#ifdef HAVE_GAI_STRERROR
108108
# define PHP_GAI_STRERROR(x) (gai_strerror(x))
109109
#else
@@ -168,7 +168,7 @@ static int php_network_getaddresses(const char *host, int socktype, struct socka
168168
{
169169
struct sockaddr **sap;
170170
int n;
171-
#ifdef HAVE_GETADDRINFO
171+
#if HAVE_GETADDRINFO
172172
static int ipv6_borked = -1; /* the way this is used *is* thread safe */
173173
struct addrinfo hints, *res, *sai;
174174
#else
@@ -179,13 +179,13 @@ static int php_network_getaddresses(const char *host, int socktype, struct socka
179179
if (host == NULL) {
180180
return 0;
181181
}
182-
#ifdef HAVE_GETADDRINFO
182+
#if HAVE_GETADDRINFO
183183
memset(&hints, '\0', sizeof(hints));
184184

185185
hints.ai_family = AF_INET; /* default to regular inet (see below) */
186186
hints.ai_socktype = socktype;
187187

188-
# ifdef HAVE_IPV6
188+
# if HAVE_IPV6
189189
/* probe for a working IPv6 stack; even if detected as having v6 at compile
190190
* time, at runtime some stacks are slow to resolve or have other issues
191191
* if they are not correctly configured.
@@ -488,7 +488,7 @@ PHPAPI int php_network_parse_network_address_with_port(const char *addr, long ad
488488
struct sockaddr **psal;
489489
int n;
490490
char *errstr = NULL;
491-
#ifdef HAVE_IPV6
491+
#if HAVE_IPV6
492492
struct sockaddr_in6 *in6 = (struct sockaddr_in6*)sa;
493493
#endif
494494

@@ -860,7 +860,7 @@ PHPAPI void php_any_addr(int family, php_sockaddr_storage *addr, unsigned short
860860
{
861861
memset(addr, 0, sizeof(php_sockaddr_storage));
862862
switch (family) {
863-
#ifdef HAVE_IPV6
863+
#if HAVE_IPV6
864864
case AF_INET6: {
865865
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) addr;
866866
sin6->sin6_family = AF_INET6;
@@ -888,7 +888,7 @@ PHPAPI int php_sockaddr_size(php_sockaddr_storage *addr)
888888
switch (((struct sockaddr *)addr)->sa_family) {
889889
case AF_INET:
890890
return sizeof(struct sockaddr_in);
891-
#ifdef HAVE_IPV6
891+
#if HAVE_IPV6
892892
case AF_INET6:
893893
return sizeof(struct sockaddr_in6);
894894
#endif

main/php_network.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
# endif
2828
# undef FD_SETSIZE
2929
# include "arpa/inet.h"
30-
# define socklen_t unsigned int
30+
# if HAVE_WS2TCPIP_H
31+
/* IPv6 stuff, also defines socklen_t */
32+
# include <ws2tcpip.h>
33+
# else
34+
typedef unsigned int socklen_t;
35+
# endif
3136
#else
3237
# undef closesocket
3338
# define closesocket close

win32/build/config.w32

+14
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,17 @@ ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c");
181181

182182
STDOUT.WriteBlankLines(1);
183183

184+
/* Can we build with IPv6 support? */
185+
ARG_ENABLE("ipv6", "Disable IPv6 support (default is turn it on if available)", "yes");
186+
187+
var main_network_has_ipv6 = 0;
188+
if (PHP_IPV6 == "yes") {
189+
main_network_has_ipv6 = CHECK_HEADER_ADD_INCLUDE("ws2tcpip.h", "CFLAGS") ? 1 : 0;
190+
}
191+
if (main_network_has_ipv6) {
192+
STDOUT.WriteLine("Enabling IPv6 support");
193+
}
194+
AC_DEFINE('HAVE_GETADDRINFO', main_network_has_ipv6);
195+
AC_DEFINE('HAVE_GAI_STRERROR', main_network_has_ipv6);
196+
AC_DEFINE('HAVE_IPV6', main_network_has_ipv6);
197+

win32/build/confutils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
+----------------------------------------------------------------------+
1818
*/
1919

20-
// $Id: confutils.js,v 1.17 2003-12-05 02:41:00 wez Exp $
20+
// $Id: confutils.js,v 1.18 2003-12-06 00:00:31 wez Exp $
2121

2222
var STDOUT = WScript.StdOut;
2323
var STDERR = WScript.StdErr;
@@ -427,14 +427,14 @@ function CHECK_HEADER_ADD_INCLUDE(header_name, flag_name, path_to_check, use_env
427427

428428
if (typeof(p) == "string") {
429429
ADD_FLAG(flag_name, '/I "' + p + '" ');
430-
have = 1;
431430
} else if (p == false) {
432431
/* not found in the defaults or the explicit paths,
433432
* so check the general extra includes; if we find
434433
* it here, no need to add another /I for it as we
435434
* already have it covered */
436435
p = search_paths(header_name, PHP_EXTRA_INCLUDES, null);
437-
}
436+
}
437+
have = p ? 1 : 0
438438

439439
sym = header_name.toUpperCase();
440440
sym = sym.replace(new RegExp("[\\\\/\.-]", "g"), "_");

0 commit comments

Comments
 (0)