--------------------- PatchSet 4721 Date: 2007/06/12 12:28:31 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: IPv6 Enable squidclient tool Members: tools/squidclient.cc:1.5.4.2->1.5.4.3 Index: squid3/tools/squidclient.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/tools/squidclient.cc,v retrieving revision 1.5.4.2 retrieving revision 1.5.4.3 diff -u -r1.5.4.2 -r1.5.4.3 --- squid3/tools/squidclient.cc 5 Jan 2007 17:01:43 -0000 1.5.4.2 +++ squid3/tools/squidclient.cc 12 Jun 2007 12:28:31 -0000 1.5.4.3 @@ -1,6 +1,6 @@ /* - * $Id: squidclient.cc,v 1.5.4.2 2007/01/05 17:01:43 hno Exp $ + * $Id: squidclient.cc,v 1.5.4.3 2007/06/12 12:28:31 amosjeffries Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived @@ -84,6 +84,7 @@ #endif #include "util.h" +#include "IPAddress.h" #ifndef BUFSIZ #define BUFSIZ 8192 @@ -452,7 +453,11 @@ int fsize = 0; /* Connect to the server */ +#if USE_IPV6 if ((conn = socket(PF_INET, SOCK_STREAM, 0)) < 0) { +#else + if ((conn = socket(PF_INET6, SOCK_STREAM, 0)) < 0) { +#endif perror("client: socket"); exit(1); } @@ -585,52 +590,56 @@ static int client_comm_bind(int sock, const char *local_host) { - static const struct hostent *hp = NULL; + int res; - static struct sockaddr_in from_addr; + static struct addrinfo *AI = NULL; + + IPAddress addr; /* Set up the source socket address from which to send. */ - if (hp == NULL) { - from_addr.sin_family = AF_INET; + addr = local_host; - if ((hp = gethostbyname(local_host)) == 0) { - return (-1); - } + if(addr.IsAnyAddr()) + return (-1); - xmemcpy(&from_addr.sin_addr, hp->h_addr, hp->h_length); - from_addr.sin_port = 0; - } + addr.GetAddrInfo(AI); + + res = bind(sock, AI->ai_addr, AI->ai_addrlen); - return bind(sock, (struct sockaddr *) &from_addr, sizeof(struct sockaddr_in)); + addr.FreeAddrInfo(AI); + + return res; } static int - client_comm_connect(int sock, const char *dest_host, u_short dest_port, struct timeval *tvp) { - static const struct hostent *hp = NULL; + int res; - static struct sockaddr_in to_addr; + static struct addrinfo *AI = NULL; + + IPAddress addr; /* Set up the destination socket address for message to send to. */ - if (hp == NULL) - { - to_addr.sin_family = AF_INET; + addr = dest_host; - if ((hp = gethostbyname(dest_host)) == 0) { - return (-1); - } + if(addr.IsAnyAddr()) + return (-1); - xmemcpy(&to_addr.sin_addr, hp->h_addr, hp->h_length); - to_addr.sin_port = htons(dest_port); - } + addr.SetPort(dest_port); + + addr.GetAddrInfo(AI); if (tvp) (void) Now(tvp); - return connect(sock, (struct sockaddr *) &to_addr, sizeof(struct sockaddr_in)); + res = connect(sock, AI->ai_addr, AI->ai_addrlen); + + addr.FreeAddrInfo(AI); + + return res; } static int