Linux 套接字绑定失败 errno = 99
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16784530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Socket bind failed errno = 99
提问by Broccoli
I'm trying to bind the server socket so I can receive and listen for incoming messages from other clients. But I can't bind, it returns an error - Socket bind failed: 99. I read up what does it mean and it says that errno 99 indicates that the socket does not exist? Any ideas? Thanks
我正在尝试绑定服务器套接字,以便我可以接收和侦听来自其他客户端的传入消息。但我无法绑定,它返回一个错误 - 套接字绑定失败:99。我读了它是什么意思,它说 errno 99 表示套接字不存在?有任何想法吗?谢谢
UDP_socketID = socket(AF_INET, SOCK_DGRAM, 0);
if (UDP_socketID < 0)
{
printf("Socket creation failed! Error = %d\n\n", errno);
exit(0);
}
//specify server address, port and IP
bzero((char *)&serverAddr, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddr.sin_port = htons(SERV_PORT);
check = inet_aton(SERVER_IP, &serverAddr.sin_addr);
if (check == 0)
printf("IP conversion error!\n\n");
start = bind(UDP_socketID, (struct sockaddr *) &serverAddr, sizeof(serverAddr));
if (start < 0) {
printf("Socket bind failed = %d\n", errno);
exit(0);
}
else
printf("Socket bind successful!\n");
回答by SKi
99 is EADDRNOTAVAIL. Which means (from man bind(2)):
99 是 EADDRNOTAVAIL。这意味着(来自 man bind(2)):
A nonexistent interface was requested or the requested address was not local.
请求了一个不存在的接口或请求的地址不是本地的。
Maybe the SERVER_IP
is not IP of your host.
也许这SERVER_IP
不是您主机的 IP。