2 * Copyright (C) 2008-2009 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/socket.h>
20 #include <sys/types.h>
21 #include <netinet/in.h>
28 tcp_connect (struct addrinfo *ai)
31 fd = socket (ai->ai_family, SOCK_STREAM, 0);
34 if (connect (fd, ai->ai_addr, ai->ai_addrlen) < 0)
43 tcp_connect_list (struct addrinfo *ai)
46 for (; ai; ai = ai->ai_next)
48 fd = tcp_connect (ai);
58 hc_tcp_connect (char *server, char *service)
60 struct addrinfo *ai = NULL;
62 if (getaddrinfo (server, service, NULL, &ai) < 0)
64 fd = tcp_connect_list (ai);
71 main (int argc, char **argv)
76 server = (argc >= 2) ? argv[1] : "localhost";
77 service = (argc >= 3) ? argv[2] : "110";
78 fd = hc_tcp_connect (server, service);