开发者

Why does bind(..) for ipv6 under mac os x give me error number 47

I am taking first steps in socke开发者_运维技巧t programming as an added complexity I am trying to use ipv6:

Shouldn't this:

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));

bind a socket to all interfaces on my machine to port 1234? trouble is bind returns -1 and errno is 47 which according to errno.h is:

#define EAFNOSUPPORT    47              /* Address family not supported by protocol 
family */

What am I missing?

Thanks


You should set addr->sin6_family to AF_INET6 or at least zero-initialise the address structure before passing it to bind().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜