diff options
author | Jörg Mayer <jmayer@loplof.de> | 2004-06-25 07:00:54 +0000 |
---|---|---|
committer | Jörg Mayer <jmayer@loplof.de> | 2004-06-25 07:00:54 +0000 |
commit | 021f72021e8de04728950de107fa94c750dfbc9b (patch) | |
tree | 88f8b5408d401a86cd757681ee2afb5c41bebe89 | |
parent | e790073f3afed22dc5084a37424e35ab14412400 (diff) |
Fix automagically generated filters in case of remote login via IPv6.
This fix was picked from the source rpm of Suse 9.1.
svn path=/trunk/; revision=11234
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | epan/resolv.c | 17 | ||||
-rw-r--r-- | epan/resolv.h | 9 | ||||
-rw-r--r-- | util.c | 22 |
4 files changed, 37 insertions, 12 deletions
@@ -2209,6 +2209,7 @@ Ainsley Pereira <APereira [AT] Witness.com> Philippe Mazeau <philippe.mazeau [AT] swissvoice.net> Carles Kishimoto <ckishimo [AT] ac.upc.es> Dennis Lim <Dennis.Lim [AT] motorola.com> + <postadal [AT] suse.cz> Alain Magloire <alainm[AT]rcsm.ece.mcgill.ca> was kind enough to give his permission to use his version of snprintf.c. diff --git a/epan/resolv.c b/epan/resolv.c index cd5612c597..72f0cbbb20 100644 --- a/epan/resolv.c +++ b/epan/resolv.c @@ -1,7 +1,7 @@ /* resolv.c * Routines for network object lookup * - * $Id: resolv.c,v 1.43 2004/05/20 13:43:14 ulfl Exp $ + * $Id: resolv.c,v 1.44 2004/06/25 07:00:54 jmayer Exp $ * * Laurent Deniel <laurent.deniel@free.fr> * @@ -1898,3 +1898,18 @@ gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp) return FALSE; } + +/* + * Find out whether a hostname resolves to an ip or ipv6 address + * Return "ip6" if it is IPv6, "ip" otherwise (including the case + * that we don't know) + */ +const char* host_ip_af(const char *host) +{ +#ifdef HAVE_GETHOSTBYNAME2 + struct hostent *h; + return (h = gethostbyname2(host, AF_INET6)) && h->h_addrtype == AF_INET6 ? "ip6" : "ip"; +#else + return "ip"; +#endif +} diff --git a/epan/resolv.h b/epan/resolv.h index 1eef0da6fc..8d5c810111 100644 --- a/epan/resolv.h +++ b/epan/resolv.h @@ -1,7 +1,7 @@ /* resolv.h * Definitions for network object lookup * - * $Id: resolv.h,v 1.17 2004/05/09 10:03:40 guy Exp $ + * $Id: resolv.h,v 1.18 2004/06/25 07:00:54 jmayer Exp $ * * Laurent Deniel <laurent.deniel@free.fr> * @@ -131,4 +131,11 @@ gboolean get_host_ipaddr(const char *host, guint32 *addrp); */ gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp); +/* + * Find out whether a hostname resolves to an ip or ipv6 address + * Return "ip6" if it is IPv6, "ip" otherwise (including the case + * that we don't know) + */ +const char* host_ip_af(const char *host); + #endif /* __RESOLV_H__ */ @@ -1,7 +1,7 @@ /* util.c * Utility routines * - * $Id: util.c,v 1.80 2004/05/22 07:50:15 guy Exp $ + * $Id: util.c,v 1.81 2004/06/25 07:00:54 jmayer Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -56,6 +56,8 @@ typedef int mode_t; /* for win32 */ #endif /* __MINGW32__ */ #endif /* HAVE_IO_H */ +#include <epan/resolv.h> + /* * This has to come after the include of <pcap.h>, as the include of * <pcap.h> might cause <winsock2.h> to be included, and if we've @@ -419,21 +421,21 @@ gchar *get_conn_cfilter(void) { if ((env = getenv("SSH_CONNECTION")) != NULL) { tokens = g_strsplit(env, " ", 4); if (tokens[3]) { - g_string_sprintf(filter_str, "not (tcp port %s and ip host %s " - "and tcp port %s and ip host %s)", tokens[1], tokens[0], - tokens[3], tokens[2]); + g_string_sprintf(filter_str, "not (tcp port %s and %s host %s " + "and tcp port %s and %s host %s)", tokens[1], host_ip_af(tokens[0]), tokens[0], + tokens[3], host_ip_af(tokens[2]), tokens[2]); return filter_str->str; } } else if ((env = getenv("SSH_CLIENT")) != NULL) { tokens = g_strsplit(env, " ", 3); - g_string_sprintf(filter_str, "not (tcp port %s and ip host %s " - "and tcp port %s)", tokens[1], tokens[0], tokens[2]); + g_string_sprintf(filter_str, "not (tcp port %s and %s host %s " + "and tcp port %s)", tokens[1], host_ip_af(tokens[0]), tokens[0], tokens[2]); return filter_str->str; } else if ((env = getenv("REMOTEHOST")) != NULL) { if (strcasecmp(env, "localhost") == 0 || strcmp(env, "127.0.0.1") == 0) { return ""; } - g_string_sprintf(filter_str, "not ip host %s", env); + g_string_sprintf(filter_str, "not %s host %s", host_ip_af(env), env); return filter_str->str; } else if ((env = getenv("DISPLAY")) != NULL) { tokens = g_strsplit(env, ":", 2); @@ -442,13 +444,13 @@ gchar *get_conn_cfilter(void) { strcmp(tokens[0], "127.0.0.1") == 0) { return ""; } - g_string_sprintf(filter_str, "not ip host %s", - tokens[0]); + g_string_sprintf(filter_str, "not %s host %s", + host_ip_af(tokens[0]), tokens[0]); return filter_str->str; } } else if ((env = getenv("CLIENTNAME")) != NULL) { if (g_strcasecmp("console", env) != 0) { - g_string_sprintf(filter_str, "not ip host %s", env); + g_string_sprintf(filter_str, "not %s host %s", host_ip_af(env), env); return filter_str->str; } } |