Isn't struct sockadr_in supposed to work for both IPv4 and IPv6?

后端 未结 2 513
庸人自扰
庸人自扰 2021-02-08 03:34

Specifically sin_addr seems to be located on different memory locations for IPv4 and IPv6 socket addressed. This results in weirdness:

#include            


        
2条回答
  •  無奈伤痛
    2021-02-08 04:37

    No, for ipv6 you need to use

    in6_addr // is used to store the 128-bit network address
    

    and

    sockaddr_in6
    

    Details can be referenced here

    For writing code which supports dual stack i.e. ipv4 and 6 along use this

提交回复
热议问题