sockaddr_in6 not declared?

拟墨画扇 提交于 2020-01-13 14:56:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!