linux – 套接字绑定失败errno = 99

前端之家收集整理的这篇文章主要介绍了linux – 套接字绑定失败errno = 99前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试绑定服务器套接字,以便我可以接收和侦听来自其他客户端的传入消息.但我无法绑定,它返回一个错误套接字绑定失败: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");

解决方法

99是EADDRNOTAVAIL.这意味着(来自man bind(2)):

A nonexistent interface was requested or the requested address was not
local.

也许SERVER_IP不是您主机的IP.

原文链接:https://www.f2er.com/linux/395820.html

猜你在找的Linux相关文章