Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket bind failed errno = 99

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

  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"); 
like image 523
Broccoli Avatar asked May 28 '13 05:05

Broccoli


1 Answers

99 is EADDRNOTAVAIL. Which means (from 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.

like image 138
SKi Avatar answered Sep 24 '22 08:09

SKi