aboutsummaryrefslogtreecommitdiffstats
path: root/dfilter.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-10-11 03:03:12 +0000
committerGuy Harris <guy@alum.mit.edu>1999-10-11 03:03:12 +0000
commit29b9c8a2850ae3be73d1fce38a1e96591ba165fb (patch)
tree2f4a35a2ca11bf7a6c31bd3079ab48e12ed9b957 /dfilter.c
parent5779d0b754957b7b0b2921a0beef14eba7ac3250 (diff)
Have "get_host_ipaddr()" return a Boolean indicating whether it
succeeded or failed, and, if it succeeded, have it fill in the IP address if found through a pointer passed as the second argument. Have it first try interpreting its first argument as a dotted-quad IP address, with "inet_aton()", and, if that fails, have it try to interpret it as a host name with "gethostbyname()"; don't bother with "gethostbyaddr()", as we should be allowed to filter on IP addresses even if there's no host name associated with them (there's no guarantee that "gethostbyaddr()" will succeed if handed an IP address with no corresponding name - and it looks as if FreeBSD 3.2, at least, may not succeed in that case). Add a "dfilter_fail()" routine that takes "printf()"-like arguments and uses them to set an error message for the parse; doing so means that even if the filter expression is syntactically valid, we treat it as being invalid. (Is there a better way to force a parse to fail from arbitrary places in routines called by the parser?) Use that routine in the lexical analyzer. If that error message was set, use it as is as the failure message, rather than adding "Unable to parse filter string XXX" to it. Have the code to handle IP addresses and host names in display filters check whether "get_host_ipaddr()" succeeded or failed and, if it failed, arrange that the parse fail with an error message indicating the source of the problem. svn path=/trunk/; revision=802
Diffstat (limited to 'dfilter.c')
-rw-r--r--dfilter.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/dfilter.c b/dfilter.c
index 6fa05ccbe8..5d162ccce4 100644
--- a/dfilter.c
+++ b/dfilter.c
@@ -1,7 +1,7 @@
/* dfilter.c
* Routines for display filters
*
- * $Id: dfilter.c,v 1.24 1999/10/07 21:47:18 guy Exp $
+ * $Id: dfilter.c,v 1.25 1999/10/11 03:03:10 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -169,7 +169,7 @@ dfilter_compile(dfilter *df, gchar *dfilter_text)
/* Errors not found by the parser may not cause the parse to
* fail; if "dfilter_error_msg" is set, it means somebody
- * else called "dfilter_error()", e.g. the lexical analyzer,
+ * else called "dfilter_fail()", e.g. the lexical analyzer,
* so treat that as a parse error. */
if (dfilter_error_msg != NULL)
retval = 1;
@@ -179,14 +179,8 @@ dfilter_compile(dfilter *df, gchar *dfilter_text)
snprintf(dfilter_error_msg_buf, sizeof(dfilter_error_msg_buf),
"Unable to parse filter string \"%s\".",
dfilter_text);
- } else {
- /* An error message was supplied; use it in the
- * error we display. */
- snprintf(dfilter_error_msg_buf, sizeof(dfilter_error_msg_buf),
- "Unable to parse filter string \"%s\": %s.",
- dfilter_text, dfilter_error_msg);
+ dfilter_error_msg = &dfilter_error_msg_buf[0];
}
- dfilter_error_msg = &dfilter_error_msg_buf[0];
}
/* Clear the list of allocated nodes */
@@ -273,12 +267,6 @@ clear_byte_array(gpointer data, gpointer user_data)
void
dfilter_error(char *s)
{
- /* Remember the error message we were handed, unless it's
- * the boring "parse error" message used by YACC.
- */
- if (strcmp(s, "parse error") != 0)
- dfilter_error_msg = s;
-
/* The only data we have to worry about freeing is the
* data used by any GNodes that were allocated during
* parsing. The data in those Gnodes will be cleared
@@ -305,6 +293,23 @@ dfilter_error(char *s)
*/
}
+/* Called when an error other than a parsing error occurs. */
+void
+dfilter_fail(char *format, ...)
+{
+ va_list ap;
+
+ /* If we've already reported one error, don't overwrite it with this
+ * one. */
+ if (dfilter_error_msg != NULL)
+ return;
+
+ va_start(ap, format);
+ vsnprintf(dfilter_error_msg_buf, sizeof dfilter_error_msg_buf, format, ap);
+ dfilter_error_msg = dfilter_error_msg_buf;
+ va_end(ap);
+}
+
static void
unlink_gnode_children(gpointer gnode_ptr, gpointer user_data)
{