@@ -199,53 +199,39 @@ service: service]; } - (void)bindService: (OFString*)service onNode: (OFString*)node - withFamily: (int)family { if (sock != INVALID_SOCKET) @throw [OFAlreadyConnectedException newWithClass: isa]; -#ifndef HAVE_THREADSAFE_GETADDRINFO - if (family != AF_INET) - @throw [OFBindFailedException newWithClass: isa - node: node - service: service - family: family]; -#endif - - if ((sock = socket(family, SOCK_STREAM, 0)) == INVALID_SOCKET) - @throw [OFBindFailedException newWithClass: isa - node: node - service: service - family: family]; - #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res; memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = family; + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - if (getaddrinfo([node cString], [service cString], &hints, &res)) { - close(sock); - sock = INVALID_SOCKET; + if (getaddrinfo([node cString], [service cString], &hints, &res)) @throw [OFAddressTranslationFailedException newWithClass: isa node: node service: service]; - } + + if ((sock = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) + @throw [OFBindFailedException newWithClass: isa + node: node + service: service]; if (bind(sock, res->ai_addr, res->ai_addrlen) == -1) { freeaddrinfo(res); close(sock); sock = INVALID_SOCKET; @throw [OFBindFailedException newWithClass: isa node: node - service: service - family: family]; + service: service]; } freeaddrinfo(res); #else struct hostent *he; @@ -272,12 +258,10 @@ else if ((port = OF_BSWAP16_IF_LE(strtol([service cString], NULL, 10))) == 0) { # ifdef OF_THREADS [mutex unlock]; # endif - close(sock); - sock = INVALID_SOCKET; @throw [OFAddressTranslationFailedException newWithClass: isa node: node service: service]; } @@ -288,12 +272,10 @@ if (he->h_addrtype != AF_INET || he->h_addr_list[0] == NULL) { # ifdef OF_THREADS [mutex unlock]; # endif - close(sock); - sock = INVALID_SOCKET; @throw [OFAddressTranslationFailedException newWithClass: isa node: node service: service]; } @@ -301,18 +283,21 @@ memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length); # ifdef OF_THREADS [mutex unlock]; # endif + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) + @throw [OFBindFailedException newWithClass: isa + node: node + service: service]; if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) { close(sock); sock = INVALID_SOCKET; @throw [OFBindFailedException newWithClass: isa node: node - service: service - family: family]; + service: service]; } #endif } - (void)listenWithBackLog: (int)backlog