2 * Copyright (C) 2012 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: connecttcp.c,v 1.3.2.2 2012/07/22 08:04:24 darren_r Exp $
13 * Format expected is one addres per line, at the start of each line.
16 connecttcp(char *server, int port)
18 struct sockaddr_in sin;
22 memset(&sin, 0, sizeof(sin));
23 sin.sin_family = AF_INET;
24 sin.sin_port = htons(port & 65535);
26 if (ISDIGIT(*server)) {
27 if (inet_aton(server, &sin.sin_addr) == -1) {
31 host = gethostbyname(server);
34 memcpy(&sin.sin_addr, host->h_addr_list[0],
35 sizeof(sin.sin_addr));
38 fd = socket(AF_INET, SOCK_STREAM, 0);
42 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {