|
|
@ -179,7 +179,9 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
|
|
|
|
|
|
|
|
|
|
|
|
int e = getaddrinfo(StrEmpty(this->hostname) ? NULL : this->hostname, port_name, &hints, &ai);
|
|
|
|
int e = getaddrinfo(StrEmpty(this->hostname) ? NULL : this->hostname, port_name, &hints, &ai);
|
|
|
|
if (e != 0) {
|
|
|
|
if (e != 0) {
|
|
|
|
|
|
|
|
if (func != ResolveLoopProc) {
|
|
|
|
DEBUG(net, 0, "getaddrinfo(%s, %s) failed: %s", this->hostname, port_name, FS2OTTD(gai_strerror(e)));
|
|
|
|
DEBUG(net, 0, "getaddrinfo(%s, %s) failed: %s", this->hostname, port_name, FS2OTTD(gai_strerror(e)));
|
|
|
|
|
|
|
|
}
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -250,23 +252,23 @@ static SOCKET ListenLoopProc(addrinfo *runp)
|
|
|
|
|
|
|
|
|
|
|
|
SOCKET sock = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol);
|
|
|
|
SOCKET sock = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol);
|
|
|
|
if (sock == INVALID_SOCKET) {
|
|
|
|
if (sock == INVALID_SOCKET) {
|
|
|
|
DEBUG(net, 1, "[%s] Could not create socket on port %s: %s", type, address, strerror(errno));
|
|
|
|
DEBUG(net, 0, "[%s] Could not create socket on port %s: %s", type, address, strerror(errno));
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (runp->ai_socktype == SOCK_STREAM && !SetNoDelay(sock)) {
|
|
|
|
if (runp->ai_socktype == SOCK_STREAM && !SetNoDelay(sock)) {
|
|
|
|
DEBUG(net, 1, "[%s] Setting TCP_NODELAY failed for port %s", type, address);
|
|
|
|
DEBUG(net, 3, "[%s] Setting TCP_NODELAY failed for port %s", type, address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int on = 1;
|
|
|
|
int on = 1;
|
|
|
|
/* The (const char*) cast is needed for windows!! */
|
|
|
|
/* The (const char*) cast is needed for windows!! */
|
|
|
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)) == -1) {
|
|
|
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)) == -1) {
|
|
|
|
DEBUG(net, 1, "[%s] Could not set reusable sockets for port %s: %s", type, address, strerror(errno));
|
|
|
|
DEBUG(net, 3, "[%s] Could not set reusable sockets for port %s: %s", type, address, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (runp->ai_family == AF_INET6 &&
|
|
|
|
if (runp->ai_family == AF_INET6 &&
|
|
|
|
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&on, sizeof(on)) == -1) {
|
|
|
|
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&on, sizeof(on)) == -1) {
|
|
|
|
DEBUG(net, 1, "[%s] Could not disable IPv4 over IPv6 on port %s: %s", type, address, strerror(errno));
|
|
|
|
DEBUG(net, 3, "[%s] Could not disable IPv4 over IPv6 on port %s: %s", type, address, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bind(sock, runp->ai_addr, runp->ai_addrlen) != 0) {
|
|
|
|
if (bind(sock, runp->ai_addr, runp->ai_addrlen) != 0) {
|
|
|
|