--------------------- PatchSet 898 Date: 2000/12/07 13:58:09 Author: rvenning Branch: ipv6 Tag: (none) Log: Initial round of modifications to enable IPv6 support in squid. Basis of modifications revolves around key defines placed in src/defines.h INET_NTOA, SA_NTOA, SAFE_INET_ADDR, PORT_FROM_SA, ADDR_FROM_SA, etc.... maybe I should consider changing these to inline function wrappers for various benefits?? MAJOR OUTSTANDING ISSUES must use --disable-wccp, as we don't play ball with wccp yet. OUTSTANDING ISSUES DNS support required from system libraries: the squid internal DNS client has not been modified. SNMP over IPv6 & passing back IPv6 addresses in response to requests for certain OIDs is all a little interesting at the moment ICP: hostid drawn from some bits of IPv6 address, used to be exactly the IPv4 address of the host. Maybe not so important, although the choice of bits is suboptimal at the moment as far as uniqueness is concerned. (warning: multicast ICP on linux IPv6 could well be stuffed. Hell, this whole patch probably doesn't work yet, it just compiles and loads without core dumping) ftp.c: readPasv getting IP addresses as text, as part of FTP protocol???? net_db.c: exchanges between non-IPv6 enabled & IPv6 enabled squids will be stuffed at the moment Members: configure.in:1.5->1.5.2.1 include/util.h:1.4->1.4.4.1 lib/safe_inet_addr.c:1.2->1.2.6.1 src/access_log.c:1.5->1.5.2.1 src/acl.c:1.4->1.4.6.1 src/asn.c:1.4->1.4.4.1 src/cache_cf.c:1.4->1.4.2.1 src/cachemgr.c:1.3->1.3.6.1 src/client.c:1.3->1.3.6.1 src/client_db.c:1.4->1.4.6.1 src/client_side.c:1.7->1.7.2.1 src/comm.c:1.4->1.4.6.1 src/defines.h:1.3->1.3.6.1 src/dns.c:1.3->1.3.6.1 src/dns_internal.c:1.5->1.5.6.1 src/dnsserver.c:1.3->1.3.6.1 src/errorpage.c:1.5->1.5.2.1 src/forward.c:1.4->1.4.6.1 src/fqdncache.c:1.4->1.4.6.1 src/ftp.c:1.5->1.5.2.1 src/globals.h:1.4->1.4.4.1 src/htcp.c:1.4->1.4.6.1 src/icmp.c:1.3->1.3.6.1 src/icp_v2.c:1.3->1.3.6.1 src/icp_v3.c:1.3->1.3.6.1 src/ident.c:1.4->1.4.6.1 src/internal.c:1.5->1.5.2.1 src/ipc.c:1.3->1.3.6.1 src/ipcache.c:1.4->1.4.6.1 src/main.c:1.5->1.5.4.1 src/multicast.c:1.3->1.3.6.1 src/neighbors.c:1.5->1.5.4.1 src/net_db.c:1.6->1.6.2.1 src/peer_select.c:1.3->1.3.6.1 src/pinger.c:1.3->1.3.6.1 src/protos.h:1.5->1.5.2.1 src/recv-announce.c:1.3->1.3.6.1 src/redirect.c:1.3->1.3.6.1 src/send-announce.c:1.3->1.3.6.1 src/snmp_core.c:1.3->1.3.6.1 src/ssl.c:1.3->1.3.6.1 src/stat.c:1.4->1.4.6.1 src/structs.h:1.7->1.7.2.1 src/tools.c:1.4->1.4.2.1 Index: squid/configure.in =================================================================== RCS file: /cvsroot/squid-sf//squid/configure.in,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- squid/configure.in 18 Nov 2000 11:01:25 -0000 1.5 +++ squid/configure.in 7 Dec 2000 13:58:09 -0000 1.5.2.1 @@ -3,13 +3,13 @@ dnl dnl Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9) dnl -dnl $Id: configure.in,v 1.5 2000/11/18 11:01:25 adri Exp $ +dnl $Id: configure.in,v 1.5.2.1 2000/12/07 13:58:09 rvenning Exp $ dnl dnl dnl AC_INIT(src/main.c) AC_CONFIG_HEADER(include/autoconf.h) -AC_REVISION($Revision: 1.5 $)dnl +AC_REVISION($Revision: 1.5.2.1 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AC_CONFIG_AUX_DIR(cfgaux) @@ -748,6 +748,157 @@ dnl Check for programs AC_PROG_CPP + +AC_MSG_CHECKING([whether to enable ipv6]) +AC_ARG_ENABLE(ipv6, +[ --enable-ipv6 Enable ipv6 (with ipv4) support + --disable-ipv6 Disable ipv6 support], +[ case "$enableval" in + no) + AC_MSG_RESULT(no) + ipv6=no + ;; + *) AC_MSG_RESULT(yes) + AC_DEFINE(INET6) + ipv6=yes + ;; + esac ], + + AC_TRY_RUN([ /* AF_INET6 avalable check */ +#include +#include +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} +], + AC_MSG_RESULT(yes) + AC_DEFINE(INET6) + ipv6=yes, + AC_MSG_RESULT(no) + ipv6=no, + AC_MSG_RESULT(no) + ipv6=no +)) + +ipv6type=unknown +ipv6lib=none + +if test "$ipv6" = "yes"; then + AC_MSG_CHECKING([ipv6 stack type]) + for i in inria kame linux-glibc linux-inet6 toshiba v6d zeta; do + case $i in + inria) + dnl http://www.kame.net/ + AC_EGREP_CPP(yes, [dnl +#include +#ifdef IPV6_INRIA_VERSION +yes +#endif], + [ipv6type=$i; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + kame) + dnl http://www.kame.net/ + AC_EGREP_CPP(yes, [dnl +#include +#ifdef __KAME__ +yes +#endif], + [ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + linux-glibc) + dnl http://www.linux-ipv6.org/ + AC_EGREP_CPP(yes, [dnl +#include +#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)) +yes +#endif], + [ipv6type=$i; + ipv6lib=none; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + linux-inet6) + dnl http://www.linux-ipv6.org/ + if test -d /usr/inet6; then + ipv6type=$i + ipv6lib=inet6 + ipv6libdir=/usr/inet6/lib + CFLAGS="-DINET6 -I/usr/inet6/include $CFLAGS" + fi + ;; + toshiba) + AC_EGREP_CPP(yes, [dnl +#include +#ifdef _TOSHIBA_INET6 +yes +#endif], + [ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + v6d) + AC_EGREP_CPP(yes, [dnl +#include +#ifdef __V6D__ +yes +#endif], + [ipv6type=$i; + ipv6lib=v6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-I/usr/local/v6/include $CFLAGS"]) + ;; + zeta) + AC_EGREP_CPP(yes, [dnl +#include +#ifdef _ZETA_MINAMI_INET6 +yes +#endif], + [ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + esac + if test "$ipv6type" != "unknown"; then + break + fi + done + AC_MSG_RESULT($ipv6type) +fi + +if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then + if test -d $ipv6libdir -a -f $ipv6libdir/lib$ipv6lib.a; then + LIBS="-L$ipv6libdir -l$ipv6lib $LIBS" + else + echo 'Fatal: no $ipv6lib library found. cannot continue.' + echo "You need to fetch lib$ipv6lib.a from appropriate" + echo 'ipv6 kit and compile beforehand.' + exit 1 + fi +fi + + +AC_MSG_CHECKING([whether struct sockaddr_storage has __ss_family]) +AC_TRY_COMPILE([ +#include +#include +],[ +struct sockaddr_storage ss; +int i = ss.__ss_family; +], +[AC_MSG_RESULT(yes) + CFLAGS="$CFLAGS -Dss_family=__ss_family -Dss_len=__ss_len" + ], +AC_MSG_RESULT(no), AC_MSG_RESULT(no)) + AC_PROG_INSTALL AC_PROG_RANLIB AC_PROG_LN_S Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.4 retrieving revision 1.4.4.1 diff -u -r1.4 -r1.4.4.1 --- squid/include/util.h 4 Nov 2000 23:23:06 -0000 1.4 +++ squid/include/util.h 7 Dec 2000 13:58:10 -0000 1.4.4.1 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.4 2000/11/04 23:23:06 hno Exp $ + * $Id: util.h,v 1.4.4.1 2000/12/07 13:58:10 rvenning Exp $ * * AUTHOR: Harvest Derived * @@ -39,6 +39,9 @@ #if HAVE_SYS_TIME_H #include #endif +#if HAVE_NETINET_IN_H +#include +#endif #if !defined(SQUIDHOSTNAMELEN) #include @@ -108,6 +111,12 @@ typedef struct in_addr SIA; extern int safe_inet_addr(const char *, SIA *); + +#if INET6 +const char * inet6_ntoa(const struct in6_addr in); +#endif + + extern time_t parse_iso3307_time(const char *buf); extern char *base64_decode(const char *coded); extern const char *base64_encode(const char *decoded); Index: squid/lib/safe_inet_addr.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/safe_inet_addr.c,v retrieving revision 1.2 retrieving revision 1.2.6.1 diff -u -r1.2 -r1.2.6.1 --- squid/lib/safe_inet_addr.c 23 Oct 2000 15:04:19 -0000 1.2 +++ squid/lib/safe_inet_addr.c 7 Dec 2000 13:58:10 -0000 1.2.6.1 @@ -1,6 +1,6 @@ /* - * $Id: safe_inet_addr.c,v 1.2 2000/10/23 15:04:19 hno Exp $ + * $Id: safe_inet_addr.c,v 1.2.6.1 2000/12/07 13:58:10 rvenning Exp $ */ #include "config.h" @@ -63,3 +63,32 @@ addr->s_addr = A.s_addr; return 1; } + +int safe_inet_sockaddr(const char *buf, struct sockaddr_storage *addr) +{ + struct in6_addr inaddr6; + struct in_addr inaddr4; + + if (inet_pton(AF_INET6, buf, &inaddr6) != 0) { + struct sockaddr_in6 *saddr6p = (struct sockaddr_in6 *)addr; + saddr6p->sin6_family = AF_INET6; + saddr6p->sin6_addr = inaddr6; + return 1; + } else if (inet_aton(buf,&inaddr4) != 0) { + struct sockaddr_in *saddr4p = (struct sockaddr_in *)addr; + saddr4p->sin_family = AF_INET; + saddr4p->sin_addr = inaddr4; + return 1; + } + return 0; +} + + +#if INET6 +const char * inet6_ntoa(const struct in6_addr in) +{ + static char buff[INET6_ADDRSTRLEN]; + + return inet_ntop(AF_INET6, &in, buff, INET6_ADDRSTRLEN); +} +#endif Index: squid/src/access_log.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/access_log.c,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- squid/src/access_log.c 14 Nov 2000 13:03:47 -0000 1.5 +++ squid/src/access_log.c 7 Dec 2000 13:58:10 -0000 1.5.2.1 @@ -1,6 +1,6 @@ /* - * $Id: access_log.c,v 1.5 2000/11/14 13:03:47 adri Exp $ + * $Id: access_log.c,v 1.5.2.1 2000/12/07 13:58:10 rvenning Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -45,7 +45,7 @@ #if MULTICAST_MISS_STREAM static int mcast_miss_fd = -1; -static struct sockaddr_in mcast_miss_to; +static struct SOCKADDR_IN mcast_miss_to; static void mcast_encode(unsigned int *, size_t, const unsigned int *); #endif @@ -189,7 +189,7 @@ if (Config.onoff.log_fqdn) client = fqdncache_gethostbyaddr(al->cache.caddr, FQDN_LOOKUP_IF_MISS); if (client == NULL) - client = inet_ntoa(al->cache.caddr); + client = INET_NTOA(al->cache.caddr); logfilePrintf(logfile, "%9d.%03d %6d %s %s/%03d %d %s %s %s %s%s/%s %s", (int) current_time.tv_sec, (int) current_time.tv_usec / 1000, @@ -214,7 +214,7 @@ if (Config.onoff.log_fqdn) client = fqdncache_gethostbyaddr(al->cache.caddr, 0); if (client == NULL) - client = inet_ntoa(al->cache.caddr); + client = INET_NTOA(al->cache.caddr); logfilePrintf(logfile, "%s %s - [%s] \"%s %s HTTP/%d.%d\" %d %d %s:%s", client, al->cache.ident, @@ -339,13 +339,10 @@ #endif #if MULTICAST_MISS_STREAM if (Config.mcast_miss.addr.s_addr != no_addr.s_addr) { - memset(&mcast_miss_to, '\0', sizeof(mcast_miss_to)); - mcast_miss_to.sin_family = AF_INET; - mcast_miss_to.sin_port = htons(Config.mcast_miss.port); - mcast_miss_to.sin_addr.s_addr = Config.mcast_miss.addr.s_addr; + CLEAR_AND_SET(mcast_miss_to, Config.mcast_miss.port, Config.mcast_miss.addr); mcast_miss_fd = comm_open(SOCK_DGRAM, 0, - Config.Addrs.udp_incoming, + &Config.Addrs.udp_incoming, Config.mcast_miss.port, COMM_NONBLOCKING, "Multicast Miss Stream"); Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/acl.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/acl.c 7 Dec 2000 13:58:11 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: acl.c,v 1.4.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -58,7 +58,7 @@ static int aclMatchIntegerRange(intrange * data, int i); static int aclMatchTime(acl_time_data * data, time_t when); static int aclMatchUser(wordlist * data, const char *ident); -static int aclMatchIp(void *dataptr, struct in_addr c); +static int aclMatchIp(void *dataptr, struct IN_ADDR c); static int aclMatchDomainList(void *dataptr, const char *); static int aclMatchIntegerRange(intrange * data, int i); #if SQUID_SNMP @@ -95,7 +95,7 @@ #if USE_ARP_ACL static void aclParseArpList(void *curlist); static int decode_eth(const char *asc, char *eth); -static int aclMatchArp(void *dataptr, struct in_addr c); +static int aclMatchArp(void *dataptr, struct IN_ADDR c); static wordlist *aclDumpArpList(void *); static SPLAYCMP aclArpCompare; static SPLAYWALKEE aclDumpArpListWalkee; @@ -451,7 +451,7 @@ r = *Q = memAllocate(MEM_ACL_IP_DATA); xmemcpy(&r->addr1.s_addr, *x, sizeof(r->addr1.s_addr)); r->addr2.s_addr = 0; - r->mask.s_addr = no_addr.s_addr; /* 255.255.255.255 */ + r->mask.s_addr = INADDR_NONE; /* all ones IP */ Q = &r->next; debug(28, 3) ("%s --> %s\n", addr1, inet_ntoa(r->addr1)); } @@ -953,12 +953,12 @@ /**************/ static int -aclMatchIp(void *dataptr, struct in_addr c) +aclMatchIp(void *dataptr, struct IN_ADDR c) { splayNode **Top = dataptr; *Top = splay_splay(&c, *Top, aclIpNetworkCompare); debug(28, 3) ("aclMatchIp: '%s' %s\n", - inet_ntoa(c), splayLastResult ? "NOT found" : "found"); + INET_NTOA(c), splayLastResult ? "NOT found" : "found"); return !splayLastResult; } @@ -1133,7 +1133,7 @@ return -1; } else if ((0 == strcmp(auth_user->passwd, password)) && (auth_user->expiretime > current_time.tv_sec)) { - if (checklist->src_addr.s_addr == auth_user->ipaddr.s_addr + if (memcmp(&checklist->src_addr, &auth_user->ipaddr, sizeof(struct IN_ADDR)) == 0 || auth_user->ip_expiretime <= squid_curtime) { /* user already known and valid */ debug(28, 5) ("aclMatchProxyAuth: user '%s' previously validated\n", @@ -1352,7 +1352,7 @@ return aclMatchDomainList(&ae->data, fqdn); if (checklist->state[ACL_DST_DOMAIN] == ACL_LOOKUP_NONE) { debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - ae->name, inet_ntoa(ia->in_addrs[0])); + ae->name, INET_NTOA(ia->in_addrs[0])); checklist->state[ACL_DST_DOMAIN] = ACL_LOOKUP_NEEDED; return 0; } @@ -1364,7 +1364,7 @@ return aclMatchDomainList(&ae->data, fqdn); } else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NONE) { debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - ae->name, inet_ntoa(checklist->src_addr)); + ae->name, INET_NTOA(checklist->src_addr)); checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_NEEDED; return 0; } @@ -1378,7 +1378,7 @@ return aclMatchRegex(ae->data, fqdn); if (checklist->state[ACL_DST_DOMAIN] == ACL_LOOKUP_NONE) { debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - ae->name, inet_ntoa(ia->in_addrs[0])); + ae->name, INET_NTOA(ia->in_addrs[0])); checklist->state[ACL_DST_DOMAIN] = ACL_LOOKUP_NEEDED; return 0; } @@ -1390,7 +1390,7 @@ return aclMatchRegex(ae->data, fqdn); } else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NONE) { debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - ae->name, inet_ntoa(checklist->src_addr)); + ae->name, INET_NTOA(checklist->src_addr)); checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_NEEDED; return 0; } @@ -1512,6 +1512,7 @@ case ACL_SNMP_COMMUNITY: return aclMatchWordList(ae->data, checklist->snmp_community); #endif +#if !INET6 /* ** FIXME ** .... no ASN acls with IPv6 yet */ case ACL_SRC_ASN: return asnMatchIp(ae->data, checklist->src_addr); case ACL_DST_ASN: @@ -1530,6 +1531,7 @@ return asnMatchIp(ae->data, no_addr); } return 0; +#endif #if USE_ARP_ACL case ACL_SRC_ARP: return aclMatchArp(&ae->data, checklist->src_addr); @@ -2037,34 +2039,33 @@ */ /* compare an address and a network spec */ - static int aclIpNetworkCompare(const void *a, const void *b) { - struct in_addr A = *(const struct in_addr *) a; + struct IN_ADDR A = *(const struct IN_ADDR *) a; const acl_ip_data *q = b; - const struct in_addr B = q->addr1; - const struct in_addr C = q->addr2; - int rc = 0; - A.s_addr &= q->mask.s_addr; /* apply netmask */ - if (C.s_addr == 0) { /* single address check */ - if (ntohl(A.s_addr) > ntohl(B.s_addr)) - rc = 1; - else if (ntohl(A.s_addr) < ntohl(B.s_addr)) - rc = -1; - else - rc = 0; - } else { /* range address check */ - if (ntohl(A.s_addr) > ntohl(C.s_addr)) - rc = 1; - else if (ntohl(A.s_addr) < ntohl(B.s_addr)) - rc = -1; - else - rc = 0; + struct in_addr B; + struct in_addr C; + int i; + char *p1,*p2; + + B = q->addr1; + C = q->addr2; + /* apply netmask ** FIXME... review this ** */ + p1 = (char *)&A; + p2 = (char *)&q->mask; + for (i = 0; i < sizeof(struct IN_ADDR); i++) { + *(p1++) &= *(p2++); + } + + if (ADDR_IS_ANYADDR(C)) { + return memcmp(&A, &B, sizeof(struct IN_ADDR)); + } else { + return memcmp(&A, &C, sizeof(struct IN_ADDR)); } - return rc; } + static void aclDumpIpListWalkee(void *node, void *state) { @@ -2073,9 +2074,9 @@ wordlist **W = state; memBufDefInit(&mb); memBufPrintf(&mb, "%s", inet_ntoa(ip->addr1)); - if (ip->addr2.s_addr != any_addr.s_addr) + if (!ADDR_IS_ANYADDR(ip->addr2)) memBufPrintf(&mb, "-%s", inet_ntoa(ip->addr2)); - if (ip->mask.s_addr != no_addr.s_addr) + if (ip->mask.s_addr != INADDR_NONE) memBufPrintf(&mb, "/%s", inet_ntoa(ip->mask)); wordlistAdd(W, mb.buf); memBufClean(&mb); @@ -2386,11 +2387,11 @@ /* aclMatchArp */ /***************/ static int -aclMatchArp(void *dataptr, struct in_addr c) +aclMatchArp(void *dataptr, struct IN_ADDR c) { #if defined(_SQUID_LINUX_) struct arpreq arpReq; - struct sockaddr_in ipAddr; + struct SOCKADDR_IN ipAddr; unsigned char ifbuffer[sizeof(struct ifreq) * 64]; struct ifconf ifc; struct ifreq *ifr; @@ -2410,11 +2411,9 @@ /* * Set up structures for ARP lookup with blank interface name */ - ipAddr.sin_family = AF_INET; - ipAddr.sin_port = 0; - ipAddr.sin_addr = c; + CLEAR_AND_SET_SA(ipAddr, 0, c); memset(&arpReq, '\0', sizeof(arpReq)); - xmemcpy(&arpReq.arp_pa, &ipAddr, sizeof(struct sockaddr_in)); + xmemcpy(&arpReq.arp_pa, &ipAddr, sizeof(struct SOCKADDR_IN)); /* Query ARP table */ if (ioctl(HttpSockets[0], SIOCGARP, &arpReq) != -1) { /* Skip non-ethernet interfaces */ @@ -2428,7 +2427,7 @@ /* Do lookup */ *Top = splay_splay(&arpReq.arp_ha.sa_data, *Top, aclArpCompare); debug(28, 3) ("aclMatchArp: '%s' %s\n", - inet_ntoa(c), splayLastResult ? "NOT found" : "found"); + INET_NTOA(c), splayLastResult ? "NOT found" : "found"); return (0 == splayLastResult); } /* lookup list of interface names */ @@ -2453,14 +2452,12 @@ continue; if (NULL != strchr(ifr->ifr_name, ':')) continue; - debug(28, 4) ("Looking up ARP address for %s on %s\n", inet_ntoa(c), + debug(28, 4) ("Looking up ARP address for %s on %s\n", INET_NTOA(c), ifr->ifr_name); /* Set up structures for ARP lookup */ - ipAddr.sin_family = AF_INET; - ipAddr.sin_port = 0; - ipAddr.sin_addr = c; + CLEAR_AND_SET_SA(ipAddr, 0, c); memset(&arpReq, '\0', sizeof(arpReq)); - xmemcpy(&arpReq.arp_pa, &ipAddr, sizeof(struct sockaddr_in)); + xmemcpy(&arpReq.arp_pa, &ipAddr, sizeof(struct SOCKADDR_IN)); strncpy(arpReq.arp_dev, ifr->ifr_name, sizeof(arpReq.arp_dev) - 1); arpReq.arp_dev[sizeof(arpReq.arp_dev) - 1] = '\0'; /* Query ARP table */ @@ -2494,7 +2491,7 @@ /* Return if match, otherwise continue to other interfaces */ if (0 == splayLastResult) { debug(28, 3) ("aclMatchArp: %s found on %s\n", - inet_ntoa(c), ifr->ifr_name); + INET_NTOA(c), ifr->ifr_name); return 1; } /* @@ -2504,7 +2501,7 @@ } #elif defined(_SQUID_SOLARIS_) struct arpreq arpReq; - struct sockaddr_in ipAddr; + struct SOCKADDR_IN ipAddr; unsigned char ifbuffer[sizeof(struct ifreq) * 64]; struct ifconf ifc; struct ifreq *ifr; @@ -2513,11 +2510,9 @@ /* * Set up structures for ARP lookup with blank interface name */ - ipAddr.sin_family = AF_INET; - ipAddr.sin_port = 0; - ipAddr.sin_addr = c; + CLEAR_AND_SET_SA(ipAddr, 0, c); memset(&arpReq, '\0', sizeof(arpReq)); - xmemcpy(&arpReq.arp_pa, &ipAddr, sizeof(struct sockaddr_in)); + xmemcpy(&arpReq.arp_pa, &ipAddr, sizeof(struct SOCKADDR_IN)); /* Query ARP table */ if (ioctl(HttpSockets[0], SIOCGARP, &arpReq) != -1) { /* @@ -2538,7 +2533,7 @@ /* Do lookup */ *Top = splay_splay(&arpReq.arp_ha.sa_data, *Top, aclArpCompare); debug(28, 3) ("aclMatchArp: '%s' %s\n", - inet_ntoa(c), splayLastResult ? "NOT found" : "found"); + INET_NTOA(c), splayLastResult ? "NOT found" : "found"); return (0 == splayLastResult); } #else @@ -2547,7 +2542,7 @@ /* * Address was not found on any interface */ - debug(28, 3) ("aclMatchArp: %s NOT found\n", inet_ntoa(c)); + debug(28, 3) ("aclMatchArp: %s NOT found\n", INET_NTOA(c)); return 0; } Index: squid/src/asn.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/asn.c,v retrieving revision 1.4 retrieving revision 1.4.4.1 diff -u -r1.4 -r1.4.4.1 --- squid/src/asn.c 9 Nov 2000 09:09:40 -0000 1.4 +++ squid/src/asn.c 7 Dec 2000 13:58:11 -0000 1.4.4.1 @@ -1,6 +1,6 @@ /* - * $Id: asn.c,v 1.4 2000/11/09 09:09:40 hno Exp $ + * $Id: asn.c,v 1.4.4.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 53 AS Number handling * AUTHOR: Duane Wessels, Kostas Anagnostakis @@ -112,9 +112,9 @@ if (AS_tree_head == NULL) return 0; - if (addr.s_addr == no_addr.s_addr) + if (ADDR_IS_NOADDR(addr)) return 0; - if (addr.s_addr == any_addr.s_addr) + if (ADDR_IS_ANYADDR(addr)) return 0; store_m_int(lh, m_addr); rn = rn_match(m_addr, AS_tree_head); Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cache_cf.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- squid/src/cache_cf.c 18 Nov 2000 11:01:27 -0000 1.4 +++ squid/src/cache_cf.c 7 Dec 2000 13:58:11 -0000 1.4.2.1 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.4 2000/11/18 11:01:27 adri Exp $ + * $Id: cache_cf.c,v 1.4.2.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -325,7 +325,7 @@ fatal("No http_port specified!"); snprintf(ThisCache, sizeof(ThisCache), "%s:%d (%s)", uniqueHostname(), - (int) ntohs(Config.Sockaddr.http->s.sin_port), + (int) ntohs(PORT_FROM_SA(Config.Sockaddr.http->s)), full_appname_string); /* * the extra space is for loop detection in client_side.c -- we search @@ -333,7 +333,7 @@ */ snprintf(ThisCache2, sizeof(ThisCache), " %s:%d (%s)", uniqueHostname(), - (int) ntohs(Config.Sockaddr.http->s.sin_port), + (int) ntohs(PORT_FROM_SA(Config.Sockaddr.http->s)), full_appname_string); if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF) Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF; @@ -576,20 +576,20 @@ } static void -dump_address(StoreEntry * entry, const char *name, struct in_addr addr) +dump_address(StoreEntry * entry, const char *name, struct IN_ADDR addr) { - storeAppendPrintf(entry, "%s %s\n", name, inet_ntoa(addr)); + storeAppendPrintf(entry, "%s %s\n", name, INET_NTOA(addr)); } static void -parse_address(struct in_addr *addr) +parse_address(struct IN_ADDR *addr) { const struct hostent *hp; char *token = strtok(NULL, w_space); if (token == NULL) self_destruct(); - if (safe_inet_addr(token, addr) == 1) + if (SAFE_INET_ADDR(token, addr) == 1) (void) 0; else if ((hp = gethostbyname(token))) /* dont use ipcache */ *addr = inaddrFromHostent(hp); @@ -598,9 +598,9 @@ } static void -free_address(struct in_addr *addr) +free_address(struct IN_ADDR *addr) { - memset(addr, '\0', sizeof(struct in_addr)); + memset(addr, '\0', sizeof(struct IN_ADDR)); } #if DELAY_POOLS @@ -1047,7 +1047,7 @@ p->icp.port = (u_short) i; if (strcmp(p->host, me) == 0) { for (s = Config.Sockaddr.http; s; s = s->next) { - if (p->http_port != ntohs(s->s.sin_port)) + if (p->http_port != ntohs(PORT_FROM_SA(s->s))) continue; debug(15, 1) ("parse_peer: Peer looks like myself: Ignoring %s %s/%d/%d\n", neighborTypeStr(p), p->host, p->http_port, p->icp.port); @@ -1809,13 +1809,13 @@ self_destruct(); } s = xcalloc(1, sizeof(*s)); - s->s.sin_port = htons(port); + PORT_FROM_SA(s->s) = htons(port); if (NULL == host) - s->s.sin_addr = any_addr; - else if (1 == safe_inet_addr(host, &s->s.sin_addr)) + ADDR_FROM_SA(s->s) = INADDR_ANY_ASSIGN; + else if (1 == SAFE_INET_ADDR(host, &ADDR_FROM_SA(s->s))) (void) 0; else if ((hp = gethostbyname(host))) /* dont use ipcache */ - s->s.sin_addr = inaddrFromHostent(hp); + ADDR_FROM_SA(s->s) = inaddrFromHostent(hp); else self_destruct(); while (*head) @@ -1830,8 +1830,8 @@ while (s) { storeAppendPrintf(e, "%s %s:%d\n", n, - inet_ntoa(s->s.sin_addr), - ntohs(s->s.sin_port)); + SA_NTOA(s->s), + ntohs(PORT_FROM_SA(s->s))); s = s->next; } } Index: squid/src/cachemgr.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/cachemgr.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/cachemgr.c 23 Oct 2000 15:04:20 -0000 1.3 +++ squid/src/cachemgr.c 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: cachemgr.c,v 1.3 2000/10/23 15:04:20 hno Exp $ + * $Id: cachemgr.c,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 0 CGI Cache Manager * AUTHOR: Duane Wessels @@ -128,6 +128,7 @@ #include "util.h" #include "snprintf.h" +#include "defines.h" typedef struct { char *hostname; @@ -147,6 +148,7 @@ /* debugging level 0 (disabled) - 3 (max) */ #define DEBUG_LEVEL 0 +#undef debug #define debug(level) if ((level) <= DEBUG_LEVEL && DEBUG_LEVEL > 0) /* @@ -156,11 +158,12 @@ static const char *script_name = "/cgi-bin/cachemgr.cgi"; static const char *progname = NULL; static time_t now; -static struct in_addr no_addr; +static struct IN_ADDR no_addr; /* * Function prototypes */ +#undef safe_free #define safe_free(str) { if (str) { xfree(str); (str) = NULL; } } static const char *safe_str(const char *str); static char *xstrtok(char **str, char del); @@ -504,7 +507,7 @@ process_request(cachemgr_request * req) { const struct hostent *hp; - static struct sockaddr_in S; + static struct SOCKADDR_IN S; int s; int l; static char buf[2 * 1024]; @@ -530,19 +533,19 @@ error_html(buf); return 1; } - memset(&S, '\0', sizeof(struct sockaddr_in)); - S.sin_family = AF_INET; + memset(&S, '\0', sizeof(struct SOCKADDR_IN)); + FAMILY_FROM_SA(S) = AF_FAMILY; if ((hp = gethostbyname(req->hostname)) != NULL) - xmemcpy(&S.sin_addr.s_addr, hp->h_addr, hp->h_length); - else if (safe_inet_addr(req->hostname, &S.sin_addr)) + xmemcpy(&ADDR_FROM_SA(S), hp->h_addr, hp->h_length); + else if (SAFE_INET_ADDR(req->hostname, &ADDR_FROM_SA(S))) (void) 0; else { snprintf(buf, 1024, "Unknown host: %s\n", req->hostname); error_html(buf); return 1; } - S.sin_port = htons(req->port); - if (connect(s, (struct sockaddr *) &S, sizeof(struct sockaddr_in)) < 0) { + PORT_FROM_SA(S) = htons(req->port); + if (connect(s, (struct sockaddr *) &S, sizeof(struct SOCKADDR_IN)) < 0) { snprintf(buf, 1024, "connect: %s\n", xstrerror()); error_html(buf); return 1; @@ -565,7 +568,7 @@ { char *s; cachemgr_request *req; - safe_inet_addr("255.255.255.255", &no_addr); + memset(&no_addr, '\xFF', sizeof(no_addr)); now = time(NULL); if ((s = strrchr(argv[0], '/'))) progname = xstrdup(s + 1); Index: squid/src/client.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/client.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/client.c 23 Oct 2000 15:04:20 -0000 1.3 +++ squid/src/client.c 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: client.c,v 1.3 2000/10/23 15:04:20 hno Exp $ + * $Id: client.c,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived @@ -358,40 +358,40 @@ client_comm_bind(int sock, char *local_host) { static const struct hostent *hp = NULL; - static struct sockaddr_in from_addr; + static struct SOCKADDR_IN from_addr; /* Set up the source socket address from which to send. */ if (hp == NULL) { - from_addr.sin_family = AF_INET; + FAMILY_FROM_SA(from_addr) = AF_FAMILY; - if ((hp = gethostbyname(local_host)) == 0) { + if ((hp = gethostbyname(local_host)) == 0) return (-1); - } - xmemcpy(&from_addr.sin_addr, hp->h_addr, hp->h_length); - from_addr.sin_port = 0; + + xmemcpy(&ADDR_FROM_SA(from_addr), hp->h_addr, hp->h_length); + PORT_FROM_SA(from_addr) = 0; } - return bind(sock, (struct sockaddr *) &from_addr, sizeof(struct sockaddr_in)); + return bind(sock, (struct sockaddr *) &from_addr, sizeof(struct SOCKADDR_IN)); } static int client_comm_connect(int sock, char *dest_host, u_short dest_port, struct timeval *tvp) { static const struct hostent *hp = NULL; - static struct sockaddr_in to_addr; + static struct SOCKADDR_IN to_addr; /* Set up the destination socket address for message to send to. */ if (hp == NULL) { - to_addr.sin_family = AF_INET; + FAMILY_FROM_SA(to_addr) = AF_FAMILY; if ((hp = gethostbyname(dest_host)) == 0) { return (-1); } - xmemcpy(&to_addr.sin_addr, hp->h_addr, hp->h_length); - to_addr.sin_port = htons(dest_port); + xmemcpy(&ADDR_FROM_SA(to_addr), hp->h_addr, hp->h_length); + PORT_FROM_SA(to_addr) = htons(dest_port); } if (tvp) (void) Now(tvp); - return connect(sock, (struct sockaddr *) &to_addr, sizeof(struct sockaddr_in)); + return connect(sock, (struct sockaddr *) &to_addr, sizeof(struct SOCKADDR_IN)); } static int Index: squid/src/client_db.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_db.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/client_db.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/client_db.c 7 Dec 2000 13:58:11 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: client_db.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: client_db.c,v 1.4.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 0 Client Database * AUTHOR: Duane Wessels @@ -36,15 +36,15 @@ #include "squid.h" static hash_table *client_table = NULL; -static ClientInfo *clientdbAdd(struct in_addr addr); +static ClientInfo *clientdbAdd(struct IN_ADDR addr); static FREE clientdbFreeItem; static ClientInfo * -clientdbAdd(struct in_addr addr) +clientdbAdd(struct IN_ADDR addr) { ClientInfo *c; c = memAllocate(MEM_CLIENT_INFO); - c->hash.key = xstrdup(inet_ntoa(addr)); + c->hash.key = xstrdup(INET_NTOA(addr)); c->addr = addr; hash_join(client_table, &c->hash); statCounter.client_http.clients++; @@ -64,13 +64,13 @@ } void -clientdbUpdate(struct in_addr addr, log_type ltype, protocol_t p, size_t size) +clientdbUpdate(struct IN_ADDR addr, log_type ltype, protocol_t p, size_t size) { char *key; ClientInfo *c; if (!Config.onoff.client_db) return; - key = inet_ntoa(addr); + key = INET_NTOA(addr); c = (ClientInfo *) hash_lookup(client_table, key); if (c == NULL) c = clientdbAdd(addr); @@ -99,13 +99,13 @@ * -1. To get the current value, simply call with delta = 0. */ int -clientdbEstablished(struct in_addr addr, int delta) +clientdbEstablished(struct IN_ADDR addr, int delta) { char *key; ClientInfo *c; if (!Config.onoff.client_db) return 0; - key = inet_ntoa(addr); + key = INET_NTOA(addr); c = (ClientInfo *) hash_lookup(client_table, key); if (c == NULL) c = clientdbAdd(addr); @@ -117,7 +117,7 @@ #define CUTOFF_SECONDS 3600 int -clientdbCutoffDenied(struct in_addr addr) +clientdbCutoffDenied(struct IN_ADDR addr) { char *key; int NR; @@ -126,7 +126,7 @@ ClientInfo *c; if (!Config.onoff.client_db) return 0; - key = inet_ntoa(addr); + key = INET_NTOA(addr); c = (ClientInfo *) hash_lookup(client_table, key); if (c == NULL) return 0; @@ -227,13 +227,13 @@ } #if SQUID_SNMP -struct in_addr * -client_entry(struct in_addr *current) +struct IN_ADDR * +client_entry(struct IN_ADDR *current) { ClientInfo *c = NULL; char *key; if (current) { - key = inet_ntoa(*current); + key = INET_NTOA(*current); hash_first(client_table); while ((c = (ClientInfo *) hash_next(client_table))) { if (!strcmp(key, hashKeyStr(&c->hash))) Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -u -r1.7 -r1.7.2.1 --- squid/src/client_side.c 18 Nov 2000 11:01:27 -0000 1.7 +++ squid/src/client_side.c 7 Dec 2000 13:58:11 -0000 1.7.2.1 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.7 2000/11/18 11:01:27 adri Exp $ + * $Id: client_side.c,v 1.7.2.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -257,7 +257,7 @@ } err = errorCon(page_id, status); err->request = requestLink(http->request); - err->src_addr = http->conn->peer.sin_addr; + err->src_addr = ADDR_FROM_SA(http->conn->peer); errorAppendEntry(http->entry, err); } } @@ -581,7 +581,7 @@ http->log_type = LOG_TCP_DENIED; err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN); err->request = requestLink(http->request); - err->src_addr = http->conn->peer.sin_addr; + err->src_addr = ADDR_FROM_SA(http->conn->peer); http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags); errorAppendEntry(http->entry, err); return; @@ -745,7 +745,7 @@ } accessLogLog(&http->al); clientUpdateCounters(http); - clientdbUpdate(conn->peer.sin_addr, http->log_type, PROTO_HTTP, http->out.size); + clientdbUpdate(ADDR_FROM_SA(conn->peer), http->log_type, PROTO_HTTP, http->out.size); } if (http->acl_checklist) aclChecklistFree(http->acl_checklist); @@ -795,7 +795,7 @@ clientHttpRequest *http; debug(33, 3) ("connStateFree: FD %d\n", fd); assert(connState != NULL); - clientdbEstablished(connState->peer.sin_addr, -1); /* decrement */ + clientdbEstablished(ADDR_FROM_SA(connState->peer), -1); /* decrement */ while ((http = connState->chr) != NULL) { assert(http->conn == connState); assert(connState->chr != connState->chr->next); @@ -879,11 +879,11 @@ } #if USE_USERAGENT_LOG if ((str = httpHeaderGetStr(req_hdr, HDR_USER_AGENT))) - logUserAgent(fqdnFromAddr(http->conn->peer.sin_addr), str); + logUserAgent(fqdnFromAddr(ADDR_FROM_SA(http->conn->peer)), str); #endif #if USE_REFERER_LOG if ((str = httpHeaderGetStr(req_hdr, HDR_REFERER))) - logReferer(fqdnFromAddr(http->conn->peer.sin_addr), str, + logReferer(fqdnFromAddr(ADDR_FROM_SA(http->conn->peer)), str, http->log_uri); #endif #if FORW_VIA_DB @@ -1250,7 +1250,7 @@ /* Append X-Cache-Lookup: -- temporary hack, to be removed @?@ @?@ */ httpHeaderPutStrf(hdr, HDR_X_CACHE_LOOKUP, "%s from %s:%d", http->lookup_type ? http->lookup_type : "NONE", - getMyHostname(), ntohs(Config.Sockaddr.http->s.sin_port)); + getMyHostname(), ntohs(PORT_FROM_SA(Config.Sockaddr.http->s))); #endif if (httpReplyBodySize(request->method, rep) < 0) { debug(33, 3) ("clientBuildReplyHeader: can't keep-alive, unknown body size\n"); @@ -1940,7 +1940,7 @@ http->al.http.code = HTTP_GATEWAY_TIMEOUT; err = errorCon(ERR_ONLY_IF_CACHED_MISS, HTTP_GATEWAY_TIMEOUT); err->request = requestLink(r); - err->src_addr = http->conn->peer.sin_addr; + err->src_addr = ADDR_FROM_SA(http->conn->peer); if (http->entry) { storeUnregister(http->sc, http->entry, http); http->sc = NULL; @@ -2177,7 +2177,7 @@ http->al.http.code = HTTP_FORBIDDEN; err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN); err->request = requestLink(r); - err->src_addr = http->conn->peer.sin_addr; + err->src_addr = ADDR_FROM_SA(http->conn->peer); http->entry = clientCreateStoreEntry(http, r->method, null_request_flags); errorAppendEntry(http->entry, err); return; @@ -2396,14 +2396,14 @@ url_sz = strlen(url) + 32 + Config.appendDomainLen; http->uri = xcalloc(url_sz, 1); if (vport_mode) - vport = (int) ntohs(http->conn->me.sin_port); + vport = (int) ntohs(PORT_FROM_SA(http->conn->me)); else vport = (int) Config.Accel.port; #if IPF_TRANSPARENT - natLookup.nl_inport = http->conn->me.sin_port; - natLookup.nl_outport = http->conn->peer.sin_port; - natLookup.nl_inip = http->conn->me.sin_addr; - natLookup.nl_outip = http->conn->peer.sin_addr; + natLookup.nl_inport = PORT_FROM_SA(http->conn->me); + natLookup.nl_outport = PORT_FROM_SA(http->conn->peer); + natLookup.nl_inip = ADDR_FROM_SA(http->conn->me); + natLookup.nl_outip = ADDR_FROM_SA(http->conn->peer); natLookup.nl_flags = IPN_TCP; if (natfd < 0) natfd = open(IPL_NAT, O_RDONLY, 0); @@ -2433,7 +2433,7 @@ return parseHttpRequestAbort(conn, "error:nat-lookup-failed"); } else snprintf(http->uri, url_sz, "http://%s:%d%s", - inet_ntoa(http->conn->me.sin_addr), + SA_NTOA(http->conn->me), vport, url); } else snprintf(http->uri, url_sz, "http://%s:%d%s", @@ -2441,7 +2441,7 @@ vport, url); #else snprintf(http->uri, url_sz, "http://%s:%d%s", - inet_ntoa(http->conn->me.sin_addr), + SA_NTOA(http->conn->me), vport, url); #endif debug(33, 5) ("VHOST REWRITE: '%s'\n", http->uri); @@ -2601,7 +2601,7 @@ if ((request = urlParse(method, http->uri)) == NULL) { debug(33, 5) ("Invalid URL: %s\n", http->uri); err = errorCon(ERR_INVALID_URL, HTTP_BAD_REQUEST); - err->src_addr = conn->peer.sin_addr; + err->src_addr = ADDR_FROM_SA(conn->peer); err->url = xstrdup(http->uri); http->al.http.code = err->http_status; http->entry = clientCreateStoreEntry(http, method, null_request_flags); @@ -2620,11 +2620,11 @@ if (!http->flags.internal) { if (internalCheck(strBuf(request->urlpath))) { if (internalHostnameIs(request->host) && - request->port == ntohs(Config.Sockaddr.http->s.sin_port)) { + request->port == ntohs(PORT_FROM_SA(Config.Sockaddr.http->s))) { http->flags.internal = 1; } else if (internalStaticCheck(strBuf(request->urlpath))) { xstrncpy(request->host, internalHostname(), SQUIDHOSTNAMELEN); - request->port = ntohs(Config.Sockaddr.http->s.sin_port); + request->port = ntohs(PORT_FROM_SA(Config.Sockaddr.http->s)); http->flags.internal = 1; } } @@ -2638,13 +2638,13 @@ safe_free(prefix); safe_free(http->log_uri); http->log_uri = xstrdup(urlCanonicalClean(request)); - request->client_addr = conn->peer.sin_addr; - request->my_addr = conn->me.sin_addr; - request->my_port = ntohs(conn->me.sin_port); + request->client_addr = ADDR_FROM_SA(conn->peer); + request->my_addr = ADDR_FROM_SA(conn->me); + request->my_port = ntohs(PORT_FROM_SA(conn->me)); request->http_ver = http->http_ver; if (!urlCheckRequest(request)) { err = errorCon(ERR_UNSUP_REQ, HTTP_NOT_IMPLEMENTED); - err->src_addr = conn->peer.sin_addr; + err->src_addr = ADDR_FROM_SA(conn->peer); err->request = requestLink(request); request->flags.proxy_keepalive = 0; http->al.http.code = err->http_status; @@ -2654,7 +2654,7 @@ } if (0 == clientCheckContentLength(request)) { err = errorCon(ERR_INVALID_REQ, HTTP_LENGTH_REQUIRED); - err->src_addr = conn->peer.sin_addr; + err->src_addr = ADDR_FROM_SA(conn->peer); err->request = requestLink(request); http->al.http.code = err->http_status; http->entry = clientCreateStoreEntry(http, request->method, null_request_flags); @@ -2806,7 +2806,7 @@ clientHttpRequest *http = data; ConnStateData *conn = http->conn; debug(33, 1) ("WARNING: Closing client %s connection due to lifetime timeout\n", - inet_ntoa(conn->peer.sin_addr)); + SA_NTOA(conn->peer)); debug(33, 1) ("\t%s\n", http->uri); comm_close(fd); } @@ -2831,16 +2831,16 @@ int *N = data; int fd = -1; ConnStateData *connState = NULL; - struct sockaddr_in peer; - struct sockaddr_in me; + struct SOCKADDR_IN peer; + struct SOCKADDR_IN me; int max = INCOMING_HTTP_MAX; #if USE_IDENT static aclCheck_t identChecklist; #endif commSetSelect(sock, COMM_SELECT_READ, httpAccept, NULL, 0); while (max-- && !httpAcceptDefer(sock, NULL)) { - memset(&peer, '\0', sizeof(struct sockaddr_in)); - memset(&me, '\0', sizeof(struct sockaddr_in)); + memset(&peer, '\0', sizeof(peer)); + memset(&me, '\0', sizeof(me)); if ((fd = comm_accept(sock, &peer, &me)) < 0) { if (!ignoreErrno(errno)) debug(50, 1) ("httpAccept: FD %d: accept failure: %s\n", @@ -2851,8 +2851,9 @@ connState = memAllocate(MEM_CONNSTATEDATA); cbdataAdd(connState, memFree, MEM_CONNSTATEDATA); connState->peer = peer; - connState->log_addr = peer.sin_addr; - connState->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr; + connState->log_addr = ADDR_FROM_SA(peer); + /* connState->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr; */ + /* ** FIXME ** */ connState->me = me; connState->fd = fd; connState->in.size = CLIENT_REQ_BUF_SZ; @@ -2860,18 +2861,18 @@ /* XXX account connState->in.buf */ comm_add_close_handler(fd, connStateFree, connState); if (Config.onoff.log_fqdn) - fqdncache_gethostbyaddr(peer.sin_addr, FQDN_LOOKUP_IF_MISS); + fqdncache_gethostbyaddr(ADDR_FROM_SA(peer), FQDN_LOOKUP_IF_MISS); commSetTimeout(fd, Config.Timeout.request, requestTimeout, connState); #if USE_IDENT - identChecklist.src_addr = peer.sin_addr; - identChecklist.my_addr = me.sin_addr; - identChecklist.my_port = ntohs(me.sin_port); + identChecklist.src_addr = ADDR_FROM_SA(peer); + identChecklist.my_addr = ADDR_FROM_SA(me); + identChecklist.my_port = ntohs(PORT_FROM_SA(me)); if (aclCheckFast(Config.accessList.identLookup, &identChecklist)) identStart(&me, &peer, clientIdentDone, connState); #endif commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, connState, 0); commSetDefer(fd, clientReadDefer, connState); - clientdbEstablished(peer.sin_addr, 1); + clientdbEstablished(ADDR_FROM_SA(peer), 1); assert(N); (*N)++; } @@ -3015,8 +3016,8 @@ enter_suid(); fd = comm_open(SOCK_STREAM, 0, - s->s.sin_addr, - ntohs(s->s.sin_port), + ADDR_FROM_SA(s->s), + ntohs(PORT_FROM_SA(s->s)), COMM_NONBLOCKING, "HTTP Socket"); leave_suid(); @@ -3030,8 +3031,8 @@ */ commSetDefer(fd, httpAcceptDefer, NULL); debug(1, 1) ("Accepting HTTP connections at %s, port %d, FD %d.\n", - inet_ntoa(s->s.sin_addr), - (int) ntohs(s->s.sin_port), + INET_NTOA(ADDR_FROM_SA(s->s)), + (int) ntohs(PORT_FROM_SA(s->s)), fd); HttpSockets[NHttpSockets++] = fd; } Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/comm.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/comm.c 7 Dec 2000 13:58:11 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: comm.c,v 1.4.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -42,10 +42,10 @@ typedef struct { char *host; u_short port; - struct sockaddr_in S; + struct SOCKADDR_IN S; CNCB *callback; void *data; - struct in_addr in_addr; + struct IN_ADDR in_addr; int locks; int fd; int tries; @@ -54,7 +54,7 @@ } ConnectStateData; /* STATIC */ -static int commBind(int s, struct in_addr, u_short port); +static int commBind(int s, struct IN_ADDR *, u_short port); static void commSetReuseAddr(int); static void commSetNoLinger(int); static void CommWriteStateCallbackAndFree(int fd, int code); @@ -104,7 +104,7 @@ u_short comm_local_port(int fd) { - struct sockaddr_in addr; + struct SOCKADDR_IN addr; socklen_t addr_len = 0; fde *F = &fd_table[fd]; @@ -120,26 +120,23 @@ debug(50, 1) ("comm_local_port: Failed to retrieve TCP/UDP port number for socket: FD %d: %s\n", fd, xstrerror()); return 0; } - F->local_port = ntohs(addr.sin_port); + F->local_port = ntohs(PORT_FROM_SA(addr)); debug(5, 6) ("comm_local_port: FD %d: port %d\n", fd, (int) F->local_port); return F->local_port; } static int -commBind(int s, struct in_addr in_addr, u_short port) +commBind(int s, struct IN_ADDR * in_addr, u_short port) { - struct sockaddr_in S; + struct SOCKADDR_IN S; - memset(&S, '\0', sizeof(S)); - S.sin_family = AF_INET; - S.sin_port = htons(port); - S.sin_addr = in_addr; + CLEAR_AND_SET_SA(S, port, *in_addr); statCounter.syscalls.sock.binds++; if (bind(s, (struct sockaddr *) &S, sizeof(S)) == 0) return COMM_OK; debug(50, 0) ("commBind: Cannot bind socket FD %d to %s:%d: %s\n", s, - S.sin_addr.s_addr == INADDR_ANY ? "*" : inet_ntoa(S.sin_addr), + SA_IS_ANYADDR(S) ? "*" : SA_NTOA(S), (int) port, xstrerror()); return COMM_ERROR; @@ -150,7 +147,7 @@ int comm_open(int sock_type, int proto, - struct in_addr addr, + struct IN_ADDR addr, u_short port, int flags, const char *note) @@ -160,7 +157,7 @@ /* Create socket for accepting new connections. */ statCounter.syscalls.sock.sockets++; - if ((new_socket = socket(AF_INET, sock_type, proto)) < 0) { + if ((new_socket = socket(AF_FAMILY, sock_type, proto)) < 0) { /* Increase the number of reserved fd's if calls to socket() * are failing because the open file table is full. This * limits the number of simultaneous clients */ @@ -188,8 +185,8 @@ if (opt_reuseaddr) commSetReuseAddr(new_socket); } - if (addr.s_addr != no_addr.s_addr) { - if (commBind(new_socket, addr, port) != COMM_OK) { + if (!ADDR_IS_NOADDR(addr)) { + if (commBind(new_socket, &addr, port) != COMM_OK) { comm_close(new_socket); return -1; } @@ -310,7 +307,7 @@ if (!cbdataValid(cs->data)) return 0; statCounter.syscalls.sock.sockets++; - fd2 = socket(AF_INET, SOCK_STREAM, 0); + fd2 = socket(AF_FAMILY, SOCK_STREAM, 0); statCounter.syscalls.sock.sockets++; if (fd2 < 0) { debug(5, 0) ("commResetFD: socket: %s\n", xstrerror()); @@ -331,8 +328,8 @@ * the original socket */ commSetCloseOnExec(cs->fd); - if (Config.Addrs.tcp_outgoing.s_addr != no_addr.s_addr) { - if (commBind(cs->fd, Config.Addrs.tcp_outgoing, 0) != COMM_OK) { + if (!ADDR_IS_NOADDR(Config.Addrs.tcp_outgoing)) { + if (commBind(cs->fd, &Config.Addrs.tcp_outgoing, 0) != COMM_OK) { return 0; } } @@ -366,12 +363,10 @@ commConnectHandle(int fd, void *data) { ConnectStateData *cs = data; - if (cs->S.sin_addr.s_addr == 0) { - cs->S.sin_family = AF_INET; - cs->S.sin_addr = cs->in_addr; - cs->S.sin_port = htons(cs->port); + if (SA_IS_ANYADDR(cs->S)) { + CLEAR_AND_SET_SA(cs->S, cs->port, cs->in_addr); if (Config.onoff.log_fqdn) - fqdncache_gethostbyaddr(cs->S.sin_addr, FQDN_LOOKUP_IF_MISS); + fqdncache_gethostbyaddr(ADDR_FROM_SA(cs->S), FQDN_LOOKUP_IF_MISS); } switch (comm_connect_addr(fd, &cs->S)) { case COMM_INPROGRESS: @@ -379,14 +374,14 @@ commSetSelect(fd, COMM_SELECT_WRITE, commConnectHandle, cs, 0); break; case COMM_OK: - ipcacheMarkGoodAddr(cs->host, cs->S.sin_addr); + ipcacheMarkGoodAddr(cs->host, ADDR_FROM_SA(cs->S)); commConnectCallback(cs, COMM_OK); break; default: cs->tries++; - ipcacheMarkBadAddr(cs->host, cs->S.sin_addr); + ipcacheMarkBadAddr(cs->host, ADDR_FROM_SA(cs->S)); if (Config.onoff.test_reachability) - netdbDeleteAddrNetwork(cs->S.sin_addr); + netdbDeleteAddrNetwork(ADDR_FROM_SA(cs->S)); if (commRetryConnect(cs)) { cs->locks++; ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs); @@ -420,14 +415,14 @@ } int -comm_connect_addr(int sock, const struct sockaddr_in *address) +comm_connect_addr(int sock, const struct SOCKADDR_IN *address) { int status = COMM_OK; fde *F = &fd_table[sock]; int x; int err = 0; socklen_t errlen; - assert(ntohs(address->sin_port) != 0); + assert(ntohs(PORT_FROM_SA(*address)) != 0); /* Establish connection. */ errno = 0; if (!F->flags.called_connect) { @@ -469,8 +464,8 @@ status = COMM_INPROGRESS; else return COMM_ERROR; - xstrncpy(F->ipaddr, inet_ntoa(address->sin_addr), 16); - F->remote_port = ntohs(address->sin_port); + xstrncpy(F->ipaddr, SA_NTOA(*address), MAXIPSTRLEN); + F->remote_port = ntohs(PORT_FROM_SA(*address)); if (status == COMM_OK) { debug(5, 10) ("comm_connect_addr: FD %d connected to %s:%d\n", sock, F->ipaddr, F->remote_port); @@ -483,11 +478,11 @@ /* Wait for an incoming connection on FD. FD should be a socket returned * from comm_listen. */ int -comm_accept(int fd, struct sockaddr_in *pn, struct sockaddr_in *me) +comm_accept(int fd, struct SOCKADDR_IN *pn, struct SOCKADDR_IN *me) { int sock; - struct sockaddr_in P; - struct sockaddr_in M; + struct SOCKADDR_IN P; + struct SOCKADDR_IN M; socklen_t Slen; fde *F = NULL; Slen = sizeof(P); @@ -515,9 +510,9 @@ /* fdstat update */ fd_open(sock, FD_SOCKET, "HTTP Request"); F = &fd_table[sock]; - xstrncpy(F->ipaddr, inet_ntoa(P.sin_addr), 16); - F->remote_port = htons(P.sin_port); - F->local_port = htons(M.sin_port); + xstrncpy(F->ipaddr, SA_NTOA(P), MAXIPSTRLEN); + F->remote_port = htons(PORT_FROM_SA(P)); + F->local_port = htons(PORT_FROM_SA(M)); commSetNonBlocking(sock); return sock; } @@ -600,7 +595,7 @@ /* Send a udp datagram to specified TO_ADDR. */ int comm_udp_sendto(int fd, - const struct sockaddr_in *to_addr, + const struct SOCKADDR_IN *to_addr, int addr_len, const void *buf, int len) @@ -614,8 +609,8 @@ #endif debug(50, 1) ("comm_udp_sendto: FD %d, %s, port %d: %s\n", fd, - inet_ntoa(to_addr->sin_addr), - (int) htons(to_addr->sin_port), + SA_NTOA(*to_addr), + (int) htons(PORT_FROM_SA(*to_addr)), xstrerror()); return COMM_ERROR; } Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/defines.h 23 Oct 2000 15:04:20 -0000 1.3 +++ squid/src/defines.h 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.3 2000/10/23 15:04:20 hno Exp $ + * $Id: defines.h,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -281,3 +281,89 @@ #ifndef _PATH_DEVNULL #define _PATH_DEVNULL "/dev/null" #endif + +#if INET6 +#define SOCKADDR_IN sockaddr_in6 +#define IN_ADDR in6_addr +#define INADDR_ANY_ASSIGN in6addr_any +#define INADDR_ANY_INIT IN6ADR_ANY_INIT +#define AF_FAMILY AF_INET6 +#define PF_FAMILY PF_INET6 +#define MAXIPSTRLEN INET6_ADDRSTRLEN /* 46 */ + +#define CLEAR_AND_SET_SA(S, port, in_addr) \ + memset(&(S), '\0', sizeof(S)); \ + (S).sin6_family = AF_FAMILY; \ + (S).sin6_port = htons(port); \ + (S).sin6_addr = in_addr; + +#define SA_IS_ANYADDR(s) \ + (memcmp(&(s).sin6_addr, &in6addr_any, sizeof(in6addr_any)) == 0) + +#define ADDR_IS_NOADDR(s) \ + (memcmp(&(s), &no_addr, sizeof(no_addr)) == 0) + +#define ADDR_IS_ANYADDR(s) \ + (memcmp(&(s), &in6addr_any, sizeof(in6addr_any)) == 0) + +#define SA_NTOA(s) \ + inet6_ntoa((s).sin6_addr) + +#define INET_NTOA(s) \ + inet6_ntoa(s) + +#define ADDR_FROM_SA(s) \ + ((s).sin6_addr) +#define PORT_FROM_SA(s) \ + ((s).sin6_port) +#define FAMILY_FROM_SA(s) \ + ((s).sin6_family) + +#define SAFE_INET_ADDR(host, addr) \ + inet_pton(AF_INET, host, addr) + +#else +#define SOCKADDR_IN sockaddr_in +#define IN_ADDR in_addr +#define INADDR_ANY_ASSIGN any_addr +#define INADDR_ANY_INIT htonl(INADDR_ANY) +#define AF_FAMILY AF_INET +#define PF_FAMILY PF_INET +#define MAXIPSTRLEN 16 +#define CLEAR_AND_SET_SA(S, port, in_addr) \ + memset(&(S), '\0', sizeof(S)); \ + (S).sin_family = AF_FAMILY; \ + (S).sin_port = htons(port); \ + (S).sin_addr = in_addr + +#define SA_IS_ANYADDR(s) \ + ((s).sin_addr.s_addr == INADDR_ANY) + +#define ADDR_IS_NOADDR(s) \ + ((s).s_addr == 0xFFFFFFFF) + +#define ADDR_IS_ANYADDR(s) \ + ((s).s_addr == 0x00000000) + +#define SA_NTOA(s) \ + inet_ntoa((s).sin_addr) + +#define INET_NTOA(s) \ + inet_ntoa(s) + +#define ADDR_FROM_SA(s) \ + ((s).sin_addr) +#define PORT_FROM_SA(s) \ + ((s).sin_port) +#define FAMILY_FROM_SA(s) \ + ((s).sin_family) + +#define SAFE_INET_ADDR(host, addr) \ + safe_inet_addr(host,addr) + +#endif + + + + + Index: squid/src/dns.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/dns.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/dns.c 23 Oct 2000 15:04:20 -0000 1.3 +++ squid/src/dns.c 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: dns.c,v 1.3 2000/10/23 15:04:20 hno Exp $ + * $Id: dns.c,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 34 Dnsserver interface * AUTHOR: Harvest Derived @@ -127,3 +127,23 @@ return Answer; } #endif /*SQUID_SNMP */ + + + + + + + + + + + + + + + + + + + + Index: squid/src/dns_internal.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/dns_internal.c,v retrieving revision 1.5 retrieving revision 1.5.6.1 diff -u -r1.5 -r1.5.6.1 --- squid/src/dns_internal.c 3 Nov 2000 21:04:27 -0000 1.5 +++ squid/src/dns_internal.c 7 Dec 2000 13:58:11 -0000 1.5.6.1 @@ -1,6 +1,6 @@ /* - * $Id: dns_internal.c,v 1.5 2000/11/03 21:04:27 hno Exp $ + * $Id: dns_internal.c,v 1.5.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c * AUTHOR: Duane Wessels @@ -64,7 +64,7 @@ }; struct _ns { - struct sockaddr_in S; + struct SOCKADDR_IN S; int nqueries; int nreplies; int large_pkts; @@ -82,7 +82,7 @@ static void idnsParseNameservers(void); static void idnsParseResolvConf(void); static void idnsSendQuery(idns_query * q); -static int idnsFromKnownNameserver(struct sockaddr_in *from); +static int idnsFromKnownNameserver(struct SOCKADDR_IN *from); static idns_query *idnsFindQuery(unsigned short id); static void idnsGrokReply(const char *buf, size_t sz); static PF idnsRead; @@ -93,8 +93,8 @@ static void idnsAddNameserver(const char *buf) { - struct in_addr A; - if (!safe_inet_addr(buf, &A)) { + struct IN_ADDR A; + if (!SAFE_INET_ADDR(buf, &A)) { debug(78, 0) ("WARNING: rejecting '%s' as a name server, because it is not a numeric IP address\n", buf); return; } @@ -112,11 +112,9 @@ safe_free(oldptr); } assert(nns < nns_alloc); - nameservers[nns].S.sin_family = AF_INET; - nameservers[nns].S.sin_port = htons(DOMAIN_PORT); - nameservers[nns].S.sin_addr.s_addr = A.s_addr; + CLEAR_AND_SET_SA(nameservers[nns].S, DOMAIN_PORT, A); debug(78, 3) ("idnsAddNameserver: Added nameserver #%d: %s\n", - nns, inet_ntoa(nameservers[nns].S.sin_addr)); + nns, SA_NTOA(nameservers[nns].S)); nns++; } @@ -183,11 +181,11 @@ tvSubDsec(q->sent_t, current_time)); } storeAppendPrintf(sentry, "\nNameservers:\n"); - storeAppendPrintf(sentry, "IP ADDRESS # QUERIES # REPLIES\n"); - storeAppendPrintf(sentry, "--------------- --------- ---------\n"); + storeAppendPrintf(sentry, "IP ADDRESS # QUERIES # REPLIES\n"); + storeAppendPrintf(sentry, "--------------------------------------------- --------- ---------\n"); for (i = 0; i < nns; i++) { - storeAppendPrintf(sentry, "%-15s %9d %9d\n", - inet_ntoa(nameservers[i].S.sin_addr), + storeAppendPrintf(sentry, "%-45s %9d %9d\n", + SA_NTOA(nameservers[i].S), nameservers[i].nqueries, nameservers[i].nreplies); } @@ -252,13 +250,13 @@ } static int -idnsFromKnownNameserver(struct sockaddr_in *from) +idnsFromKnownNameserver(struct SOCKADDR_IN *from) { int i; for (i = 0; i < nns; i++) { - if (nameservers[i].S.sin_addr.s_addr != from->sin_addr.s_addr) + if (memcmp(&ADDR_FROM_SA(nameservers[i].S), &ADDR_FROM_SA((*from)), sizeof(struct IN_ADDR))) continue; - if (nameservers[i].S.sin_port != from->sin_port) + if (PORT_FROM_SA(nameservers[i].S) != PORT_FROM_SA((*from))) continue; return i; } @@ -332,7 +330,7 @@ { int *N = data; ssize_t len; - struct sockaddr_in from; + struct SOCKADDR_IN from; socklen_t from_len; int max = INCOMING_DNS_MAX; static char rbuf[SQUID_UDP_SO_RCVBUF]; @@ -364,7 +362,7 @@ debug(78, 3) ("idnsRead: FD %d: received %d bytes from %s.\n", fd, len, - inet_ntoa(from.sin_addr)); + SA_NTOA(from)); ns = idnsFromKnownNameserver(&from); if (ns >= 0) { nameservers[ns].nreplies++; @@ -372,7 +370,7 @@ static time_t last_warning = 0; if (squid_curtime - last_warning > 60) { debug(78, 1) ("WARNING: Reply from unknown nameserver [%s]\n", - inet_ntoa(from.sin_addr)); + SA_NTOA(from)); last_warning = squid_curtime; } continue; @@ -391,7 +389,7 @@ x = (ns < 0) ? ++other_large_pkts : ++nameservers[ns].large_pkts; if (isPowTen(x)) debug(78, 1) ("WARNING: Got %d large DNS replies from %s\n", - x, inet_ntoa(from.sin_addr)); + x, SA_NTOA(from)); len = 512; } idnsGrokReply(rbuf, len); @@ -516,13 +514,14 @@ } void -idnsPTRLookup(const struct in_addr addr, IDNSCB * callback, void *data) +idnsPTRLookup(const struct IN_ADDR addr, IDNSCB * callback, void *data) { idns_query *q = memAllocate(MEM_IDNS_QUERY); q->sz = sizeof(q->buf); - q->id = rfc1035BuildPTRQuery(addr, q->buf, &q->sz); +/* ** FIXME ** we must use dns servers at this stage */ +/* q->id = rfc1035BuildPTRQuery(addr, q->buf, &q->sz); */ debug(78, 3) ("idnsPTRLookup: buf is %d bytes for %s, id = %#hx\n", - (int) q->sz, inet_ntoa(addr), q->id); + (int) q->sz, INET_NTOA(addr), q->id); q->callback = callback; q->callback_data = data; cbdataLock(q->callback_data); Index: squid/src/dnsserver.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/dnsserver.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/dnsserver.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/dnsserver.c 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: dnsserver.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: dnsserver.c,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 0 DNS Resolver * AUTHOR: Harvest Derived @@ -156,7 +156,7 @@ #define gethostbyname _res_gethostbyname #endif /* _SQUID_NEXT_ */ -static struct in_addr no_addr; +static struct IN_ADDR no_addr; #ifdef _SQUID_OS2_ struct state _res = @@ -189,7 +189,7 @@ int ttl = 0; int retry = 0; int i; - struct in_addr addr; + struct IN_ADDR addr; if (0 == strcmp(buf, "$shutdown")) exit(0); if (0 == strcmp(buf, "$hello")) { @@ -198,9 +198,9 @@ } /* check if it's already an IP address in text form. */ for (;;) { - if (safe_inet_addr(buf, &addr)) { + if (SAFE_INET_ADDR(buf, &addr)) { reverse = 1; - result = gethostbyaddr((char *) &addr.s_addr, 4, AF_INET); + result = gethostbyaddr((char *) &addr, sizeof(addr), AF_FAMILY); } else { result = gethostbyname(buf); } @@ -237,7 +237,7 @@ if (32 == i) break; xmemcpy(&addr, result->h_addr_list[i], sizeof(addr)); - printf(" %s", inet_ntoa(addr)); + printf(" %s", INET_NTOA(addr)); } printf("\n"); } @@ -262,7 +262,7 @@ int opt_s = 0; extern char *optarg; - safe_inet_addr("255.255.255.255", &no_addr); + memset(&no_addr, '\xFF', sizeof(no_addr)); #if HAVE_RES_INIT res_init(); @@ -310,10 +310,10 @@ } #if HAVE_RES_NSADDR_LIST _res.nsaddr_list[_res.nscount] = _res.nsaddr_list[0]; - safe_inet_addr(optarg, &_res.nsaddr_list[_res.nscount++].sin_addr); + SAFE_INET_ADDR(optarg, &ADDR_FROM_SA(_res.nsaddr_list[_res.nscount++])); #elif HAVE_RES_NS_LIST _res.ns_list[_res.nscount] = _res.ns_list[0]; - safe_inet_addr(optarg, &_res.ns_list[_res.nscount++].addr.sin_addr); + SAFE_INET_ADDR(optarg, &ADDR_FROM_SA(_res.ns_list[_res.nscount++].addr)); #else /* Unknown NS list format */ fprintf(stderr, "-s is not supported on this resolver\n"); #endif Index: squid/src/errorpage.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/errorpage.c,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- squid/src/errorpage.c 14 Nov 2000 13:03:47 -0000 1.5 +++ squid/src/errorpage.c 7 Dec 2000 13:58:11 -0000 1.5.2.1 @@ -1,6 +1,6 @@ /* - * $Id: errorpage.c,v 1.5 2000/11/14 13:03:47 adri Exp $ + * $Id: errorpage.c,v 1.5.2.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -469,7 +469,7 @@ p = r ? r->host : "[unknown host]"; break; case 'i': - memBufPrintf(&mb, "%s", inet_ntoa(err->src_addr)); + memBufPrintf(&mb, "%s", INET_NTOA(err->src_addr)); break; case 'I': if (err->host) { Index: squid/src/forward.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/forward.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/forward.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/forward.c 7 Dec 2000 13:58:11 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: forward.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: forward.c,v 1.4.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -463,7 +463,7 @@ * from peer_digest.c, asn.c, netdb.c, etc and should always * be allowed. yuck, I know. */ - if (r->client_addr.s_addr != no_addr.s_addr) { + if (!ADDR_IS_NOADDR(r->client_addr)) { /* * Check if this host is allowed to fetch MISSES from us (miss_access) */ Index: squid/src/fqdncache.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fqdncache.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/fqdncache.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/fqdncache.c 7 Dec 2000 13:58:11 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: fqdncache.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: fqdncache.c,v 1.4.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 35 FQDN Cache * AUTHOR: Harvest Derived @@ -323,10 +323,10 @@ } void -fqdncache_nbgethostbyaddr(struct in_addr addr, FQDNH * handler, void *handlerData) +fqdncache_nbgethostbyaddr(struct IN_ADDR addr, FQDNH * handler, void *handlerData) { fqdncache_entry *f = NULL; - char *name = inet_ntoa(addr); + char *name = INET_NTOA(addr); generic_cbdata *c; assert(handler); debug(35, 4) ("fqdncache_nbgethostbyaddr: Name '%s'.\n", name); @@ -399,11 +399,11 @@ } const char * -fqdncache_gethostbyaddr(struct in_addr addr, int flags) +fqdncache_gethostbyaddr(struct IN_ADDR addr, int flags) { - char *name = inet_ntoa(addr); + char *name = INET_NTOA(addr); fqdncache_entry *f = NULL; - struct in_addr ip; + struct IN_ADDR ip; assert(name); FqdncacheStats.requests++; f = fqdncache_get(name); @@ -422,7 +422,7 @@ return f->names[0]; } /* check if it's already a FQDN address in text form. */ - if (!safe_inet_addr(name, &ip)) + if (!SAFE_INET_ADDR(name, &ip)) return name; FqdncacheStats.misses++; if (flags & FQDN_LOOKUP_IF_MISS) @@ -476,13 +476,13 @@ } const char * -fqdnFromAddr(struct in_addr addr) +fqdnFromAddr(struct IN_ADDR addr) { const char *n; - static char buf[32]; + static char buf[MAXIPSTRLEN]; if (Config.onoff.log_fqdn && (n = fqdncache_gethostbyaddr(addr, 0))) return n; - xstrncpy(buf, inet_ntoa(addr), 32); + xstrncpy(buf, INET_NTOA(addr), MAXIPSTRLEN); return buf; } Index: squid/src/ftp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ftp.c,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- squid/src/ftp.c 14 Nov 2000 13:03:47 -0000 1.5 +++ squid/src/ftp.c 7 Dec 2000 13:58:11 -0000 1.5.2.1 @@ -1,6 +1,6 @@ /* - * $Id: ftp.c,v 1.5 2000/11/14 13:03:47 adri Exp $ + * $Id: ftp.c,v 1.5.2.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -1647,7 +1647,7 @@ ftpSendPasv(FtpStateData * ftpState) { int fd; - struct sockaddr_in addr; + struct SOCKADDR_IN addr; socklen_t addr_len; if (ftpState->request->method == METHOD_HEAD) { /* Terminate here for HEAD requests */ @@ -1676,12 +1676,12 @@ if (getsockname(ftpState->ctrl.fd, (struct sockaddr *) &addr, &addr_len)) { debug(9, 0) ("ftpSendPasv: getsockname(%d,..): %s\n", ftpState->ctrl.fd, xstrerror()); - addr.sin_addr = Config.Addrs.tcp_outgoing; + ADDR_FROM_SA(addr) = Config.Addrs.tcp_outgoing; } /* Open data channel with the same local address as control channel */ fd = comm_open(SOCK_STREAM, 0, - addr.sin_addr, + ADDR_FROM_SA(addr), 0, COMM_NONBLOCKING, storeUrl(ftpState->entry)); @@ -1710,8 +1710,7 @@ static void ftpReadPasv(FtpStateData * ftpState) -{ - int code = ftpState->ctrl.replycode; +{ int code = ftpState->ctrl.replycode; int h1, h2, h3, h4; int p1, p2; int n; @@ -1742,7 +1741,7 @@ return; } snprintf(junk, 1024, "%d.%d.%d.%d", h1, h2, h3, h4); - if (!safe_inet_addr(junk, NULL)) { + if (!SAFE_INET_ADDR(junk, NULL)) { debug(9, 1) ("unsafe address (%s)\n", junk); ftpSendPort(ftpState); return; @@ -1782,7 +1781,7 @@ ftpOpenListenSocket(FtpStateData * ftpState, int fallback) { int fd; - struct sockaddr_in addr; + struct SOCKADDR_IN addr; socklen_t addr_len; int on = 1; u_short port = 0; @@ -1810,11 +1809,11 @@ */ if (fallback) { setsockopt(ftpState->ctrl.fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)); - port = ntohs(addr.sin_port); + port = ntohs(PORT_FROM_SA(addr)); } fd = comm_open(SOCK_STREAM, 0, - addr.sin_addr, + ADDR_FROM_SA(addr), port, COMM_NONBLOCKING | (fallback ? COMM_REUSEADDR : 0), storeUrl(ftpState->entry)); @@ -1837,7 +1836,7 @@ ftpSendPort(FtpStateData * ftpState) { int fd; - struct sockaddr_in addr; + struct SOCKADDR_IN addr; socklen_t addr_len; unsigned char *addrptr; unsigned char *portptr; @@ -1851,9 +1850,9 @@ ftpFail(ftpState); return; } - addrptr = (unsigned char *) &addr.sin_addr.s_addr; - portptr = (unsigned char *) &addr.sin_port; - snprintf(cbuf, 1024, "PORT %d,%d,%d,%d,%d,%d\r\n", + addrptr = (unsigned char *) &(ADDR_FROM_SA(addr)); + portptr = (unsigned char *) &(PORT_FROM_SA(addr)); + snprintf(cbuf, 1024, "PORT %d,%d,%d,%d,%d,%d\r\n", /* ** FIXME ** ** FIXME ** */ addrptr[0], addrptr[1], addrptr[2], addrptr[3], portptr[0], portptr[1]); ftpWriteCommand(cbuf, ftpState); @@ -1878,7 +1877,7 @@ ftpAcceptDataConnection(int fd, void *data) { FtpStateData *ftpState = data; - struct sockaddr_in my_peer, me; + struct SOCKADDR_IN my_peer, me; debug(9, 3) ("ftpAcceptDataConnection\n"); if (EBIT_TEST(ftpState->entry->flags, ENTRY_ABORTED)) { @@ -1896,8 +1895,8 @@ comm_close(ftpState->data.fd); debug(9, 3) ("ftpAcceptDataConnection: Connected data socket on FD %d\n", fd); ftpState->data.fd = fd; - ftpState->data.port = ntohs(my_peer.sin_port); - ftpState->data.host = xstrdup(inet_ntoa(my_peer.sin_addr)); + ftpState->data.port = ntohs(PORT_FROM_SA(my_peer)); + ftpState->data.host = xstrdup(SA_NTOA(my_peer)); commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); commSetTimeout(ftpState->data.fd, Config.Timeout.read, ftpTimeout, ftpState); Index: squid/src/globals.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/globals.h,v retrieving revision 1.4 retrieving revision 1.4.4.1 diff -u -r1.4 -r1.4.4.1 --- squid/src/globals.h 10 Nov 2000 16:36:45 -0000 1.4 +++ squid/src/globals.h 7 Dec 2000 13:58:11 -0000 1.4.4.1 @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.4 2000/11/10 16:36:45 hno Exp $ + * $Id: globals.h,v 1.4.4.1 2000/12/07 13:58:11 rvenning Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -76,6 +76,7 @@ extern int do_mallinfo; /* 0 */ extern int opt_reuseaddr; /* 1 */ extern int icmp_sock; /* -1 */ +extern int icmp6_sock; /* -1 */ extern int neighbors_do_private_keys; /* 1 */ extern int opt_accel_uses_host; /* 0 */ extern int opt_catch_signals; /* 1 */ @@ -102,11 +103,11 @@ extern int n_disk_objects; /* 0 */ extern iostats IOStats; extern struct _acl_deny_info_list *DenyInfoList; /* NULL */ -extern struct in_addr any_addr; -extern struct in_addr local_addr; -extern struct in_addr no_addr; -extern struct in_addr theOutICPAddr; -extern struct in_addr theOutSNMPAddr; +extern struct IN_ADDR local_addr; +extern struct IN_ADDR no_addr; +extern struct IN_ADDR any_addr; +extern struct IN_ADDR theOutICPAddr; +extern struct IN_ADDR theOutSNMPAddr; extern struct timeval current_time; extern struct timeval squid_start; extern time_t squid_curtime; /* 0 */ Index: squid/src/htcp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/htcp.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/htcp.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/htcp.c 7 Dec 2000 13:58:11 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: htcp.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: htcp.c,v 1.4.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 31 Hypertext Caching Protocol * AUTHOR: Duane Wesssels @@ -392,15 +392,15 @@ } static void -htcpSend(const char *buf, int len, struct sockaddr_in *to) +htcpSend(const char *buf, int len, struct SOCKADDR_IN *to) { int x; debug(31, 3) ("htcpSend: %s/%d\n", - inet_ntoa(to->sin_addr), (int) ntohs(to->sin_port)); + SA_NTOA(*to)), (int) ntohs(PORT_FROM_SA(*to))); htcpHexdump("htcpSend", buf, len); x = comm_udp_sendto(htcpOutSocket, to, - sizeof(struct sockaddr_in), + sizeof(struct SOCKADDR_IN), buf, len); if (x < 0) @@ -818,13 +818,13 @@ { static char buf[8192]; int len; - static struct sockaddr_in from; - int flen = sizeof(struct sockaddr_in); + static struct SOCKADDR_IN from; + int flen = sizeof(struct SOCKADDR_IN); memset(&from, '\0', flen); statCounter.syscalls.sock.recvfroms++; len = recvfrom(fd, buf, 8192, 0, (struct sockaddr *) &from, &flen); debug(31, 3) ("htcpRecv: FD %d, %d bytes from %s:%d\n", - fd, len, inet_ntoa(from.sin_addr), ntohs(from.sin_port)); + fd, len, SA_NTOA(from), ntohs(PORT_FROM_SA(from))); htcpHandle(buf, len, &from); commSetSelect(fd, COMM_SELECT_READ, htcpRecv, NULL, 0); } @@ -841,7 +841,7 @@ enter_suid(); htcpInSocket = comm_open(SOCK_DGRAM, 0, - Config.Addrs.udp_incoming, + &Config.Addrs.udp_incoming, Config.Port.htcp, COMM_NONBLOCKING, "HTCP Socket"); @@ -855,7 +855,7 @@ enter_suid(); htcpOutSocket = comm_open(SOCK_DGRAM, 0, - Config.Addrs.udp_outgoing, + &Config.Addrs.udp_outgoing, Config.Port.htcp, COMM_NONBLOCKING, "Outgoing HTCP Socket"); Index: squid/src/icmp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/icmp.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/icmp.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/icmp.c 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: icmp.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: icmp.c,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels @@ -51,7 +51,7 @@ #endif static void -icmpSendEcho(struct in_addr to, int opcode, const char *payload, int len) +icmpSendEcho(struct IN_ADDR to, int opcode, const char *payload, int len) { static pingerEchoData pecho; if (payload && len == 0) @@ -70,7 +70,7 @@ int n; static int fail_count = 0; pingerReplyData preply; - static struct sockaddr_in F; + static struct SOCKADDR_IN F; commSetSelect(icmp_sock, COMM_SELECT_READ, icmpRecv, NULL, 0); memset(&preply, '\0', sizeof(pingerReplyData)); statCounter.syscalls.sock.recvfroms++; @@ -87,9 +87,7 @@ fail_count = 0; if (n == 0) /* test probe from pinger */ return; - F.sin_family = AF_INET; - F.sin_addr = preply.from; - F.sin_port = 0; + CLEAR_AND_SET_SA(F, 0, preply.from); switch (preply.opcode) { case S_ICMP_ECHO: break; @@ -114,7 +112,7 @@ if (icmp_sock < 0) return; debug(37, 2) ("icmpSend: to %s, opcode %d, len %d\n", - inet_ntoa(pkt->to), (int) pkt->opcode, pkt->psize); + INET_NTOA(pkt->to), (int) pkt->opcode, pkt->psize); x = send(icmp_sock, (char *) pkt, len, 0); if (x < 0) { debug(50, 1) ("icmpSend: send: %s\n", xstrerror()); @@ -129,7 +127,7 @@ #if ALLOW_SOURCE_PING static void -icmpHandleSourcePing(const struct sockaddr_in *from, const char *buf) +icmpHandleSourcePing(const struct SOCKADDR_IN *from, const char *buf) { const cache_key *key; icp_common_t header; @@ -138,7 +136,7 @@ url = buf + sizeof(icp_common_t); key = icpGetCacheKey(url, (int) header.reqnum); debug(37, 3) ("icmpHandleSourcePing: from %s, key '%s'\n", - inet_ntoa(from->sin_addr), storeKeyText(key)); + SA_NTOA(*from), storeKeyText(key)); /* call neighborsUdpAck even if ping_status != PING_WAITING */ neighborsUdpAck(key, &header, from); } @@ -148,7 +146,7 @@ #endif /* USE_ICMP */ void -icmpPing(struct in_addr to) +icmpPing(struct IN_ADDR to) { #if USE_ICMP icmpSendEcho(to, S_ICMP_ECHO, NULL, 0); @@ -157,7 +155,7 @@ #if ALLOW_SOURCE_PING void -icmpSourcePing(struct in_addr to, const icp_common_t * header, const char *url) +icmpSourcePing(struct IN_ADDR to, const icp_common_t * header, const char *url) { #if USE_ICMP char *payload; @@ -178,7 +176,7 @@ #endif void -icmpDomainPing(struct in_addr to, const char *domain) +icmpDomainPing(struct IN_ADDR to, const char *domain) { #if USE_ICMP debug(37, 3) ("icmpDomainPing: '%s'\n", domain); @@ -223,3 +221,5 @@ icmp_sock = -1; #endif } + + Index: squid/src/icp_v2.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/icp_v2.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/icp_v2.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/icp_v2.c 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: icp_v2.c,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -35,8 +35,8 @@ #include "squid.h" -static void icpLogIcp(struct in_addr, log_type, int, const char *, int); -static void icpHandleIcpV2(int, struct sockaddr_in, char *, int); +static void icpLogIcp(struct IN_ADDR, log_type, int, const char *, int); +static void icpHandleIcpV2(int, struct SOCKADDR_IN, char *, int); static void icpCount(void *, int, size_t, int); /* @@ -46,7 +46,7 @@ static icpUdpData *IcpQueueTail = NULL; static void -icpLogIcp(struct in_addr caddr, log_type logcode, int len, const char *url, int delay) +icpLogIcp(struct IN_ADDR caddr, log_type logcode, int len, const char *url, int delay) { AccessLogEntry al; if (LOG_TAG_NONE == logcode) @@ -106,7 +106,8 @@ headerp->reqnum = htonl(reqnum); headerp->flags = htonl(flags); headerp->pad = htonl(pad); - headerp->shostid = theOutICPAddr.s_addr; + /* ** FIXME ** we should get more unique data from IPv6 address */ + xmemcpy(&headerp->shostid, &theOutICPAddr, sizeof(headerp->shostid)); urloffset = buf + sizeof(icp_common_t); if (opcode == ICP_QUERY) urloffset += sizeof(u_num32); @@ -116,7 +117,7 @@ int icpUdpSend(int fd, - const struct sockaddr_in *to, + const struct SOCKADDR_IN *to, icp_common_t * msg, log_type logcode, int delay) @@ -129,12 +130,12 @@ fd, icp_opcode_str[msg->opcode], len, - inet_ntoa(to->sin_addr), - ntohs(to->sin_port)); + SA_NTOA(*to), + ntohs(PORT_FROM_SA(*to))); x = comm_udp_sendto(fd, to, sizeof(*to), msg, len); if (x >= 0) { /* successfully written */ - icpLogIcp(to->sin_addr, logcode, len, (char *) (msg + 1), delay); + icpLogIcp(ADDR_FROM_SA(*to), logcode, len, (char *) (msg + 1), delay); icpCount(msg, SENT, (size_t) len, delay); safe_free(msg); } else if (0 == delay) { @@ -179,7 +180,7 @@ } static void -icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) +icpHandleIcpV2(int fd, struct SOCKADDR_IN from, char *buf, int len) { icp_common_t header; StoreEntry *entry = NULL; @@ -224,19 +225,19 @@ break; } memset(&checklist, '\0', sizeof(checklist)); - checklist.src_addr = from.sin_addr; + checklist.src_addr = ADDR_FROM_SA(from); checklist.my_addr = no_addr; checklist.request = icp_request; allow = aclCheckFast(Config.accessList.icp, &checklist); if (!allow) { debug(12, 2) ("icpHandleIcpV2: Access Denied for %s by %s.\n", - inet_ntoa(from.sin_addr), AclMatchedName); - if (clientdbCutoffDenied(from.sin_addr)) { + SA_NTOA(from), AclMatchedName); + if (clientdbCutoffDenied(ADDR_FROM_SA(from))) { /* * count this DENIED query in the clientdb, even though * we're not sending an ICP reply... */ - clientdbUpdate(from.sin_addr, LOG_UDP_DENIED, PROTO_ICP, 0); + clientdbUpdate(ADDR_FROM_SA(from), LOG_UDP_DENIED, PROTO_ICP, 0); } else { reply = icpCreateMessage(ICP_DENIED, 0, url, header.reqnum, 0); icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, 0); @@ -288,14 +289,14 @@ case ICP_MISS_NOFETCH: if (neighbors_do_private_keys && header.reqnum == 0) { debug(12, 0) ("icpHandleIcpV2: Neighbor %s returned reqnum = 0\n", - inet_ntoa(from.sin_addr)); + SA_NTOA(from)); debug(12, 0) ("icpHandleIcpV2: Disabling use of private keys\n"); neighbors_do_private_keys = 0; } url = buf + sizeof(icp_common_t); debug(12, 3) ("icpHandleIcpV2: %s from %s for '%s'\n", icp_opcode_str[header.opcode], - inet_ntoa(from.sin_addr), + SA_NTOA(from), url); key = icpGetCacheKey(url, (int) header.reqnum); /* call neighborsUdpAck even if ping_status != PING_WAITING */ @@ -308,7 +309,7 @@ default: debug(12, 0) ("icpHandleIcpV2: UNKNOWN OPCODE: %d from %s\n", - header.opcode, inet_ntoa(from.sin_addr)); + header.opcode, SA_NTOA(from)); break; } if (icp_request) @@ -319,7 +320,7 @@ static void icpPktDump(icp_common_t * pkt) { - struct in_addr a; + struct IN_ADDR a; debug(12, 9) ("opcode: %3d %s\n", (int) pkt->opcode, @@ -328,8 +329,9 @@ debug(12, 9) ("length: %-8d\n", (int) ntohs(pkt->length)); debug(12, 9) ("reqnum: %-8d\n", ntohl(pkt->reqnum)); debug(12, 9) ("flags: %-8x\n", ntohl(pkt->flags)); - a.s_addr = pkt->shostid; - debug(12, 9) ("shostid: %s\n", inet_ntoa(a)); + xmemcpy(&a, &pkt->shostid, 4); /* FIXME... maybe this should be sizeof(pkt->hostid). + Really we want min(sizeof(shostid), sizeof(a)) */ + debug(12, 9) ("shostid: %s\n", INET_NTOA(a)); debug(12, 9) ("payload: %s\n", (char *) pkt + sizeof(icp_common_t)); } #endif @@ -338,7 +340,7 @@ icpHandleUdp(int sock, void *data) { int *N = data; - struct sockaddr_in from; + struct SOCKADDR_IN from; socklen_t from_len; LOCAL_ARRAY(char, buf, SQUID_UDP_SO_RCVBUF); int len; @@ -377,7 +379,7 @@ debug(12, 4) ("icpHandleUdp: FD %d: received %d bytes from %s.\n", sock, len, - inet_ntoa(from.sin_addr)); + SA_NTOA(from)); #ifdef ICP_PACKET_DUMP icpPktDump(buf); #endif @@ -393,8 +395,8 @@ else debug(12, 1) ("WARNING: Unused ICP version %d received from %s:%d\n", icp_version, - inet_ntoa(from.sin_addr), - ntohs(from.sin_port)); + SA_NTOA(from), + ntohs(PORT_FROM_SA(from))); } } @@ -402,8 +404,8 @@ icpConnectionsOpen(void) { u_short port; - struct in_addr addr; - struct sockaddr_in xaddr; + struct IN_ADDR addr; + struct SOCKADDR_IN xaddr; int x; socklen_t len; wordlist *s; @@ -429,9 +431,10 @@ for (s = Config.mcast_group_list; s; s = s->next) ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL); debug(12, 1) ("Accepting ICP messages at %s, port %d, FD %d.\n", - inet_ntoa(Config.Addrs.udp_incoming), + INET_NTOA(Config.Addrs.udp_incoming), (int) port, theInIcpConnection); - if ((addr = Config.Addrs.udp_outgoing).s_addr != no_addr.s_addr) { + addr = Config.Addrs.udp_outgoing; + if (!ADDR_IS_NOADDR(addr)) { enter_suid(); theOutIcpConnection = comm_open(SOCK_DGRAM, 0, @@ -454,8 +457,8 @@ } else { theOutIcpConnection = theInIcpConnection; } - memset(&theOutICPAddr, '\0', sizeof(struct in_addr)); - len = sizeof(struct sockaddr_in); + memset(&theOutICPAddr, '\0', sizeof(struct IN_ADDR)); + len = sizeof(struct SOCKADDR_IN); memset(&xaddr, '\0', len); x = getsockname(theOutIcpConnection, (struct sockaddr *) &xaddr, &len); @@ -463,7 +466,7 @@ debug(50, 1) ("theOutIcpConnection FD %d: getsockname: %s\n", theOutIcpConnection, xstrerror()); else - theOutICPAddr = xaddr.sin_addr; + theOutICPAddr = ADDR_FROM_SA(xaddr); } /* Index: squid/src/icp_v3.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/icp_v3.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/icp_v3.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/icp_v3.c 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: icp_v3.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: icp_v3.c,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -37,7 +37,7 @@ /* Currently Harvest cached-2.x uses ICP_VERSION_3 */ void -icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len) +icpHandleIcpV3(int fd, struct SOCKADDR_IN from, char *buf, int len) { icp_common_t header; icp_common_t *reply; @@ -78,19 +78,19 @@ break; } memset(&checklist, '\0', sizeof(checklist)); - checklist.src_addr = from.sin_addr; + checklist.src_addr = ADDR_FROM_SA(from); checklist.my_addr = no_addr; checklist.request = icp_request; allow = aclCheckFast(Config.accessList.icp, &checklist); if (!allow) { debug(12, 2) ("icpHandleIcpV3: Access Denied for %s by %s.\n", - inet_ntoa(from.sin_addr), AclMatchedName); - if (clientdbCutoffDenied(from.sin_addr)) { + SA_NTOA(from), AclMatchedName); + if (clientdbCutoffDenied(ADDR_FROM_SA(from))) { /* * count this DENIED query in the clientdb, even though * we're not sending an ICP reply... */ - clientdbUpdate(from.sin_addr, LOG_UDP_DENIED, PROTO_ICP, 0); + clientdbUpdate(ADDR_FROM_SA(from), LOG_UDP_DENIED, PROTO_ICP, 0); } else { reply = icpCreateMessage(ICP_DENIED, 0, url, header.reqnum, 0); icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, 0); @@ -129,14 +129,14 @@ case ICP_MISS_NOFETCH: if (neighbors_do_private_keys && header.reqnum == 0) { debug(12, 0) ("icpHandleIcpV3: Neighbor %s returned reqnum = 0\n", - inet_ntoa(from.sin_addr)); + SA_NTOA(from)); debug(12, 0) ("icpHandleIcpV3: Disabling use of private keys\n"); neighbors_do_private_keys = 0; } url = buf + sizeof(icp_common_t); debug(12, 3) ("icpHandleIcpV3: %s from %s for '%s'\n", icp_opcode_str[header.opcode], - inet_ntoa(from.sin_addr), + SA_NTOA(from), url); key = icpGetCacheKey(url, (int) header.reqnum); /* call neighborsUdpAck even if ping_status != PING_WAITING */ @@ -149,7 +149,7 @@ default: debug(12, 0) ("icpHandleIcpV3: UNKNOWN OPCODE: %d from %s\n", - header.opcode, inet_ntoa(from.sin_addr)); + header.opcode, SA_NTOA(from)); break; } if (icp_request) Index: squid/src/ident.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ident.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/ident.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/ident.c 7 Dec 2000 13:58:11 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: ident.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: ident.c,v 1.4.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 30 Ident (RFC 931) * AUTHOR: Duane Wessels @@ -49,8 +49,8 @@ typedef struct _IdentStateData { hash_link hash; /* must be first */ int fd; /* IDENT fd */ - struct sockaddr_in me; - struct sockaddr_in my_peer; + struct SOCKADDR_IN me; + struct SOCKADDR_IN my_peer; IdentClient *clients; } IdentStateData; @@ -93,7 +93,7 @@ { IdentStateData *state = data; debug(30, 3) ("identTimeout: FD %d, %s\n", fd, - inet_ntoa(state->my_peer.sin_addr)); + SA_NTOA(state->my_peer)); comm_close(fd); } @@ -122,8 +122,8 @@ } memBufDefInit(&mb); memBufPrintf(&mb, "%d, %d\r\n", - ntohs(state->my_peer.sin_port), - ntohs(state->me.sin_port)); + ntohs(PORT_FROM_SA(state->my_peer)), + ntohs(PORT_FROM_SA(state->me))); comm_write_mbuf(fd, mb, NULL, state); commSetSelect(fd, COMM_SELECT_READ, identReadReply, state, 0); commSetTimeout(fd, Config.Timeout.ident, identTimeout, state); @@ -184,7 +184,7 @@ * start a TCP connection to the peer host on port 113 */ void -identStart(struct sockaddr_in *me, struct sockaddr_in *my_peer, IDCB * callback, void *data) +identStart(struct SOCKADDR_IN *me, struct SOCKADDR_IN *my_peer, IDCB * callback, void *data) { IdentStateData *state; int fd; @@ -192,11 +192,11 @@ char key2[IDENT_KEY_SZ]; char key[IDENT_KEY_SZ]; snprintf(key1, IDENT_KEY_SZ, "%s:%d", - inet_ntoa(me->sin_addr), - ntohs(me->sin_port)); + SA_NTOA(*me), + ntohs(PORT_FROM_SA(*me))); snprintf(key2, IDENT_KEY_SZ, "%s:%d", - inet_ntoa(my_peer->sin_addr), - ntohs(my_peer->sin_port)); + SA_NTOA(*my_peer), + ntohs(PORT_FROM_SA(*my_peer))); snprintf(key, IDENT_KEY_SZ, "%s,%s", key1, key2); if ((state = hash_lookup(ident_hash, key)) != NULL) { identClientAdd(state, callback, data); @@ -204,7 +204,7 @@ } fd = comm_open(SOCK_STREAM, 0, - me->sin_addr, + ADDR_FROM_SA(*me), 0, COMM_NONBLOCKING, "ident"); @@ -226,7 +226,7 @@ state); commSetTimeout(fd, Config.Timeout.ident, identTimeout, state); commConnectStart(fd, - inet_ntoa(state->my_peer.sin_addr), + SA_NTOA(state->my_peer), IDENT_PORT, identConnectDone, state); Index: squid/src/internal.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/internal.c,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- squid/src/internal.c 18 Nov 2000 11:01:27 -0000 1.5 +++ squid/src/internal.c 7 Dec 2000 13:58:11 -0000 1.5.2.1 @@ -1,6 +1,6 @@ /* - * $Id: internal.c,v 1.5 2000/11/18 11:01:27 adri Exp $ + * $Id: internal.c,v 1.5.2.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 76 Internal Squid Object handling * AUTHOR: Duane, Alex, Henrik @@ -46,7 +46,7 @@ const char *upath = strBuf(request->urlpath); http_version_t version; debug(76, 3) ("internalStart: %s requesting '%s'\n", - inet_ntoa(request->client_addr), upath); + INET_NTOA(request->client_addr), upath); if (0 == strcmp(upath, "/squid-internal-dynamic/netdb")) { netdbBinaryExchange(entry); } else if (0 == strcmp(upath, "/squid-internal-periodic/store_digest")) { @@ -127,7 +127,7 @@ internalLocalUri(const char *dir, const char *name) { return internalRemoteUri(getMyHostname(), - ntohs(Config.Sockaddr.http->s.sin_port), dir, name); + ntohs(PORT_FROM_SA(Config.Sockaddr.http->s)), dir, name); } const char * Index: squid/src/ipc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipc.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/ipc.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/ipc.c 7 Dec 2000 13:58:11 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: ipc.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: ipc.c,v 1.3.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -59,8 +59,8 @@ ipcCreate(int type, const char *prog, char *const args[], const char *name, int *rfd, int *wfd) { pid_t pid; - struct sockaddr_in CS; - struct sockaddr_in PS; + struct SOCKADDR_IN CS; + struct SOCKADDR_IN PS; int crfd = -1; int prfd = -1; int cwfd = -1; @@ -147,7 +147,7 @@ return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } debug(54, 3) ("ipcCreate: FD %d sockaddr %s:%d\n", - pwfd, inet_ntoa(PS.sin_addr), ntohs(PS.sin_port)); + pwfd, SA_NTOA(PS), ntohs(PORT_FROM_SA(PS))); len = sizeof(CS); memset(&CS, '\0', len); if (getsockname(crfd, (struct sockaddr *) &CS, &len) < 0) { @@ -155,7 +155,7 @@ return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } debug(54, 3) ("ipcCreate: FD %d sockaddr %s:%d\n", - crfd, inet_ntoa(CS.sin_addr), ntohs(CS.sin_port)); + crfd, SA_NTOA(CS), ntohs(PORT_FROM_SA(CS))); } if (type == IPC_TCP_SOCKET) { if (listen(crfd, 1) < 0) { @@ -248,7 +248,7 @@ #endif /* * This double-dup stuff avoids problems when one of - * crfd, cwfd, or debug_log are in the rage 0-2. + * crfd, cwfd, or debug_log are in the range 0-2. */ do { x = open(_PATH_DEVNULL, 0, 0444); Index: squid/src/ipcache.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipcache.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/ipcache.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/ipcache.c 7 Dec 2000 13:58:11 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: ipcache.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: ipcache.c,v 1.4.6.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -266,7 +266,7 @@ i.addrs.in_addrs = NULL; i.addrs.bad_mask = NULL; } else { - i.addrs.in_addrs = xcalloc(ipcount, sizeof(struct in_addr)); + i.addrs.in_addrs = xcalloc(ipcount, sizeof(struct IN_ADDR)); i.addrs.bad_mask = xcalloc(ipcount, sizeof(unsigned char)); } for (j = 0, k = 0; k < ipcount; k++) { @@ -314,7 +314,7 @@ return &i; } i.flags.negcached = 0; - i.addrs.in_addrs = xcalloc(na, sizeof(struct in_addr)); + i.addrs.in_addrs = xcalloc(na, sizeof(struct IN_ADDR)); i.addrs.bad_mask = xcalloc(na, sizeof(unsigned char)); i.addrs.count = (unsigned char) na; for (j = 0, k = 0; k < nr; k++) { @@ -328,7 +328,7 @@ xmemcpy(&i.addrs.in_addrs[j++], answers[k].rdata, 4); debug(14, 3) ("ipcacheParse: #%d %s\n", j - 1, - inet_ntoa(i.addrs.in_addrs[j - 1])); + INET_NTOA(i.addrs.in_addrs[j - 1])); } assert(j == na); return &i; @@ -438,7 +438,7 @@ debug(14, 1) ("Successful DNS name lookup tests...\n"); } memset(&static_addrs, '\0', sizeof(ipcache_addrs)); - static_addrs.in_addrs = xcalloc(1, sizeof(struct in_addr)); + static_addrs.in_addrs = xcalloc(1, sizeof(struct IN_ADDR)); static_addrs.bad_mask = xcalloc(1, sizeof(unsigned char)); ipcache_high = (long) (((float) Config.ipcache.size * (float) Config.ipcache.high) / (float) 100); @@ -495,7 +495,7 @@ (int) i->addrs.count, (int) i->addrs.badcount); for (k = 0; k < (int) i->addrs.count; k++) { - storeAppendPrintf(sentry, " %15s-%3s", inet_ntoa(i->addrs.in_addrs[k]), + storeAppendPrintf(sentry, " %15s-%3s", INET_NTOA(i->addrs.in_addrs[k]), i->addrs.bad_mask[k] ? "BAD" : "OK "); } storeAppendPrintf(sentry, "\n"); @@ -556,13 +556,13 @@ ipcache_addrs * ipcacheCheckNumeric(const char *name) { - struct in_addr ip; + struct IN_ADDR ip; /* check if it's already a IP address in text form. */ - if (!safe_inet_addr(name, &ip)) + if (!SAFE_INET_ADDR(name, &ip)) return NULL; static_addrs.count = 1; static_addrs.cur = 0; - static_addrs.in_addrs[0].s_addr = ip.s_addr; + static_addrs.in_addrs[0] = ip; static_addrs.bad_mask[0] = FALSE; static_addrs.badcount = 0; return &static_addrs; @@ -615,7 +615,7 @@ ia->cur = 0; } debug(14, 3) ("ipcacheCycleAddr: %s now at %s\n", name, - inet_ntoa(ia->in_addrs[ia->cur])); + INET_NTOA(ia->in_addrs[ia->cur])); } /* @@ -623,7 +623,7 @@ * advance the current pointer to the next OK address. */ void -ipcacheMarkBadAddr(const char *name, struct in_addr addr) +ipcacheMarkBadAddr(const char *name, struct IN_ADDR addr) { ipcache_entry *i; ipcache_addrs *ia; @@ -632,7 +632,7 @@ return; ia = &i->addrs; for (k = 0; k < (int) ia->count; k++) { - if (ia->in_addrs[k].s_addr == addr.s_addr) + if (memcmp (&ia->in_addrs[k], &addr, sizeof(addr)) == 0) /* ie. the same */ break; } if (k == (int) ia->count) /* not found */ @@ -640,13 +640,13 @@ if (!ia->bad_mask[k]) { ia->bad_mask[k] = TRUE; ia->badcount++; - debug(14, 2) ("ipcacheMarkBadAddr: %s [%s]\n", name, inet_ntoa(addr)); + debug(14, 2) ("ipcacheMarkBadAddr: %s [%s]\n", name, INET_NTOA(addr)); } ipcacheCycleAddr(name, ia); } void -ipcacheMarkGoodAddr(const char *name, struct in_addr addr) +ipcacheMarkGoodAddr(const char *name, struct IN_ADDR addr) { ipcache_entry *i; ipcache_addrs *ia; @@ -655,7 +655,7 @@ return; ia = &i->addrs; for (k = 0; k < (int) ia->count; k++) { - if (ia->in_addrs[k].s_addr == addr.s_addr) + if (memcmp (&ia->in_addrs[k], &addr, sizeof(addr)) == 0) /* ie. the same */ break; } if (k == (int) ia->count) /* not found */ @@ -664,7 +664,7 @@ return; ia->bad_mask[k] = FALSE; ia->badcount--; - debug(14, 2) ("ipcacheMarkGoodAddr: %s [%s]\n", name, inet_ntoa(addr)); + debug(14, 2) ("ipcacheMarkGoodAddr: %s [%s]\n", name, INET_NTOA(addr)); } static void Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.5 retrieving revision 1.5.4.1 diff -u -r1.5 -r1.5.4.1 --- squid/src/main.c 10 Nov 2000 16:36:45 -0000 1.5 +++ squid/src/main.c 7 Dec 2000 13:58:11 -0000 1.5.4.1 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.5 2000/11/10 16:36:45 hno Exp $ + * $Id: main.c,v 1.5.4.1 2000/12/07 13:58:11 rvenning Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -471,7 +471,7 @@ setEffectiveUser(); assert(Config.Sockaddr.http); if (httpPortNumOverride != 1) - Config.Sockaddr.http->s.sin_port = htons(httpPortNumOverride); + PORT_FROM_SA(Config.Sockaddr.http->s) = htons(httpPortNumOverride); if (icpPortNumOverride != 1) Config.Port.icp = (u_short) icpPortNumOverride; @@ -611,12 +611,10 @@ if (oldmask) umask(oldmask); - memset(&local_addr, '\0', sizeof(struct in_addr)); - safe_inet_addr(localhost, &local_addr); - memset(&any_addr, '\0', sizeof(struct in_addr)); - safe_inet_addr("0.0.0.0", &any_addr); - memset(&no_addr, '\0', sizeof(struct in_addr)); - safe_inet_addr("255.255.255.255", &no_addr); + memset(&local_addr, '\0', sizeof(local_addr)); + SAFE_INET_ADDR(localhost, &local_addr); + memset(&no_addr, '\xFF', sizeof(no_addr)); + memset(&any_addr, '\0', sizeof(any_addr)); squid_srandom(time(NULL)); getCurrentTime(); Index: squid/src/multicast.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/multicast.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/multicast.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/multicast.c 7 Dec 2000 13:58:12 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: multicast.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: multicast.c,v 1.3.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 7 Multicast * AUTHOR: Martin Hamilton @@ -40,10 +40,14 @@ { #ifdef IP_MULTICAST_TTL char ttl = (char) mcast_ttl; +#if INET6 + if (setsockopt(fd, IPPROTO_IPV6, IP_MULTICAST_TTL, &ttl, 1) < 0) +#else /* INET6 */ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0) +#endif /* INET6 */ debug(50, 1) ("comm_set_mcast_ttl: FD %d, TTL: %d: %s\n", fd, mcast_ttl, xstrerror()); -#endif +#endif /* IP_MULTICAST_TTL */ return 0; } @@ -52,7 +56,11 @@ { #ifdef IP_MULTICAST_TTL int fd = theInIcpConnection; +#if INET6 + struct ipv6_mreq mr; +#else struct ip_mreq mr; +#endif int i; int x; char c = 0; @@ -62,17 +70,38 @@ } for (i = 0; i < (int) ia->count; i++) { debug(7, 10) ("Listening for ICP requests on %s\n", - inet_ntoa(*(ia->in_addrs + i))); - mr.imr_multiaddr.s_addr = (ia->in_addrs + i)->s_addr; - mr.imr_interface.s_addr = INADDR_ANY; + INET_NTOA(*(ia->in_addrs + i))); + +#if INET6 + mr.ipv6mr_multiaddr = *(ia->in_addrs + i); + mr.ipv6mr_interface = -1; /* ** FIXME ** we need specify an interface number */ + x = setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP /*IP_JOIN_GROUP*/, /* ** FIXME ** */ + (char *) &mr, sizeof(struct ipv6_mreq)); +#else + mr.imr_multiaddr = *(ia->in_addrs + i); + mr.imr_interface = INADDR_ANY_ASSIGN; x = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mr, sizeof(struct ip_mreq)); +#endif if (x < 0) debug(7, 1) ("comm_join_mcast_groups: FD %d, [%s]\n", - fd, inet_ntoa(*(ia->in_addrs + i))); + fd, INET_NTOA(*(ia->in_addrs + i))); +#if INET6 + x = setsockopt(fd, IPPROTO_IPV6, IP_MULTICAST_LOOP, &c, 1); +#else x = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1); +#endif if (x < 0) debug(7, 1) ("Can't disable multicast loopback: %s\n", xstrerror()); } #endif } + + + + + + + + + Index: squid/src/neighbors.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/neighbors.c,v retrieving revision 1.5 retrieving revision 1.5.4.1 diff -u -r1.5 -r1.5.4.1 --- squid/src/neighbors.c 9 Nov 2000 09:09:41 -0000 1.5 +++ squid/src/neighbors.c 7 Dec 2000 13:58:12 -0000 1.5.4.1 @@ -1,6 +1,6 @@ /* - * $Id: neighbors.c,v 1.5 2000/11/09 09:09:41 hno Exp $ + * $Id: neighbors.c,v 1.5.4.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -55,7 +55,7 @@ static void peerCountMcastPeersStart(void *data); static void peerCountMcastPeersSchedule(peer * p, time_t when); static IRCB peerCountHandleIcpReply; -static void neighborIgnoreNonPeer(const struct sockaddr_in *, icp_opcode); +static void neighborIgnoreNonPeer(const struct SOCKADDR_IN *, icp_opcode); static OBJH neighborDumpPeers; static OBJH neighborDumpNonPeers; static void dump_peers(StoreEntry * sentry, peer * peers); @@ -80,16 +80,16 @@ peer * -whichPeer(const struct sockaddr_in * from) +whichPeer(const struct SOCKADDR_IN * from) { int j; - u_short port = ntohs(from->sin_port); - struct in_addr ip = from->sin_addr; + u_short port = ntohs(PORT_FROM_SA(*from)); + struct IN_ADDR ip = ADDR_FROM_SA(*from); peer *p = NULL; - debug(15, 3) ("whichPeer: from %s port %d\n", inet_ntoa(ip), port); + debug(15, 3) ("whichPeer: from %s port %d\n", INET_NTOA(ip), port); for (p = Config.peers; p; p = p->next) { for (j = 0; j < p->n_addresses; j++) { - if (ip.s_addr == p->addresses[j].s_addr && port == p->icp.port) { + if ((memcmp(&ip, &p->addresses[j], sizeof(ip))==0) && port == p->icp.port) { return p; } } @@ -345,10 +345,10 @@ void neighbors_open(int fd) { - struct sockaddr_in name; - socklen_t len = sizeof(struct sockaddr_in); + struct SOCKADDR_IN name; + socklen_t len = sizeof(struct SOCKADDR_IN); struct servent *sep = NULL; - memset(&name, '\0', sizeof(struct sockaddr_in)); + memset(&name, '\0', sizeof(struct SOCKADDR_IN)); if (getsockname(fd, (struct sockaddr *) &name, &len) < 0) debug(15, 1) ("getsockname(%d,%p,%p) failed.\n", fd, &name, &len); peerRefreshDNS((void *) 1); @@ -359,7 +359,7 @@ echo_hdr.reqnum = 0; echo_hdr.flags = 0; echo_hdr.pad = 0; - echo_hdr.shostid = name.sin_addr.s_addr; + xmemcpy(&echo_hdr.shostid, &ADDR_FROM_SA(name), sizeof(echo_hdr.shostid)); sep = getservbyname("echo", "udp"); echo_port = sep ? ntohs((u_short) sep->s_port) : 7; } @@ -482,7 +482,7 @@ /* only do source_ping if we have neighbors */ if (Config.npeers) { const ipcache_addrs *ia = NULL; - struct sockaddr_in to_addr; + struct SOCKADDR_IN to_addr; char *host = request->host; if (!Config.onoff.source_ping) { debug(15, 6) ("neighborsUdpPing: Source Ping is disabled.\n"); @@ -493,9 +493,7 @@ if (icmp_sock != -1) { icmpSourcePing(ia->in_addrs[ia->cur], &echo_hdr, url); } else { - to_addr.sin_family = AF_INET; - to_addr.sin_addr = ia->in_addrs[ia->cur]; - to_addr.sin_port = htons(echo_port); + CLEAR_AND_SET_SA(to_addr, echo_port, ia->in_addrs[ia->cur]); query = icpCreateMessage(ICP_SECHO, 0, url, reqnum, 0); icpUdpSend(theOutIcpConnection, &to_addr, @@ -700,23 +698,23 @@ static peer *non_peers = NULL; static void -neighborIgnoreNonPeer(const struct sockaddr_in *from, icp_opcode opcode) +neighborIgnoreNonPeer(const struct SOCKADDR_IN *from, icp_opcode opcode) { peer *np; for (np = non_peers; np; np = np->next) { - if (np->in_addr.sin_addr.s_addr != from->sin_addr.s_addr) + if (memcmp(&ADDR_FROM_SA(np->in_addr), &ADDR_FROM_SA(*from), sizeof(struct IN_ADDR))) continue; - if (np->in_addr.sin_port != from->sin_port) + if (PORT_FROM_SA(np->in_addr) != PORT_FROM_SA(*from)) continue; break; } if (np == NULL) { np = xcalloc(1, sizeof(peer)); - np->in_addr.sin_addr = from->sin_addr; - np->in_addr.sin_port = from->sin_port; - np->icp.port = ntohl(from->sin_port); + ADDR_FROM_SA(np->in_addr) = ADDR_FROM_SA(*from); + PORT_FROM_SA(np->in_addr) = PORT_FROM_SA(*from); + np->icp.port = ntohl(PORT_FROM_SA(*from)); np->type = PEER_NONE; - np->host = xstrdup(inet_ntoa(from->sin_addr)); + np->host = xstrdup(SA_NTOA(*from)); np->next = non_peers; non_peers = np; } @@ -751,7 +749,7 @@ * If a hit process is already started, then sobeit */ void -neighborsUdpAck(const cache_key * key, icp_common_t * header, const struct sockaddr_in *from) +neighborsUdpAck(const cache_key * key, icp_common_t * header, const struct SOCKADDR_IN *from) { peer *p = NULL; StoreEntry *entry; @@ -841,7 +839,7 @@ mem->ping_reply_callback(NULL, ntype, PROTO_ICP, header, mem->ircb_data); #endif } else { - debug(15, 1) ("Unsolicited SECHO from %s\n", inet_ntoa(from->sin_addr)); + debug(15, 1) ("Unsolicited SECHO from %s\n", SA_NTOA(*from)); } } else if (opcode == ICP_DENIED) { if (p == NULL) { @@ -949,7 +947,7 @@ peerDNSConfigure(const ipcache_addrs * ia, void *data) { peer *p = data; - struct sockaddr_in *ap; + struct SOCKADDR_IN *ap; int j; if (p->n_addresses == 0) { debug(15, 1) ("Configuring %s %s/%d/%d\n", neighborTypeStr(p), @@ -968,14 +966,11 @@ } for (j = 0; j < (int) ia->count && j < PEER_MAX_ADDRESSES; j++) { p->addresses[j] = ia->in_addrs[j]; - debug(15, 2) ("--> IP address #%d: %s\n", j, inet_ntoa(p->addresses[j])); + debug(15, 2) ("--> IP address #%d: %s\n", j, INET_NTOA(p->addresses[j])); p->n_addresses++; } ap = &p->in_addr; - memset(ap, '\0', sizeof(struct sockaddr_in)); - ap->sin_family = AF_INET; - ap->sin_addr = p->addresses[0]; - ap->sin_port = htons(p->icp.port); + CLEAR_AND_SET_SA(*ap, p->icp.port, p->addresses[0]); if (p->type == PEER_MULTICAST) peerCountMcastPeersSchedule(p, 10); if (p->type != PEER_MULTICAST) @@ -1100,7 +1095,7 @@ LOCAL_ARRAY(char, url, MAX_URL); assert(p->type == PEER_MULTICAST); p->mcast.flags.count_event_pending = 0; - snprintf(url, MAX_URL, "http://%s/", inet_ntoa(p->in_addr.sin_addr)); + snprintf(url, MAX_URL, "http://%s/", SA_NTOA(p->in_addr)); fake = storeCreateEntry(url, url, null_request_flags, METHOD_GET); psstate->request = requestLink(urlParse(METHOD_GET, url)); psstate->entry = fake; @@ -1237,7 +1232,7 @@ dump_peer_options(sentry, e); for (i = 0; i < e->n_addresses; i++) { storeAppendPrintf(sentry, "Address[%d] : %s\n", i, - inet_ntoa(e->addresses[i])); + INET_NTOA(e->addresses[i])); } storeAppendPrintf(sentry, "Status : %s\n", neighborUp(e) ? "Up" : "Down"); @@ -1297,7 +1292,7 @@ #if USE_HTCP void -neighborsHtcpReply(const cache_key * key, htcpReplyData * htcp, const struct sockaddr_in *from) +neighborsHtcpReply(const cache_key * key, htcpReplyData * htcp, const struct SOCKADDR_IN *from) { StoreEntry *e = storeGet(key); MemObject *mem = NULL; Index: squid/src/net_db.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/net_db.c,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -r1.6 -r1.6.2.1 --- squid/src/net_db.c 14 Nov 2000 13:03:47 -0000 1.6 +++ squid/src/net_db.c 7 Dec 2000 13:58:12 -0000 1.6.2.1 @@ -1,6 +1,6 @@ /* - * $Id: net_db.c,v 1.6 2000/11/14 13:03:47 adri Exp $ + * $Id: net_db.c,v 1.6.2.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 38 Network Measurement Database * AUTHOR: Duane Wessels @@ -51,9 +51,9 @@ static hash_table *addr_table = NULL; static hash_table *host_table = NULL; -static struct in_addr networkFromInaddr(struct in_addr a); +static struct IN_ADDR networkFromInaddr(struct IN_ADDR a); static void netdbRelease(netdbEntry * n); -static void netdbHashInsert(netdbEntry * n, struct in_addr addr); +static void netdbHashInsert(netdbEntry * n, struct IN_ADDR addr); static void netdbHashDelete(const char *key); static void netdbHostInsert(netdbEntry * n, const char *hostname); static void netdbHostDelete(const net_db_name * x); @@ -78,9 +78,9 @@ static wordlist *peer_names = NULL; static void -netdbHashInsert(netdbEntry * n, struct in_addr addr) +netdbHashInsert(netdbEntry * n, struct IN_ADDR addr) { - xstrncpy(n->network, inet_ntoa(networkFromInaddr(addr)), 16); + xstrncpy(n->network, INET_NTOA(networkFromInaddr(addr)), MAXIPSTRLEN); n->hash.key = n->network; assert(hash_lookup(addr_table, n->network) == NULL); hash_join(addr_table, &n->hash); @@ -198,16 +198,16 @@ } static netdbEntry * -netdbLookupAddr(struct in_addr addr) +netdbLookupAddr(struct IN_ADDR addr) { netdbEntry *n; - char *key = inet_ntoa(networkFromInaddr(addr)); + char *key = INET_NTOA(networkFromInaddr(addr)); n = (netdbEntry *) hash_lookup(addr_table, key); return n; } static netdbEntry * -netdbAdd(struct in_addr addr) +netdbAdd(struct IN_ADDR addr) { netdbEntry *n; if (memInUse(MEM_NETDBENTRY) > Config.Netdb.high) @@ -222,7 +222,7 @@ static void netdbSendPing(const ipcache_addrs * ia, void *data) { - struct in_addr addr; + struct IN_ADDR addr; char *hostname = data; netdbEntry *n; netdbEntry *na; @@ -277,10 +277,22 @@ cbdataFree(hostname); } -static struct in_addr -networkFromInaddr(struct in_addr a) +static struct IN_ADDR +networkFromInaddr(struct IN_ADDR a) { - struct in_addr b; + struct IN_ADDR b; + +#if INET6 + memset(&b, '\0', sizeof(b)); + /* is it IPv4 mapped or compatible address? */ + if (IN6_IS_ADDR_V4COMPAT(&a) || IN6_IS_ADDR_V4MAPPED(&a)) { + /* we treat an IPv4 /24 */ + memcpy(&b, &a, 15); + } else { + /* otherwise we always use /64 ?? */ + memcpy(&b, &a, 8); + } +#else /* INET6 */ b.s_addr = ntohl(a.s_addr); #if USE_CLASSFUL if (IN_CLASSC(b.s_addr)) @@ -289,11 +301,12 @@ b.s_addr &= IN_CLASSB_NET; else if (IN_CLASSA(b.s_addr)) b.s_addr &= IN_CLASSA_NET; -#else +#else /* USE_CLASSFUL */ /* use /24 for everything */ b.s_addr &= IN_CLASSC_NET; -#endif +#endif /* USE_CLASSFUL */ b.s_addr = htonl(b.s_addr); +#endif /* INET6 */ return b; } @@ -426,7 +439,7 @@ struct stat sb; netdbEntry *n; netdbEntry N; - struct in_addr addr; + struct IN_ADDR addr; int count = 0; struct timeval start = current_time; snprintf(path, SQUID_MAXPATHLEN, "%s/netdb_state", storeSwapDir(0)); @@ -454,7 +467,7 @@ t = s + 1; if (NULL == q) continue; - if (!safe_inet_addr(q, &addr)) + if (!SAFE_INET_ADDR(q, &addr)) continue; if (netdbLookupAddr(addr) != NULL) /* no dups! */ continue; @@ -530,7 +543,7 @@ netdbExchangeState *ex = data; int rec_sz = 0; off_t o; - struct in_addr addr; + struct IN_ADDR addr; double rtt; double hops; char *p; @@ -539,7 +552,7 @@ size_t hdr_sz; int nused = 0; rec_sz = 0; - rec_sz += 1 + sizeof(addr.s_addr); + rec_sz += 1 + sizeof(addr); rec_sz += 1 + sizeof(int); rec_sz += 1 + sizeof(int); ex->seen = ex->used + size; @@ -577,14 +590,14 @@ while (size >= rec_sz) { debug(38, 5) ("netdbExchangeHandleReply: in parsing loop, size = %d\n", size); - addr.s_addr = any_addr.s_addr; + addr = any_addr; hops = rtt = 0.0; for (o = 0; o < rec_sz;) { switch ((int) *(p + o)) { case NETDB_EX_NETWORK: o++; - xmemcpy(&addr.s_addr, p + o, sizeof(addr.s_addr)); - o += sizeof(addr.s_addr); + xmemcpy(&addr, p + o, sizeof(addr)); + o += sizeof(addr); break; case NETDB_EX_RTT: o++; @@ -604,7 +617,7 @@ return; } } - if (addr.s_addr != any_addr.s_addr && rtt > 0) + if (!ADDR_IS_ANYADDR(addr) && rtt > 0) netdbExchangeUpdatePeer(addr, ex->p, rtt, hops); assert(o == rec_sz); ex->used += rec_sz; @@ -690,13 +703,13 @@ } void -netdbHandlePingReply(const struct sockaddr_in *from, int hops, int rtt) +netdbHandlePingReply(const struct SOCKADDR_IN *from, int hops, int rtt) { #if USE_ICMP netdbEntry *n; int N; - debug(38, 3) ("netdbHandlePingReply: from %s\n", inet_ntoa(from->sin_addr)); - if ((n = netdbLookupAddr(from->sin_addr)) == NULL) + debug(38, 3) ("netdbHandlePingReply: from %s\n", SA_NTOA(from)); + if ((n = netdbLookupAddr(ADDR_FROM_SA(*from))) == NULL) return; N = ++n->pings_recv; if (N > 5) @@ -728,7 +741,7 @@ } int -netdbHops(struct in_addr addr) +netdbHops(struct IN_ADDR addr) { #if USE_ICMP netdbEntry *n = netdbLookupAddr(addr); @@ -752,7 +765,7 @@ int j; net_db_peer *p; storeAppendPrintf(sentry, "Network DB Statistics:\n"); - storeAppendPrintf(sentry, "%-16.16s %9s %7s %5s %s\n", + storeAppendPrintf(sentry, "%-MAXIPSTRLEN.MAXIPSTRLENs %9s %7s %5s %s\n", "Network", "recv/sent", "RTT", @@ -772,7 +785,7 @@ sortByRtt); for (k = 0; k < i; k++) { n = *(list + k); - storeAppendPrintf(sentry, "%-16.16s %4d/%4d %7.1f %5.1f", + storeAppendPrintf(sentry, "%-MAXIPSTRLEN.MAXIPSTRLENs %4d/%4d %7.1f %5.1f", n->network, n->pings_recv, n->pings_sent, @@ -878,13 +891,13 @@ } void -netdbExchangeUpdatePeer(struct in_addr addr, peer * e, double rtt, double hops) +netdbExchangeUpdatePeer(struct IN_ADDR addr, peer * e, double rtt, double hops) { #if USE_ICMP netdbEntry *n; net_db_peer *p; debug(38, 5) ("netdbExchangeUpdatePeer: '%s', %0.1f hops, %0.1f rtt\n", - inet_ntoa(addr), hops, rtt); + INET_NTOA(addr), hops, rtt); n = netdbLookupAddr(addr); if (n == NULL) n = netdbAdd(addr); @@ -904,7 +917,7 @@ } void -netdbDeleteAddrNetwork(struct in_addr addr) +netdbDeleteAddrNetwork(struct IN_ADDR addr) { #if USE_ICMP netdbEntry *n = netdbLookupAddr(addr); @@ -926,7 +939,7 @@ int j; int rec_sz; char *buf; - struct in_addr addr; + struct IN_ADDR addr; storeBuffer(s); httpReplyReset(reply); httpBuildVersion(&version, 1, 0); @@ -934,7 +947,7 @@ NULL, -1, squid_curtime, -2); httpReplySwapOut(reply, s); rec_sz = 0; - rec_sz += 1 + sizeof(addr.s_addr); + rec_sz += 1 + sizeof(addr); rec_sz += 1 + sizeof(int); rec_sz += 1 + sizeof(int); buf = memAllocate(MEM_4K_BUF); @@ -945,10 +958,10 @@ continue; if (n->rtt > 60000) /* RTT > 1 MIN probably bogus */ continue; - if (!safe_inet_addr(n->network, &addr)) + if (!SAFE_INET_ADDR(n->network, &addr)) continue; buf[i++] = (char) NETDB_EX_NETWORK; - xmemcpy(&buf[i], &addr.s_addr, sizeof(addr.s_addr)); + xmemcpy(&buf[i], &addr, sizeof(addr)); i += sizeof(addr.s_addr); buf[i++] = (char) NETDB_EX_RTT; j = htonl((int) (n->rtt * 1000)); Index: squid/src/peer_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/peer_select.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/peer_select.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/peer_select.c 7 Dec 2000 13:58:12 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: peer_select.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: peer_select.c,v 1.3.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 44 Peer Selection Algorithm * AUTHOR: Duane Wessels @@ -391,10 +391,10 @@ code = SOURCE_FASTEST; } else #endif - if (ps->closest_parent_miss.sin_addr.s_addr != any_addr.s_addr) { + if (!SA_IS_ANYADDR(ps->closest_parent_miss)) { p = whichPeer(&ps->closest_parent_miss); code = CLOSEST_PARENT_MISS; - } else if (ps->first_parent_miss.sin_addr.s_addr != any_addr.s_addr) { + } else if (!SA_IS_ANYADDR(ps->first_parent_miss)) { p = whichPeer(&ps->first_parent_miss); code = FIRST_PARENT_MISS; } @@ -525,7 +525,7 @@ if (p->options.closest_only) return; /* set FIRST_MISS if there is no CLOSEST parent */ - if (ps->closest_parent_miss.sin_addr.s_addr != any_addr.s_addr) + if (!SA_IS_ANYADDR(ps->closest_parent_miss)) return; rtt = tvSubMsec(ps->ping.start, current_time) / p->weight; if (ps->ping.w_rtt == 0 || rtt < ps->ping.w_rtt) { @@ -612,7 +612,7 @@ if (p->options.closest_only) return; /* set FIRST_MISS if there is no CLOSEST parent */ - if (ps->closest_parent_miss.sin_addr.s_addr != any_addr.s_addr) + if (!SA_IS_ANYADDR(ps->closest_parent_miss)) return; rtt = tvSubMsec(ps->ping.start, current_time) / p->weight; if (ps->ping.w_rtt == 0 || rtt < ps->ping.w_rtt) { Index: squid/src/pinger.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/pinger.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/pinger.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/pinger.c 7 Dec 2000 13:58:12 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: pinger.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: pinger.c,v 1.3.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 42 ICMP Pinger program * AUTHOR: Duane Wessels @@ -115,7 +115,7 @@ static int in_cksum(unsigned short *ptr, int size); static void pingerRecv(void); -static void pingerLog(struct icmphdr *, struct in_addr, int, int); +static void pingerLog(struct icmphdr *, struct IN_ADDR, int, int); static int ipHops(int ttl); static void pingerSendtoSquid(pingerReplyData * preply); @@ -134,6 +134,21 @@ } icmp_ident = getpid() & 0xffff; debug(42, 0) ("pinger: ICMP socket opened\n"); + +#if INET6 + /* we open the socket for ICMPv6 as well */ + struct protoent *proto = NULL; + if ((proto = getprotobyname("ipv6-icmp")) == 0) { + debug(42, 0) ("pingerOpen: unknown protocol: ipv6-icmp\n"); + exit(1); + } + icmp_sock = socket(PF_INET6, SOCK_RAW, proto->p_proto); + if (icmp6_sock < 0) { + debug(50, 0) ("pingerOpen: icmp6_sock: %s\n", xstrerror()); + exit(1); + } + debug(42, 0) ("pinger: ICMPv6 socket opened\n"); +#endif } void @@ -145,15 +160,25 @@ } static void -pingerSendEcho(struct in_addr to, int opcode, char *payload, int len) +pingerSendEchoSock(struct IN_ADDR to, int opcode, char *payload, int len, int thesock) { LOCAL_ARRAY(char, pkt, MAX_PKT_SZ); +#if INET6 + struct icmp6_hdr *icmp = NULL; + int icmp_pktsize = sizeof(struct icmp6_hdr); +#else struct icmphdr *icmp = NULL; - icmpEchoData *echo; int icmp_pktsize = sizeof(struct icmphdr); - struct sockaddr_in S; +#endif + icmpEchoData *echo; + struct SOCKADDR_IN S; memset(pkt, '\0', MAX_PKT_SZ); + +#if INET6 + icmp = (struct icmp6_hdr *) (void *) pkt; +#else icmp = (struct icmphdr *) (void *) pkt; +#endif /* * cevans - beware signed/unsigned issues in untrusted data from @@ -162,11 +187,22 @@ if (len < 0) { len = 0; } + +#if INET6 /* they just changed the names..., but if + icmphdr & icmp6_hdr diverge in the future, + then this will need to be broken apart */ + icmp->icmp6_type = ICMP_ECHO; + icmp->icmp6_code = 0; + icmp->icmp6_cksum = 0; + icmp->icmp6_id = icmp_ident; + icmp->icmp6_seq = (u_short) icmp_pkts_sent++; +#else icmp->icmp_type = ICMP_ECHO; icmp->icmp_code = 0; icmp->icmp_cksum = 0; icmp->icmp_id = icmp_ident; icmp->icmp_seq = (u_short) icmp_pkts_sent++; +#endif echo = (icmpEchoData *) (icmp + 1); echo->opcode = (unsigned char) opcode; echo->tv = current_time; @@ -178,28 +214,43 @@ icmp_pktsize += len; } icmp->icmp_cksum = in_cksum((u_short *) icmp, icmp_pktsize); - S.sin_family = AF_INET; /* * cevans: alert: trusting to-host, was supplied in network packet */ - S.sin_addr = to; - S.sin_port = 0; + CLEAR_AND_SET_SA(S, 0, to); assert(icmp_pktsize <= MAX_PKT_SZ); - sendto(icmp_sock, + sendto(thesock, pkt, icmp_pktsize, 0, (struct sockaddr *) &S, - sizeof(struct sockaddr_in)); + sizeof(struct SOCKADDR_IN)); pingerLog(icmp, to, 0, 0); } + +static void +pingerSendEcho(struct IN_ADDR to, int opcode, char *payload, int len) +{ +#if INET6 + if (IN6_IS_ADDR_V4COMPAT(&to) || IN6_IS_ADDR_V4MAPPED(&to)) { + /* we're sending V4 icmp anyway */ + pingerSendEchoSock(to, opcode, payload, len, icmp_sock); + } else { + pingerSendEchoSock(to, opcode, payload, len, icmp6_sock); + } +#else + _pingerSendEcho(to, opcode, payload, len, icmp6_sock); +#endif +} + + static void -pingerRecv(void) +pingerRecv(int thesock) { int n; socklen_t fromlen; - struct sockaddr_in from; + struct SOCKADDR_IN from; int iphdrlen = 20; struct iphdr *ip = NULL; struct icmphdr *icmp = NULL; @@ -211,7 +262,7 @@ if (pkt == NULL) pkt = xmalloc(MAX_PKT_SZ); fromlen = sizeof(from); - n = recvfrom(icmp_sock, + n = recvfrom(thesock, pkt, MAX_PKT_SZ, 0, @@ -222,7 +273,13 @@ #else gettimeofday(&now, NULL); #endif - debug(42, 9) ("pingerRecv: %d bytes from %s\n", n, inet_ntoa(from.sin_addr)); + debug(42, 9) ("pingerRecv: %d bytes from %s\n", n, SA_NTOA(from)); +#if INET6 + /* IPv6 specifies we don't get the IP header as data */ + icmp = (struct icmphdr *) (void *) pkt; + if (icmp->icmp_type == ICMP6_ECHO_REPLY) + icmp->icmp_type = ICMP_ECHOREPLY; /* translate into IPv4 constants table * +#else /* INET6 */ ip = (struct iphdr *) (void *) pkt; #if HAVE_IP_HL iphdrlen = ip->ip_hl << 2; @@ -234,18 +291,26 @@ #endif #endif /* HAVE_IP_HL */ icmp = (struct icmphdr *) (void *) (pkt + iphdrlen); +#endif /* INET6 */ if (icmp->icmp_type != ICMP_ECHOREPLY) return; if (icmp->icmp_id != icmp_ident) return; echo = (icmpEchoData *) (void *) (icmp + 1); - preply.from = from.sin_addr; + preply.from = ADDR_FROM_SA(from); preply.opcode = echo->opcode; - preply.hops = ipHops(ip->ip_ttl); preply.rtt = tvSubMsec(echo->tv, now); +#if INET6 + preply.hops = 10; /* ** FIXME ** ** FIXME ** we lie, when we should be + using the advanced sockets API? */ + preply.psize = n - (sizeof(icmpEchoData) - MAX_PKT_SZ); /* Huh? I think the algebra is wrong, + but no one ever looks at this field*/ +#else + preply.hops = ipHops(ip->ip_ttl); preply.psize = n - iphdrlen - (sizeof(icmpEchoData) - MAX_PKT_SZ); +#endif pingerSendtoSquid(&preply); - pingerLog(icmp, from.sin_addr, preply.rtt, preply.hops); + pingerLog(icmp, ADDR_FROM_SA(from), preply.rtt, preply.hops); } @@ -272,14 +337,17 @@ } static void -pingerLog(struct icmphdr *icmp, struct in_addr addr, int rtt, int hops) +pingerLog(struct icmphdr *icmp, struct IN_ADDR addr, int rtt, int hops) { - debug(42, 2) ("pingerLog: %9d.%06d %-16s %d %-15.15s %dms %d hops\n", + int type = icmp->icmp_type; + if (type > 17) + type = 17; + debug(42, 2) ("pingerLog: %9d.%06d %-MAXIPSTRLENs %d %-15.15s %dms %d hops\n", (int) current_time.tv_sec, (int) current_time.tv_usec, - inet_ntoa(addr), + INET_NTOA(addr), (int) icmp->icmp_type, - icmpPktStr[icmp->icmp_type], + icmpPktStr[type], rtt, hops); } @@ -381,7 +449,12 @@ FD_ZERO(&R); FD_SET(0, &R); FD_SET(icmp_sock, &R); +#if INET6 + FD_SET(icmp6_sock, &R); + x = select(icmp6_sock + 1, &R, NULL, NULL, &tv); +#else x = select(icmp_sock + 1, &R, NULL, NULL, &tv); +#endif getCurrentTime(); if (x < 0) exit(1); @@ -391,7 +464,11 @@ exit(1); } if (FD_ISSET(icmp_sock, &R)) - pingerRecv(); + pingerRecv(icmp_sock); +#if INET6 + if (FD_ISSET(icmp6_sock, &R)) + pingerRecv(icmp6_sock); +#endif if (10 + last_check_time < squid_curtime) { if (send(1, (char *) &tv, 0, 0) < 0) exit(1); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- squid/src/protos.h 14 Nov 2000 13:03:47 -0000 1.5 +++ squid/src/protos.h 7 Dec 2000 13:58:12 -0000 1.5.2.1 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.5 2000/11/14 13:03:47 adri Exp $ + * $Id: protos.h,v 1.5.2.1 2000/12/07 13:58:12 rvenning Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -101,11 +101,11 @@ extern CBDUNL cbdataXfree; extern void clientdbInit(void); -extern void clientdbUpdate(struct in_addr, log_type, protocol_t, size_t); -extern int clientdbCutoffDenied(struct in_addr); +extern void clientdbUpdate(struct IN_ADDR, log_type, protocol_t, size_t); +extern int clientdbCutoffDenied(struct IN_ADDR); extern void clientdbDump(StoreEntry *); extern void clientdbFreeMemory(void); -extern int clientdbEstablished(struct in_addr, int); +extern int clientdbEstablished(struct IN_ADDR, int); extern void clientAccessCheck(void *); extern void clientAccessCheckDone(int, void *); @@ -121,22 +121,22 @@ extern int commSetNonBlocking(int fd); extern int commUnsetNonBlocking(int fd); extern void commSetCloseOnExec(int fd); -extern int comm_accept(int fd, struct sockaddr_in *, struct sockaddr_in *); +extern int comm_accept(int fd, struct SOCKADDR_IN *, struct SOCKADDR_IN *); extern void comm_close(int fd); #if LINGERING_CLOSE extern void comm_lingering_close(int fd); #endif extern void commConnectStart(int fd, const char *, u_short, CNCB *, void *); -extern int comm_connect_addr(int sock, const struct sockaddr_in *); +extern int comm_connect_addr(int sock, const struct SOCKADDR_IN *); extern void comm_init(void); extern int comm_listen(int sock); -extern int comm_open(int, int, struct in_addr, u_short port, int, const char *note); +extern int comm_open(int, int, struct IN_ADDR, u_short port, int, const char *note); extern u_short comm_local_port(int fd); extern void commSetSelect(int, unsigned int, PF *, void *, time_t); extern void comm_add_close_handler(int fd, PF *, void *); extern void comm_remove_close_handler(int fd, PF *, void *); -extern int comm_udp_sendto(int, const struct sockaddr_in *, int, const void *, int); +extern int comm_udp_sendto(int, const struct SOCKADDR_IN *, int, const void *, int); extern void comm_write(int fd, char *buf, int size, @@ -221,7 +221,7 @@ extern void idnsInit(void); extern void idnsShutdown(void); extern void idnsALookup(const char *, IDNSCB *, void *); -extern void idnsPTRLookup(const struct in_addr, IDNSCB *, void *); +extern void idnsPTRLookup(const struct IN_ADDR, IDNSCB *, void *); extern void eventAdd(const char *name, EVH * func, void *arg, double when, int); extern void eventAddIsh(const char *name, EVH * func, void *arg, double delta_ish, int); @@ -249,12 +249,12 @@ extern void filemapFreeMemory(fileMap *); -extern void fqdncache_nbgethostbyaddr(struct in_addr, FQDNH *, void *); -extern const char *fqdncache_gethostbyaddr(struct in_addr, int flags); +extern void fqdncache_nbgethostbyaddr(struct IN_ADDR, FQDNH *, void *); +extern const char *fqdncache_gethostbyaddr(struct IN_ADDR, int flags); extern void fqdncache_init(void); extern void fqdnStats(StoreEntry *); extern void fqdncacheReleaseInvalid(const char *); -extern const char *fqdnFromAddr(struct in_addr); +extern const char *fqdnFromAddr(struct IN_ADDR); extern int fqdncacheQueueDrain(void); extern void fqdncacheFreeMemory(void); extern void fqdncache_restart(void); @@ -486,16 +486,16 @@ extern void icmpOpen(void); extern void icmpClose(void); -extern void icmpPing(struct in_addr to); -extern void icmpSourcePing(struct in_addr to, const icp_common_t *, const char *url); -extern void icmpDomainPing(struct in_addr to, const char *domain); +extern void icmpPing(struct IN_ADDR to); +extern void icmpSourcePing(struct IN_ADDR to, const icp_common_t *, const char *url); +extern void icmpDomainPing(struct IN_ADDR to, const char *domain); extern void *icpCreateMessage(icp_opcode opcode, int flags, const char *url, int reqnum, int pad); -extern int icpUdpSend(int, const struct sockaddr_in *, icp_common_t *, log_type, int); +extern int icpUdpSend(int, const struct SOCKADDR_IN *, icp_common_t *, log_type, int); extern PF icpHandleUdp; extern PF icpUdpSendQueue; extern PF httpAccept; @@ -534,7 +534,7 @@ extern void wccpConnectionClose(void); #endif /* USE_WCCP */ -extern void icpHandleIcpV3(int, struct sockaddr_in, char *, int); +extern void icpHandleIcpV3(int, struct SOCKADDR_IN, char *, int); extern int icpCheckUdpHit(StoreEntry *, request_t * request); extern void icpConnectionsOpen(void); extern void icpConnectionShutdown(void); @@ -553,8 +553,8 @@ extern void stat_ipcache_get(StoreEntry *); extern int ipcacheQueueDrain(void); extern void ipcacheCycleAddr(const char *name, ipcache_addrs *); -extern void ipcacheMarkBadAddr(const char *name, struct in_addr); -extern void ipcacheMarkGoodAddr(const char *name, struct in_addr); +extern void ipcacheMarkBadAddr(const char *name, struct IN_ADDR); +extern void ipcacheMarkGoodAddr(const char *name, struct IN_ADDR); extern void ipcacheFreeMemory(void); extern ipcache_addrs *ipcacheCheckNumeric(const char *name); extern void ipcache_restart(void); @@ -619,7 +619,7 @@ int *exprep, int *timeout); extern void neighborAddAcl(const char *, const char *); -extern void neighborsUdpAck(const cache_key *, icp_common_t *, const struct sockaddr_in *); +extern void neighborsUdpAck(const cache_key *, icp_common_t *, const struct SOCKADDR_IN *); extern void neighborAdd(const char *, const char *, int, int, int, int, int); extern void neighbors_open(int); extern peer *peerFindByName(const char *); @@ -640,27 +640,27 @@ extern void peerConnectSucceded(peer *); extern void dump_peer_options(StoreEntry *, peer *); extern int peerHTTPOkay(const peer *, request_t *); -extern peer *whichPeer(const struct sockaddr_in *from); +extern peer *whichPeer(const struct SOCKADDR_IN *from); #if USE_HTCP -extern void neighborsHtcpReply(const cache_key *, htcpReplyData *, const struct sockaddr_in *); +extern void neighborsHtcpReply(const cache_key *, htcpReplyData *, const struct SOCKADDR_IN *); #endif extern void netdbInit(void); -extern void netdbHandlePingReply(const struct sockaddr_in *from, int hops, int rtt); +extern void netdbHandlePingReply(const struct SOCKADDR_IN *from, int hops, int rtt); extern void netdbPingSite(const char *hostname); extern void netdbInit(void); extern void netdbDump(StoreEntry *); -extern int netdbHops(struct in_addr); +extern int netdbHops(struct IN_ADDR); extern void netdbFreeMemory(void); extern int netdbHostHops(const char *host); extern int netdbHostRtt(const char *host); extern int netdbHostPeerRtt(const char *host, peer * peer); extern void netdbUpdatePeer(request_t *, peer * e, int rtt, int hops); -extern void netdbDeleteAddrNetwork(struct in_addr addr); +extern void netdbDeleteAddrNetwork(struct IN_ADDR addr); extern int netdbHostPeerRtt(const char *host, peer * peer); extern void netdbBinaryExchange(StoreEntry *); extern EVH netdbExchangeStart; -extern void netdbExchangeUpdatePeer(struct in_addr, peer *, double, double); +extern void netdbExchangeUpdatePeer(struct IN_ADDR, peer *, double, double); extern peer *netdbClosestParent(request_t *); extern void netdbHostData(const char *host, int *samp, int *rtt, int *hops); @@ -721,7 +721,7 @@ /* ident.c */ #if USE_IDENT -extern void identStart(struct sockaddr_in *me, struct sockaddr_in *peer, IDCB * callback, void *cbdata); +extern void identStart(struct SOCKADDR_IN *me, struct SOCKADDR_IN *peer, IDCB * callback, void *cbdata); extern void identInit(void); #endif @@ -1004,7 +1004,7 @@ extern double dpercent(double, double); extern void squid_signal(int sig, SIGHDLR *, int flags); extern pid_t readPidFile(void); -extern struct in_addr inaddrFromHostent(const struct hostent *hp); +extern struct IN_ADDR inaddrFromHostent(const struct hostent *hp); extern int intAverage(int, int, int, int); extern double doubleAverage(double, double, int, int); extern void debug_trap(const char *); @@ -1219,3 +1219,4 @@ #if URL_CHECKSUM_DEBUG extern unsigned int url_checksum(const char *url); #endif + Index: squid/src/recv-announce.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/recv-announce.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/recv-announce.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/recv-announce.c 7 Dec 2000 13:58:12 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: recv-announce.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: recv-announce.c,v 1.3.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 0 Announcement Server * AUTHOR: Harvest Derived @@ -85,11 +85,11 @@ main(int argc, char *argv[]) { char buf[RECV_BUF_SIZE]; - struct sockaddr_in R; + struct SOCKADDR_IN R; int len; struct hostent *hp = NULL; char logfile[BUFSIZ]; - char ip[4]; + struct IN_ADDR ip; for (len = 0; len < 32; len++) { signal(len, sig_handle); @@ -118,11 +118,11 @@ perror("recv"); exit(2); } - xmemcpy(ip, &R.sin_addr.s_addr, 4); - hp = gethostbyaddr(ip, 4, AF_INET); + xmemcpy(ip, &ADDR_FROM_SA(R), sizeof(struct IN_ADDR); + hp = gethostbyaddr(ip, sizeof(ip), AF_FAMILY); printf("==============================================================================\n"); printf("Received from %s [%s]\n", - inet_ntoa(R.sin_addr), + SA_NTOA(R), (hp && hp->h_name) ? hp->h_name : "Unknown"); fputs(buf, stdout); fflush(stdout); Index: squid/src/redirect.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/redirect.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/redirect.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/redirect.c 7 Dec 2000 13:58:12 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: redirect.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: redirect.c,v 1.3.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 29 Redirector * AUTHOR: Duane Wessels @@ -38,7 +38,7 @@ typedef struct { void *data; char *orig_url; - struct in_addr client_addr; + struct IN_ADDR client_addr; const char *client_ident; const char *method_s; RH *handler; @@ -106,9 +106,9 @@ if (Config.accessList.redirector) { aclCheck_t ch; memset(&ch, '\0', sizeof(ch)); - ch.src_addr = http->conn->peer.sin_addr; - ch.my_addr = http->conn->me.sin_addr; - ch.my_port = ntohs(http->conn->me.sin_port); + ch.src_addr = ADDR_FROM_SA(http->conn->peer); + ch.my_addr = ADDR_FROM_SA(http->conn->me); + ch.my_port = ntohs(PORT_FROM_SA(http->conn->me)); ch.request = http->request; if (!aclCheckFast(Config.accessList.redirector, &ch)) { /* denied -- bypass redirector */ @@ -141,7 +141,7 @@ fqdn = dash_str; snprintf(buf, 8192, "%s %s/%s %s %s\n", r->orig_url, - inet_ntoa(r->client_addr), + INET_NTOA(r->client_addr), fqdn, r->client_ident, r->method_s); @@ -179,3 +179,4 @@ helperFree(redirectors); redirectors = NULL; } + Index: squid/src/send-announce.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/send-announce.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/send-announce.c 23 Oct 2000 15:04:21 -0000 1.3 +++ squid/src/send-announce.c 7 Dec 2000 13:58:12 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: send-announce.c,v 1.3 2000/10/23 15:04:21 hno Exp $ + * $Id: send-announce.c,v 1.3.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 27 Cache Announcer * AUTHOR: Duane Wessels @@ -55,7 +55,7 @@ { LOCAL_ARRAY(char, tbuf, 256); LOCAL_ARRAY(char, sndbuf, BUFSIZ); - struct sockaddr_in S; + struct SOCKADDR_IN S; char *host = Config.Announce.host; char *file = NULL; u_short port = Config.Announce.port; @@ -75,7 +75,7 @@ assert(Config.Sockaddr.http); snprintf(tbuf, 256, "Running on %s %d %d\n", getMyHostname(), - (int) ntohs(Config.Sockaddr.http->s.sin_port), + (int) ntohs(PORT_FROM_SA(Config.Sockaddr.http->s)), (int) Config.Port.icp); strcat(sndbuf, tbuf); if (Config.adminEmail) { @@ -98,10 +98,7 @@ debug(50, 1) ("send_announce: %s: %s\n", file, xstrerror()); } } - memset(&S, '\0', sizeof(S)); - S.sin_family = AF_INET; - S.sin_port = htons(port); - S.sin_addr = ia->in_addrs[0]; + CLEAR_AND_SET_SA(S, port, ia->in_addrs[0]); assert(theOutIcpConnection > 0); x = comm_udp_sendto(theOutIcpConnection, &S, sizeof(S), Index: squid/src/snmp_core.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/snmp_core.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/snmp_core.c 23 Oct 2000 15:04:22 -0000 1.3 +++ squid/src/snmp_core.c 7 Dec 2000 13:58:12 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: snmp_core.c,v 1.3 2000/10/23 15:04:22 hno Exp $ + * $Id: snmp_core.c,v 1.3.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 49 SNMP support * AUTHOR: Glenn Chisholm @@ -357,7 +357,7 @@ enter_suid(); theInSnmpConnection = comm_open(SOCK_DGRAM, 0, - Config.Addrs.snmp_incoming, + &Config.Addrs.snmp_incoming, port, COMM_NONBLOCKING, "SNMP Port"); @@ -371,7 +371,7 @@ enter_suid(); theOutSnmpConnection = comm_open(SOCK_DGRAM, 0, - Config.Addrs.snmp_outgoing, + &Config.Addrs.snmp_outgoing, port, COMM_NONBLOCKING, "SNMP Port"); Index: squid/src/ssl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ssl.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -r1.3 -r1.3.6.1 --- squid/src/ssl.c 23 Oct 2000 15:04:22 -0000 1.3 +++ squid/src/ssl.c 7 Dec 2000 13:58:12 -0000 1.3.6.1 @@ -1,6 +1,6 @@ /* - * $Id: ssl.c,v 1.3 2000/10/23 15:04:22 hno Exp $ + * $Id: ssl.c,v 1.3.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -443,7 +443,7 @@ * from peer_digest.c, asn.c, netdb.c, etc and should always * be allowed. yuck, I know. */ - if (request->client_addr.s_addr != no_addr.s_addr) { + if (!ADDR_IS_NOADDR(request->client_addr)) { /* * Check if this host is allowed to fetch MISSES from us (miss_access) */ Index: squid/src/stat.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/stat.c,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -r1.4 -r1.4.6.1 --- squid/src/stat.c 3 Nov 2000 08:39:20 -0000 1.4 +++ squid/src/stat.c 7 Dec 2000 13:58:12 -0000 1.4.6.1 @@ -1,6 +1,6 @@ /* - * $Id: stat.c,v 1.4 2000/11/03 08:39:20 hno Exp $ + * $Id: stat.c,v 1.4.6.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -1406,11 +1406,11 @@ storeAppendPrintf(s, "\tin: buf %p, offset %d, size %d\n", conn->in.buf, conn->in.offset, conn->in.size); storeAppendPrintf(s, "\tpeer: %s:%d\n", - inet_ntoa(conn->peer.sin_addr), - ntohs(conn->peer.sin_port)); + SA_NTOA(conn->peer), + ntohs(PORT_FROM_SA(conn->peer))); storeAppendPrintf(s, "\tme: %s:%d\n", - inet_ntoa(conn->me.sin_addr), - ntohs(conn->me.sin_port)); + SA_NTOA(conn->me), + ntohs(PORT_FROM_SA(conn->me))); storeAppendPrintf(s, "\tnrequests: %d\n", conn->nrequests); storeAppendPrintf(s, "\tpersistent: %d\n", Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -u -r1.7 -r1.7.2.1 --- squid/src/structs.h 14 Nov 2000 13:03:47 -0000 1.7 +++ squid/src/structs.h 7 Dec 2000 13:58:12 -0000 1.7.2.1 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.7 2000/11/14 13:03:47 adri Exp $ + * $Id: structs.h,v 1.7.2.1 2000/12/07 13:58:12 rvenning Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -67,7 +67,7 @@ char *passwd; int passwd_ok; /* 1 = passwd checked OK */ long expiretime; - struct in_addr ipaddr; /* IP addr this user authenticated from */ + struct IN_ADDR ipaddr; /* IP addr this user authenticated from */ time_t ip_expiretime; }; @@ -107,7 +107,7 @@ int sock; long reqid; int outlen; - struct sockaddr_in from; + struct SOCKADDR_IN from; struct snmp_pdu *PDU; aclCheck_t *acl_checklist; u_char *community; @@ -138,9 +138,9 @@ struct _aclCheck_t { const acl_access *access_list; - struct in_addr src_addr; - struct in_addr dst_addr; - struct in_addr my_addr; + struct IN_ADDR src_addr; + struct IN_ADDR dst_addr; + struct IN_ADDR my_addr; unsigned short my_port; request_t *request; #if USE_IDENT @@ -184,7 +184,7 @@ }; struct _sockaddr_in_list { - struct sockaddr_in s; + struct SOCKADDR_IN s; sockaddr_in_list *next; }; @@ -352,14 +352,14 @@ u_short port; } Announce; struct { - struct in_addr tcp_outgoing; - struct in_addr udp_incoming; - struct in_addr udp_outgoing; + struct IN_ADDR tcp_outgoing; + struct IN_ADDR udp_incoming; + struct IN_ADDR udp_outgoing; #if SQUID_SNMP - struct in_addr snmp_incoming; - struct in_addr snmp_outgoing; + struct IN_ADDR snmp_incoming; + struct IN_ADDR snmp_outgoing; #endif - struct in_addr client_netmask; + struct IN_ADDR client_netmask; } Addrs; size_t tcpRcvBufsz; size_t udpMaxHitObjsz; @@ -490,7 +490,7 @@ size_t rangeOffsetLimit; #if MULTICAST_MISS_STREAM struct { - struct in_addr addr; + struct IN_ADDR addr; int ttl; unsigned short port; char *encode_key; @@ -586,7 +586,7 @@ unsigned int type; u_short local_port; u_short remote_port; - char ipaddr[16]; /* dotted decimal address of peer */ + char ipaddr[MAXIPSTRLEN]; /* string representation of IP address (v4 & v6) */ char desc[FD_DESC_SZ]; struct { unsigned int open:1; @@ -804,7 +804,7 @@ }; struct _icpUdpData { - struct sockaddr_in address; + struct SOCKADDR_IN address; void *msg; size_t len; icpUdpData *next; @@ -852,7 +852,7 @@ icp_opcode opcode; } icp; struct { - struct in_addr caddr; + struct IN_ADDR caddr; size_t size; log_type code; int msec; @@ -913,9 +913,9 @@ size_t size; } in; clientHttpRequest *chr; - struct sockaddr_in peer; - struct sockaddr_in me; - struct in_addr log_addr; + struct SOCKADDR_IN peer; + struct SOCKADDR_IN me; + struct IN_ADDR log_addr; char ident[USER_IDENT_SZ]; int nrequests; int persistent; @@ -926,7 +926,7 @@ }; struct _ipcache_addrs { - struct in_addr *in_addrs; + struct IN_ADDR *in_addrs; unsigned char *bad_mask; unsigned char count; unsigned char cur; @@ -1028,7 +1028,7 @@ struct _peer { char *host; peer_t type; - struct sockaddr_in in_addr; + struct SOCKADDR_IN in_addr; struct { int pings_sent; int pings_acked; @@ -1094,7 +1094,7 @@ char *digest_url; #endif int tcp_up; /* 0 if a connect() fails */ - struct in_addr addresses[10]; + struct IN_ADDR addresses[10]; int n_addresses; int rr_count; int rr_lastcount; @@ -1126,7 +1126,7 @@ struct _netdbEntry { hash_link hash; /* must be first */ - char network[16]; + char network[MAXIPSTRLEN]; int pings_sent; int pings_recv; double hops; @@ -1156,8 +1156,8 @@ * the peer * based on the address when we are finally ready to * reference the peer structure. */ - struct sockaddr_in first_parent_miss; - struct sockaddr_in closest_parent_miss; + struct SOCKADDR_IN first_parent_miss; + struct SOCKADDR_IN closest_parent_miss; /* * ->hit and ->secho can be peer* because they should only be * accessed during the thread when they are set @@ -1173,14 +1173,14 @@ #if USE_ICMP struct _pingerEchoData { - struct in_addr to; + struct IN_ADDR to; unsigned char opcode; int psize; char payload[PINGER_PAYLOAD_SZ]; }; struct _pingerReplyData { - struct in_addr from; + struct IN_ADDR from; unsigned char opcode; int rtt; int hops; @@ -1449,8 +1449,8 @@ int imslen; int max_forwards; /* these in_addr's could probably be sockaddr_in's */ - struct in_addr client_addr; - struct in_addr my_addr; + struct IN_ADDR client_addr; + struct IN_ADDR my_addr; unsigned short my_port; HttpHeader header; char *body; @@ -1506,7 +1506,7 @@ u_short port; char *dnsserver_msg; time_t ttl; - struct in_addr src_addr; + struct IN_ADDR src_addr; char *redirect_url; ERCB *callback; void *callback_data; @@ -1717,7 +1717,7 @@ struct _ClientInfo { hash_link hash; /* must be first */ - struct in_addr addr; + struct IN_ADDR addr; struct { int result_hist[LOG_TYPE_MAX]; int n_requests; @@ -1919,3 +1919,11 @@ unsigned int fatal:1; } flags; }; + + + + + + + + Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- squid/src/tools.c 18 Nov 2000 11:01:28 -0000 1.4 +++ squid/src/tools.c 7 Dec 2000 13:58:12 -0000 1.4.2.1 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.4 2000/11/18 11:01:28 adri Exp $ + * $Id: tools.c,v 1.4.2.1 2000/12/07 13:58:12 rvenning Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -434,19 +434,19 @@ if (present) return host; host[0] = '\0'; - if (Config.Sockaddr.http->s.sin_addr.s_addr != any_addr.s_addr) { + if (!SA_IS_ANYADDR(Config.Sockaddr.http->s)) { /* * If the first http_port address has a specific address, try a * reverse DNS lookup on it. */ - h = gethostbyaddr((char *) &Config.Sockaddr.http->s.sin_addr, - sizeof(Config.Sockaddr.http->s.sin_addr), AF_INET); + h = gethostbyaddr((char *) &ADDR_FROM_SA(Config.Sockaddr.http->s), + sizeof(ADDR_FROM_SA(Config.Sockaddr.http->s)), AF_FAMILY); if (h != NULL) { /* DNS lookup successful */ /* use the official name from DNS lookup */ xstrncpy(host, h->h_name, SQUIDHOSTNAMELEN); debug(50, 4) ("getMyHostname: resolved %s to '%s'\n", - inet_ntoa(Config.Sockaddr.http->s.sin_addr), + SA_NTOA(Config.Sockaddr.http->s), host); present = 1; if( strchr( host, '.' ) ) @@ -454,7 +454,7 @@ } debug(50, 1) ("WARNING: failed to resolve %s to a fully qualified hostname\n", - inet_ntoa(Config.Sockaddr.http->s.sin_addr)); + SA_NTOA(Config.Sockaddr.http->s)); } /* * Get the host name and store it in host to return @@ -716,11 +716,11 @@ #endif } -struct in_addr +struct IN_ADDR inaddrFromHostent(const struct hostent *hp) { - struct in_addr s; - xmemcpy(&s.s_addr, hp->h_addr, sizeof(s.s_addr)); + struct IN_ADDR s; + xmemcpy(&s, hp->h_addr, sizeof(s)); return s; }