#include "client.h"
#include "h/mts.h"
#include "h/utils.h"
+#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
}
if (connect(sd, ai->ai_addr, ai->ai_addrlen) == 0) {
+ int flags;
+
freeaddrinfo(res);
+
+ flags = fcntl(sd, F_GETFD, 0);
+
+ if (flags != -1)
+ fcntl(sd, F_SETFD, flags | FD_CLOEXEC);
+
return sd;
}
if (res->ai_next)
snprintf(response, len_response, "no servers available (use -snoop "
- "for details");
- else
- snprintf(response, len_response, "Connection to \"%s\" failed: %s",
- server, strerror(errno));
+ "for details)");
+ else {
+ char port[NI_MAXSERV];
+
+ if (getnameinfo(res->ai_addr, res->ai_addrlen, NULL, 0, port,
+ sizeof port, NI_NUMERICSERV)) {
+ strncpy(port, "unknown", sizeof port);
+ port[sizeof(port) - 1] = '\0';
+ }
+
+ snprintf(response, len_response, "Connection to \"%s:%s\" failed: %s",
+ server, port, strerror(errno));
+ }
freeaddrinfo(res);