我有這個簡單的客戶端 - 服務器應用程序對。代碼很簡單,我只使用新的建議的方法,如getaddinfo等,一切工作正常的ipv4。即使對於ipv6 loopback(:: 1)也是如此。問題開始涉及到其他ipv6地址...我有兩臺機器在網絡中,一切正常,當我通過他們的ipv4地址,但當我給我的客戶ipv6地址,我得到一個連接函數的錯誤:無效參數。 嘿,我不知道這個?我做!當我嘗試ping6這個IPv6地址,我得到了同樣的錯誤:connect()返回「無效參數」與ipv6地址
connect: Invalid argument
但是有一個方法來克服此塊 - 應該選擇一個-I開關的接口,這一切,因爲運行順利然後。但是我如何在我的客戶端應用程序中實現相同的功能?我該怎麼辦?我的客戶端代碼如下所示:
struct addrinfo hints;
struct addrinfo *server;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
int status;
if((status = getaddrinfo(argv[1], argv[2], &hints, &server) != 0))
{
perror("getaddrinfo error");
return 1;
}
int sock_fd;
struct addrinfo *ptr;
for(ptr=server;ptr!=NULL;ptr=ptr->ai_next)
{
if((sock_fd = socket(ptr->ai_family,ptr->ai_socktype,ptr->ai_protocol)) == -1)
{
perror("socket error");
continue;
}
if(connect(sock_fd, ptr->ai_addr,ptr->ai_addrlen) == -1)
{
perror("connect error");
continue;
}
break;
}
這是ping拒絕的有問題的地址是什麼? – Ariel
我在ping我的網絡中的其他機器,但它對所有ipv6地址的作用相同 - 請檢查: http://lists.debian.org/debian-ipv6/2005/06/msg00044.html – flyjohny
@flyjohny也許你應該檢查你的路線看看是否默認路由是一個ip6路由命令:「route -A inet6」 –