问题
I'm trying to port an ipv4 server/client to ipv6, but the compiler says SOCKADDR_IN6
is not declared in the scope. SOCKADDR_IN
is declared but not SOCKADDR_IN6
. <Winsock2.h>
is included.
Any one have any ideas why it would be undeclared?
回答1:
Microsoft's documentation for sockaddr_in6 says that it is defined in the ws2tcpip.h
header, probably you need to include that.
On Linux you'd need different includes, sys/socket.h
and netinet/in.h
.
回答2:
I have currently found SOCKADDR_IN6
definition in ws2ipdef.h
header (Visual Studio 2008). However, as said in a comment below, MS Docs states that this header should never be used directly (use Ws2tcpip.h
instead).
回答3:
From msdn:
struct in_addr6 {
u_char s6_addr[16]; /* IPv6 address */
};
struct sockaddr_in6 {
short sin6_family; /* AF_INET6 */
u_short sin6_port; /* Transport level port number */
u_long sin6_flowinfo; /* IPv6 flow information */
struct in_addr6 sin6_addr; /* IPv6 address */
u_long sin6_scope_id; /* set of interfaces for a scope */
};
From your question i see that:
SOCKADDR_IN6 != sockaddr_in6
Lowercase vs. Uppercase confusion?
You may also not have the latest version of winsock, i'm not sure how far back support for IPV6 was introduced, you may want to check if thats your problem.
来源:https://stackoverflow.com/questions/3443836/sockaddr-in6-not-declared