Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c47186

Browse files
Add IPv6 support
1 parent 5537b10 commit 8c47186

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

library.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,7 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
16101610
{
16111611
struct timeval tv, read_tv, *tv_ptr = NULL;
16121612
char *host = NULL, *persistent_id = NULL, *errstr = NULL;
1613+
const char *fmtstr = "%s:%d";
16131614
int host_len, err = 0;
16141615
php_netstream_data_t *sock;
16151616
int tcp_flag = 1;
@@ -1632,8 +1633,15 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
16321633
} else {
16331634
if(redis_sock->port == 0)
16341635
redis_sock->port = 6379;
1635-
host_len = spprintf(&host, 0, "%s:%d", redis_sock->host,
1636-
redis_sock->port);
1636+
1637+
#ifdef HAVE_IPV6
1638+
/* If we've got IPv6 and find a colon in our address, convert to proper
1639+
* IPv6 [host]:port format */
1640+
if (strchr(redis_sock->host, ':') != NULL) {
1641+
fmtstr = "[%s]:%d";
1642+
}
1643+
#endif
1644+
host_len = spprintf(&host, 0, fmtstr, redis_sock->host, redis_sock->port);
16371645
}
16381646

16391647
if (redis_sock->persistent) {

0 commit comments

Comments
 (0)