Hi,
Rencently, I try to make my App to support IPv6 network through this guide Supporting IPv6 DNS64/NAT64 Networks. We directly use tcp to comunicate with the server with specific IPv4 address. According to the guide, I use getaddrinfo to do that. But in a NAT64 network, I didn't get the IPv6 address. It's still the IPv4 address. Here is the code:
int main(int argc,char *argv[])
{
struct addrinfo hints, *res, *aip;
int sockfd=-1, error;
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_DEFAULT;
hints.ai_protocol=IPPROTO_TCP;
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
error = getaddrinfo("210.5.154.195", "13163", &hints, &res);
if (error != 0) {
/ handle getaddrinfo error */
}
for (aip=res; aip; aip=aip->ai_next) {
/
if (getnameinfo(aip->ai_addr, aip->ai_addrlen, hbuf, sizeof(hbuf), sbuf,
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
{
printf("host=%s, serv=%s\n", hbuf, sbuf);
}
sockfd = socket(aip->ai_family,
aip->ai_socktype,
aip->ai_protocol);
if (sockfd < 0) {
switch errno {
case EAFNOSUPPORT:
case EPROTONOSUPPORT:
/
* e.g., skip the errors until
* the last address family,
* see section 4.4.
*/
if (aip->ai_next)
continue;
else {
/ handle unknown protocol errors */
break;
}
default:
/ handle other socket errors */
;
}
} else {
int rlt = connect(sockfd, aip->ai_addr, aip->ai_addrlen);
printf("errno:%d\n",errno);
if (rlt== 0)
{
break;
}
/ handle connect errors */
close(sockfd);
sockfd=-1;
}
}
if (sockfd > 0) {
/ socket connected to server address */
/ ... */
printf("Success\n");
}
else
{
printf("Failed\n");
}
freeaddrinfo(res);
}
Could you tell me how could this happen? What should I do? Thanks very much!
Best wishes,
Jack Gao