From 71e8f78fe42979879b77027f376b56eba5d3ba49 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 17 Apr 2009 11:45:19 +0000 Subject: [PATCH] Replace HAVE_GETADDRINFO and HAVE_GETNAMEINFO macros with HAVE_RFC2553 macro. Original patch by Petr Pisar. --- configure.in | 19 ++++++++++++++---- filters.c | 33 +++++++++++++++++-------------- jbsockets.c | 55 +++++++++++++++++++++++++++------------------------- loadcfg.c | 13 ++++++++----- project.h | 17 +++++++++------- 5 files changed, 80 insertions(+), 57 deletions(-) diff --git a/configure.in b/configure.in index 8c4fbac4..262b6fde 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. dnl -dnl $Id: configure.in,v 1.127 2009/03/25 17:26:31 fabiankeil Exp $ +dnl $Id: configure.in,v 1.128 2009/04/17 11:27:49 fabiankeil Exp $ dnl dnl Written by and Copyright (C) 2001-2009 the dnl Privoxy team. http://www.privoxy.org/ @@ -28,6 +28,9 @@ dnl or write to the Free Software Foundation, Inc., 59 dnl Temple Place - Suite 330, Boston, MA 02111-1307, USA. dnl dnl $Log: configure.in,v $ +dnl Revision 1.128 2009/04/17 11:27:49 fabiankeil +dnl Petr Pisar's privoxy-3.0.12-ipv6-3.diff. +dnl dnl Revision 1.127 2009/03/25 17:26:31 fabiankeil dnl And they are running again. Bump version to 3.0.13 UNRELEASED. dnl @@ -569,7 +572,7 @@ dnl ================================================================= dnl AutoConf Initialization dnl ================================================================= -AC_REVISION($Revision: 1.127 $) +AC_REVISION($Revision: 1.128 $) AC_INIT(jcc.c) if test ! -f config.h.in; then @@ -1240,8 +1243,16 @@ AC_FUNC_SETPGRP AC_TYPE_SIGNAL dnl uncommenting does not work for swa. suse linux dnl AC_FUNC_STAT -AC_CHECK_FUNCS([access atexit getaddrinfo getcwd gethostbyaddr gethostbyaddr_r gethostbyname gethostbyname_r getnameinfo gettimeofday inet_ntoa localtime_r memchr memmove memset poll putenv random regcomp select setlocale snprintf socket strchr strdup strerror strftime strlcat strlcpy strptime strstr strtoul timegm tzset]) - +AC_CHECK_FUNCS([access atexit getcwd gethostbyaddr gethostbyaddr_r gethostbyname gethostbyname_r gettimeofday inet_ntoa localtime_r memchr memmove memset poll putenv random regcomp select setlocale snprintf socket strchr strdup strerror strftime strlcat strlcpy strptime strstr strtoul timegm tzset]) + +dnl Checks for RFC 2553 resolver and socket functions +AC_CHECK_FUNC([getaddrinfo], + [AC_CHECK_FUNC([getnameinfo], + [AC_DEFINE([HAVE_RFC2553], [1], + [Define if RFC 2553 resolver functions like getaddrinfo(3) and + getnameinfo(3) present]) + ]) +]) dnl ================================================================= dnl Checks for libraries. diff --git a/filters.c b/filters.c index 602bb0b0..e2c54382 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.118 2009/04/17 11:37:03 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.119 2009/04/17 11:38:28 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -40,6 +40,9 @@ const char filters_rcs[] = "$Id: filters.c,v 1.118 2009/04/17 11:37:03 fabiankei * * Revisions : * $Log: filters.c,v $ + * Revision 1.119 2009/04/17 11:38:28 fabiankeil + * Add and use parse_forwarder_address() to reduce code duplication. + * * Revision 1.118 2009/04/17 11:37:03 fabiankeil * Allow IPv6 addresses in forward-override{}. * @@ -680,10 +683,10 @@ const char filters_rcs[] = "$Id: filters.c,v 1.118 2009/04/17 11:37:03 fabiankei #include #include -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 #include #include -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ #ifndef _WIN32 #ifndef __OS2__ @@ -732,7 +735,7 @@ static jb_err remove_chunked_transfer_coding(char *buffer, size_t *size); static jb_err prepare_for_filtering(struct client_state *csp); #ifdef FEATURE_ACL -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 /********************************************************************* * * Function : sockaddr_storage_to_ip @@ -874,7 +877,7 @@ int match_sockaddr(const struct sockaddr_storage *network, return 1; } -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ /********************************************************************* @@ -907,7 +910,7 @@ int block_acl(const struct access_control_addr *dst, const struct client_state * while (acl != NULL) { if ( -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 match_sockaddr(&acl->src->addr, &acl->src->mask, &csp->tcp_addr) #else (csp->ip_addr_long & acl->src->mask) == acl->src->addr @@ -923,7 +926,7 @@ int block_acl(const struct access_control_addr *dst, const struct client_state * } } else if ( -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 /* * XXX: An undefined acl->dst is full of zeros and should be * considered a wildcard address. sockaddr_storage_to_ip() @@ -974,18 +977,18 @@ int block_acl(const struct access_control_addr *dst, const struct client_state * int acl_addr(const char *aspec, struct access_control_addr *aca) { int i, masklength; -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 struct addrinfo hints, *result; uint8_t *mask_data; in_port_t *mask_port; unsigned int addr_len; #else long port; -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ char *p; char *acl_spec = NULL; -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 /* XXX: Depend on ai_family */ masklength = 128; #else @@ -1016,7 +1019,7 @@ int acl_addr(const char *aspec, struct access_control_addr *aca) } if ((masklength < 0) || -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 (masklength > 128) #else (masklength > 32) @@ -1042,7 +1045,7 @@ int acl_addr(const char *aspec, struct access_control_addr *aca) p = strchr(acl_spec, ':'); } -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -1085,10 +1088,10 @@ int acl_addr(const char *aspec, struct access_control_addr *aca) /* XXX: This will be logged as parse error. */ return(-1); } -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ /* build the netmask */ -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 /* Clip masklength according to current family. */ if ((aca->addr.ss_family == AF_INET) && (masklength > 32)) { @@ -1145,7 +1148,7 @@ int acl_addr(const char *aspec, struct access_control_addr *aca) * (i.e. save on the network portion of the address). */ aca->addr = aca->addr & aca->mask; -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ return(0); diff --git a/jbsockets.c b/jbsockets.c index 3bc67563..990c8e42 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.52 2009/04/17 11:34:34 fabiankeil Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.53 2009/04/17 11:39:52 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -35,6 +35,9 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.52 2009/04/17 11:34:34 fabian * * Revisions : * $Log: jbsockets.c,v $ + * Revision 1.53 2009/04/17 11:39:52 fabiankeil + * If the hostname is 'localhost' or not specified, request an AF_INET address. + * * Revision 1.52 2009/04/17 11:34:34 fabiankeil * Style cosmetics for the IPv6 code. * @@ -362,7 +365,7 @@ const char jbsockets_h_rcs[] = JBSOCKETS_H_VERSION; * file descriptor. * *********************************************************************/ -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 /* Getaddrinfo implementation */ jb_socket connect_to(const char *host, int portnum, struct client_state *csp) { @@ -534,7 +537,7 @@ jb_socket connect_to(const char *host, int portnum, struct client_state *csp) } -# else /* ndef HAVE_GETADDRINFO */ +#else /* ndef HAVE_RFC2553 */ /* Pre-getaddrinfo implementation */ jb_socket connect_to(const char *host, int portnum, struct client_state *csp) @@ -664,7 +667,7 @@ jb_socket connect_to(const char *host, int portnum, struct client_state *csp) return(fd); } -#endif /* ndef HAVE_GETADDRINFO */ +#endif /* ndef HAVE_RFC2553 */ /********************************************************************* @@ -860,7 +863,7 @@ void close_socket(jb_socket fd) *********************************************************************/ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) { -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 struct addrinfo hints; struct addrinfo *result, *rp; /* @@ -872,7 +875,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) int retval; #else struct sockaddr_in inaddr; -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ jb_socket fd; #ifndef _WIN32 int one = 1; @@ -880,7 +883,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) *pfd = JB_INVALID_SOCKET; -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 retval = snprintf(servnam, sizeof(servnam), "%d", portnum); if ((-1 == retval) || (sizeof(servnam) <= retval)) { @@ -941,15 +944,15 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) inaddr.sin_port = htonl((unsigned long) portnum); } #endif /* ndef _WIN32 */ -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 for (rp = result; rp != NULL; rp = rp->ai_next) { fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); #else fd = socket(AF_INET, SOCK_STREAM, 0); -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ #ifdef _WIN32 if (fd == JB_INVALID_SOCKET) @@ -957,7 +960,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) if (fd < 0) #endif { -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 continue; #else return(-1); @@ -980,7 +983,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)); #endif /* ndef _WIN32 */ -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 if (bind(fd, rp->ai_addr, rp->ai_addrlen) < 0) #else if (bind(fd, (struct sockaddr *)&inaddr, sizeof(inaddr)) < 0) @@ -993,7 +996,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) if (errno == EADDRINUSE) #endif { -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 freeaddrinfo(result); #endif close_socket(fd); @@ -1002,7 +1005,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) else { close_socket(fd); -#ifndef HAVE_GETADDRINFO +#ifndef HAVE_RFC2553 return(-1); } } @@ -1027,7 +1030,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) /* All bind()s failed */ return(-1); } -#endif /* ndef HAVE_GETADDRINFO */ +#endif /* ndef HAVE_RFC2553 */ while (listen(fd, MAX_LISTEN_BACKLOG) == -1) { @@ -1067,20 +1070,20 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd) *********************************************************************/ void get_host_information(jb_socket afd, char **ip_address, char **hostname) { -#ifdef HAVE_GETNAMEINFO +#ifdef HAVE_RFC2553 struct sockaddr_storage server; int retval; #else struct sockaddr_in server; struct hostent *host = NULL; -#endif /* HAVE_GETNAMEINFO */ +#endif /* HAVE_RFC2553 */ #if defined(_WIN32) || defined(__OS2__) || defined(__APPLE_CC__) || defined(AMIGA) /* according to accept_connection() this fixes a warning. */ int s_length, s_length_provided; #else socklen_t s_length, s_length_provided; #endif -#ifndef HAVE_GETNAMEINFO +#ifndef HAVE_RFC2553 #if defined(HAVE_GETHOSTBYADDR_R_8_ARGS) || defined(HAVE_GETHOSTBYADDR_R_7_ARGS) || defined(HAVE_GETHOSTBYADDR_R_5_ARGS) struct hostent result; #if defined(HAVE_GETHOSTBYADDR_R_5_ARGS) @@ -1090,7 +1093,7 @@ void get_host_information(jb_socket afd, char **ip_address, char **hostname) int thd_err; #endif /* def HAVE_GETHOSTBYADDR_R_5_ARGS */ #endif /* def HAVE_GETHOSTBYADDR_R_(8|7|5)_ARGS */ -#endif /* ifndef HAVE_GETNAMEINFO */ +#endif /* ifndef HAVE_RFC2553 */ s_length = s_length_provided = sizeof(server); if (NULL != hostname) @@ -1106,7 +1109,7 @@ void get_host_information(jb_socket afd, char **ip_address, char **hostname) log_error(LOG_LEVEL_ERROR, "getsockname() truncated server address"); return; } -#ifdef HAVE_GETNAMEINFO +#ifdef HAVE_RFC2553 *ip_address = malloc(NI_MAXHOST); retval = getnameinfo((struct sockaddr *) &server, s_length, *ip_address, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); @@ -1119,7 +1122,7 @@ void get_host_information(jb_socket afd, char **ip_address, char **hostname) } #else *ip_address = strdup(inet_ntoa(server.sin_addr)); -#endif /* HAVE_GETNAMEINFO */ +#endif /* HAVE_RFC2553 */ if (NULL == hostname) { /* @@ -1129,7 +1132,7 @@ void get_host_information(jb_socket afd, char **ip_address, char **hostname) return; } -#ifdef HAVE_GETNAMEINFO +#ifdef HAVE_RFC2553 *hostname = malloc(NI_MAXHOST); retval = getnameinfo((struct sockaddr *) &server, s_length, *hostname, NI_MAXHOST, NULL, 0, NI_NAMEREQD); @@ -1177,7 +1180,7 @@ void get_host_information(jb_socket afd, char **ip_address, char **hostname) { *hostname = strdup(host->h_name); } -#endif /* else def HAVE_GETNAMEINFO */ +#endif /* else def HAVE_RFC2553 */ } return; @@ -1202,7 +1205,7 @@ void get_host_information(jb_socket afd, char **ip_address, char **hostname) *********************************************************************/ int accept_connection(struct client_state * csp, jb_socket fd) { -#ifdef HAVE_GETNAMEINFO +#ifdef HAVE_RFC2553 /* XXX: client is stored directly into csp->tcp_addr */ #define client (csp->tcp_addr) int retval; @@ -1237,7 +1240,7 @@ int accept_connection(struct client_state * csp, jb_socket fd) #endif csp->cfd = afd; -#ifdef HAVE_GETNAMEINFO +#ifdef HAVE_RFC2553 csp->ip_addr_str = malloc(NI_MAXHOST); retval = getnameinfo((struct sockaddr *) &client, c_length, csp->ip_addr_str, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); @@ -1251,7 +1254,7 @@ int accept_connection(struct client_state * csp, jb_socket fd) #else csp->ip_addr_str = strdup(inet_ntoa(client.sin_addr)); csp->ip_addr_long = ntohl(client.sin_addr.s_addr); -#endif /* def HAVE_GETNAMEINFO */ +#endif /* def HAVE_RFC2553 */ return 1; diff --git a/loadcfg.c b/loadcfg.c index 4c1eb7a4..d1fb7c1e 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.95 2009/04/17 11:34:34 fabiankeil Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.96 2009/04/17 11:38:28 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -35,6 +35,9 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.95 2009/04/17 11:34:34 fabiankeil * * Revisions : * $Log: loadcfg.c,v $ + * Revision 1.96 2009/04/17 11:38:28 fabiankeil + * Add and use parse_forwarder_address() to reduce code duplication. + * * Revision 1.95 2009/04/17 11:34:34 fabiankeil * Style cosmetics for the IPv6 code. * @@ -1049,12 +1052,12 @@ struct configuration_spec * load_config(void) break; } } -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 else { cur_acl->wildcard_dst = 1; } -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ /* * Add it to the list. Note we reverse the list to get the @@ -1481,12 +1484,12 @@ struct configuration_spec * load_config(void) break; } } -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 else { cur_acl->wildcard_dst = 1; } -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ /* * Add it to the list. Note we reverse the list to get the diff --git a/project.h b/project.h index 77f6a54e..d2422669 100644 --- a/project.h +++ b/project.h @@ -1,7 +1,7 @@ #ifndef PROJECT_H_INCLUDED #define PROJECT_H_INCLUDED /** Version string. */ -#define PROJECT_H_VERSION "$Id: project.h,v 1.130 2009/04/17 11:27:49 fabiankeil Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.131 2009/04/17 11:34:35 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -37,6 +37,9 @@ * * Revisions : * $Log: project.h,v $ + * Revision 1.131 2009/04/17 11:34:35 fabiankeil + * Style cosmetics for the IPv6 code. + * * Revision 1.130 2009/04/17 11:27:49 fabiankeil * Petr Pisar's privoxy-3.0.12-ipv6-3.diff. * @@ -713,7 +716,7 @@ /* Needed for pcre choice */ #include "config.h" -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 /* Need for struct sockaddr_storage */ #include #endif @@ -1427,7 +1430,7 @@ struct client_state /** Client PC's IP address, as reported by the accept() function. As a string. */ char *ip_addr_str; -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 /** Client PC's TCP address, as reported by the accept() function. As a sockaddr. */ struct sockaddr_storage tcp_addr; @@ -1435,7 +1438,7 @@ struct client_state /** Client PC's IP address, as reported by the accept() function. As a number. */ unsigned long ip_addr_long; -#endif /* def HAVE_GETADDRINFO */ +#endif /* def HAVE_RFC2553 */ /** The URL that was requested */ struct http_request http[1]; @@ -1669,14 +1672,14 @@ struct re_filterfile_spec */ struct access_control_addr { -#ifdef HAVE_GETADDRINFO +#ifdef HAVE_RFC2553 struct sockaddr_storage addr; /*