Search code examples
macossocketsdarwin

EADDRNOTAVAIL when binding 127.0.0.1 on localhost?


I'm getting errno==49 (EADDRNOTAVAIL) when trying to UDP-bind() to 127.0.0.1:47346 running Mac OS X on a G5 (big endian PowerPC). Is there something preventing me from doing so? I've tried other addresses and ports (192.168.1.2 and port 47346) but with no success.

Here's a gdb printout of my sockaddr_in:

$1 = {
  sin_len = 0 '\0', 
  sin_family = 2 '\002', 
  sin_port = 47346, 
  sin_addr = {
    s_addr = 3232235778
  }, 
  sin_zero = "???\000\000??"
}

Solution

  • You should fill the sin_len field as well (with sizeof(struct sockaddr_in), that should do the trick). This field is not appearing on each platform, but on which it exists, it must be filled.

    Futhermore, be sure to bzero the structure before using it (but it clearly seems you did it anyway).