我正在尝试使用 ipv6 来增加套接字编程的复杂性:
不应该这样:
struct sockaddr_in6* addr = new sockaddr_in6;
int s = socket(AF_INET6, SOCK_STREAM, 0);
addr->sin6_addr = in6addr_any;
addr->sin6_port = 1234;
int ret = bind(s, (struct sockaddr*)addr, sizeof(struct sockaddr_in6));
将我机器上所有接口(interface)的套接字绑定(bind)到端口 1234? 麻烦是 bind 返回 -1 并且 errno 是 47 根据 errno.h 是:
#define EAFNOSUPPORT 47 /* Address family not supported by protocol
family */
我错过了什么?
谢谢
最佳答案
您应该将 addr->sin6_family 设置为 AF_INET6 或至少在将地址结构传递给 bind() 之前对其进行零初始化。
关于c++ - 为什么 bind(..) for ipv6 under mac os x 给我错误号 47,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6396702/