January 08, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=818

           Summary: std.socket.InternetAddress.sin needs to be properly
                    initialized on OS X
           Product: D
           Version: 1.00
          Platform: Macintosh
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: d@jeffmcglynn.com


While translating a C++ program into D on Mac OS X 10.4.7, I was unable to get the bind() call to work on any address other than ADDR_ANY and kept receiving a EADDRNOTAVAIL error code.  After dissecting D's std/stream.d, I have discovered that the problem originated from the InternetAddress class in std.socket because it does not zero out the sockaddr_in struct and does not set the sin_family value to AddressFamily.INET.  This caused OS X's bind() to fail.

To temporarily fix this problem I created a wrapper around InternetAddress:

/**
 * A modified InternetAddress that works on Darwin.
 */
class IPAddress : InternetAddress {
        private import std.c.string;

        this(char[] addr, ushort port) {
                memset(cast(void *) &sin, 0, sin.sizeof);
                sin.sin_family = AddressFamily.INET;

                super(addr, port);
        }
}

InternetAddress's constructors should be changed to zero out the sockaddr_in and set sin_family so that this problem can be avoided on Mac OS X.

Reference: http://cvs.haskell.org/trac/ghc/ticket/647

-- Jeff


--