Porting IPv4 Application to Dualstack IPv4/IPv6
问题 Actually I'm porting an IPv4 server application to a dualstack IPv4/IPv6 application on Linux. The basic function I have solved by using: serv_addr.sin6_family = AF_INET6; serv_addr.sin6_addr = in6addr_any; ... bind(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); ... listen(sock, 5); ... newsock = accept(syn->sock, (struct sockaddr *) &cli_addr, &clilen); I can connect with IPv4 and IPv6 and use the connections. But when I want to get the IP with: switch(data->sa_family) { case AF