我必須移植現有的Win API應用程序才能使用TCPv6。無法弄清楚如何將套接字綁定到本地主機。如何使用TCPv6將套接字綁定到本地用戶
早些時候:
struct sockaddr_in ServerAddress;
ListenSocket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
...
ServerAddress.sin_family = AF_INET;
ServerAddress.sin_addr.s_addr = inet_addr("127.0.0.1");
ServerAddress.sin_port = htons(nPortNo);
現在,我想:
struct sockaddr_in ServerAddress;
ListenSocket = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
...
ServerAddress.sin_family = AF_INET6;
ServerAddress.sin_addr.s_addr = inet_addr("::1");
ServerAddress.sin_port = htons(nPortNo);
,並綁定返回SOCKET_ERROR
有一個從MS https://msdn.microsoft.com/en-us/library/windows/desktop/ms737937%28v=vs.85%29.aspx一個頁面,但沒有綁定例如
'inet_addr'返回一個unsigned long,究竟如何你期待爲了適應IPv6地址? –