/*************************************************/
-static int
-m_streamsocket(const uschar * hostname, struct in_addr * inp, uschar ** errstr)
-{
- struct hostent * he;
- int sock;
-
- /* Lookup the host */
- if(!(he = gethostbyname(CS hostname))) {
- *errstr = string_sprintf("failed to lookup host '%s'", hostname);
- return -1;
- }
-/*XXX will fail for ipv6 */
- *inp = *(struct in_addr *) he->h_addr_list[0];
-
- /* Create the TCP socket */
- if ((sock = ip_socket(SOCK_STREAM, AF_INET)) >= 0)
- return sock;
-
- *errstr = string_sprintf("unable to acquire socket (%s)", strerror(errno));
- return -1;
-}
-
-static int
+/* Only used by the Clamav code, which is working from a list of servers and
+uses the returned in_addr to get a second connection to the same system.
+*/
+static inline int
m_tcpsocket(const uschar * hostname, unsigned int port,
- struct in_addr * inp, uschar ** errstr)
+ host_item * host, uschar ** errstr)
{
- int sock;
-
- if ((sock = m_streamsocket(hostname, inp, errstr)) < 0)
- return -1;
-
- if (ip_connect(sock, AF_INET, (uschar*)inet_ntoa(*inp), port, 5) >= 0)
- return sock;
-
- *errstr = string_sprintf("connection to %s, port %u failed (%s)",
- inet_ntoa(*inp), port, strerror(errno));
- (void)close(sock);
- return -1;
+ return ip_connectedsocket(SOCK_STREAM, hostname, port, port, 5, host, errstr);
}
static int
}
return ip_connectedsocket(SOCK_STREAM, hostname, portlow, porthigh,
- 5, errstr);
+ 5, NULL, errstr);
}
static int
uschar * file_name;
uschar av_buffer[1024];
uschar *hostname = "";
- struct in_addr in;
+ host_item connhost;
uschar *clamav_fbuf;
int clam_fd, result;
unsigned int fsize;
* on both connections (as one host could resolve to multiple ips) */
sock= m_tcpsocket(CS clamd_address_vector[current_server]->tcp_addr,
clamd_address_vector[current_server]->tcp_port,
- &in, &errstr);
+ &connhost, &errstr);
if (sock >= 0) {
/* Connection successfully established with a server */
hostname = clamd_address_vector[current_server]->tcp_addr;
av_buffer2));
}
- if ( (sockData = ip_socket(SOCK_STREAM, AF_INET)) < 0) {
- int err = errno;
+ sockData = m_tcpsocket(connhost.address, port, NULL, &errstr);
+ if (sockData < 0) {
(void)close(sock);
- return clmd_errlog_defer(
- string_sprintf("unable to acquire socket (%s)", strerror(err)));
- }
-
- if (ip_connect(sockData, AF_INET, (uschar*)inet_ntoa(in), port, 5) < 0) {
- int err = errno;
- (void)close(sockData); (void)close(sock);
- return clmd_errlog_defer(
- string_sprintf("connection to %s, port %u failed (%s)",
- inet_ntoa(in), port, strerror(err)));
+ return clmd_errlog_defer(errstr);
}
#define CLOSE_SOCKDATA (void)close(sockData)