@@ -1611,11 +1611,25 @@ void uvGetSockInfo(struct sockaddr* addr, SIpAddr* ip) {
16111611 } else if (addr -> sa_family == AF_INET6 ) {
16121612 struct sockaddr_in6 * addr_in = (struct sockaddr_in6 * )addr ;
16131613 ip -> port = ntohs (addr_in -> sin6_port );
1614- if (inet_ntop (AF_INET6 , & addr_in -> sin6_addr , ip -> ipv6 , INET6_ADDRSTRLEN ) == NULL ) {
1615- uInfo ("failed to convert ipv6 address" );
1614+
1615+ // Check for IPv4-mapped IPv6 address (::ffff:x.x.x.x)
1616+ if (IN6_IS_ADDR_V4MAPPED (& addr_in -> sin6_addr )) {
1617+ // Convert IPv4-mapped IPv6 address to IPv4
1618+ struct in_addr ipv4_addr ;
1619+ memcpy (& ipv4_addr , ((const uint8_t * )& addr_in -> sin6_addr ) + 12 , sizeof (ipv4_addr ));
1620+ if (inet_ntop (AF_INET , & ipv4_addr , ip -> ipv4 , INET_ADDRSTRLEN ) == NULL ) {
1621+ uInfo ("failed to convert ipv4-mapped ipv6 address to ipv4" );
1622+ }
1623+ ip -> type = 0 ;
1624+ ip -> mask = 32 ;
1625+ } else {
1626+ // Pure IPv6 address
1627+ if (inet_ntop (AF_INET6 , & addr_in -> sin6_addr , ip -> ipv6 , INET6_ADDRSTRLEN ) == NULL ) {
1628+ uInfo ("failed to convert ipv6 address" );
1629+ }
1630+ ip -> type = 1 ;
1631+ ip -> mask = 128 ;
16161632 }
1617- ip -> type = 1 ;
1618- ip -> mask = 128 ;
16191633 }
16201634}
16211635void uvOnConnectionCb (uv_stream_t * q , ssize_t nread , const uv_buf_t * buf ) {
@@ -1859,11 +1873,21 @@ static int32_t addHandleToAcceptloop(void* arg) {
18591873 return TSDB_CODE_THIRDPARTY_ERROR ;
18601874 }
18611875
1862- if ((code = uv_tcp_bind (& srv -> server , (const struct sockaddr * )& bind_addr , 1 )) != 0 ) {
1876+ if ((code = uv_tcp_bind (& srv -> server , (const struct sockaddr * )& bind_addr , 0 )) != 0 ) {
18631877 tError ("failed to bind since %s" , uv_err_name (code ));
18641878 return TSDB_CODE_THIRDPARTY_ERROR ;
18651879 }
1866- tInfo ("bind to ipv6 addr" );
1880+
1881+ // set IPV6_V6ONLY to 0 to allow both IPv4 and IPv6 connections
1882+ uv_os_fd_t fd ;
1883+ if ((code = uv_fileno ((const uv_handle_t * )& srv -> server , & fd )) == 0 ) {
1884+ int opt = 0 ;
1885+ if (setsockopt (fd , IPPROTO_IPV6 , IPV6_V6ONLY , & opt , sizeof (opt )) < 0 ) {
1886+ tWarn ("failed to set IPV6_V6ONLY=0: %s, continue with default setting" , strerror (errno ));
1887+ } else {
1888+ tInfo ("successfully set IPV6_V6ONLY=0 (dual-stack enabled)" );
1889+ }
1890+ }
18671891 } else {
18681892 struct sockaddr_in bind_addr ;
18691893 if ((code = uv_ip4_addr ("0.0.0.0" , srv -> port , & bind_addr )) != 0 ) {
0 commit comments