|
|
|
@ -167,8 +167,8 @@ int TCP::Connect() {
|
|
|
|
|
hints.ai_flags = 0;
|
|
|
|
|
hints.ai_protocol = 0;
|
|
|
|
|
|
|
|
|
|
s = getaddrinfo(remote_host.c_str(), remote_port.c_str(), &hints, &res);
|
|
|
|
|
if (s != 0) {
|
|
|
|
|
err = getaddrinfo(remote_host.c_str(), remote_port.c_str(), &hints, &res);
|
|
|
|
|
if (err != 0) {
|
|
|
|
|
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -177,11 +177,13 @@ int TCP::Connect() {
|
|
|
|
|
// walk through all results until we could connect
|
|
|
|
|
//
|
|
|
|
|
for (rp = res; rp != NULL; rp = rp->ai_next) {
|
|
|
|
|
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
|
|
|
|
if (sock == -1) continue;
|
|
|
|
|
if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) break;
|
|
|
|
|
close(sock);
|
|
|
|
|
sock = -1;
|
|
|
|
|
s = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
|
|
|
|
if (s == -1) continue;
|
|
|
|
|
if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1) {
|
|
|
|
|
sock = s;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
close(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
freeaddrinfo(res);
|
|
|
|
|