/* packet-smtp.c
* Routines for SMTP packet disassembly
*
- * $Id: packet-smtp.c,v 1.29 2002/07/15 09:40:20 guy Exp $
+ * $Id: packet-smtp.c,v 1.31 2002/08/02 23:36:02 jmayer Exp $
*
* Copyright (c) 2000 by Richard Sharpe <rsharpe@ns.aus.com>
*
#include "config.h"
#endif
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
static int global_smtp_tcp_port = TCP_PORT_SMTP;
+/* desegmentation of SMTP command and response lines */
+static gboolean smtp_desegment = TRUE;
+
/*
* A CMD is an SMTP command, MESSAGE is the message portion, and EOM is the
* last part of a message
int request = 0;
conversation_t *conversation;
struct smtp_request_val *request_val;
- const u_char *line;
+ const guchar *line;
guint32 code;
int linelen;
gboolean eom_seen = FALSE;
/*
* Get the first line from the buffer.
*
- * Note that "tvb_find_line_end()" will return a value that
- * is not longer than what's in the buffer, so the
- * "tvb_get_ptr()" call won't throw an exception.
+ * Note that "tvb_find_line_end()" will, if it doesn't return
+ * -1, return a value that is not longer than what's in the buffer,
+ * and "tvb_find_line_end()" will always return a value that is not
+ * longer than what's in the buffer, so the "tvb_get_ptr()" call
+ * won't throw an exception.
*/
- linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
+ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
+ smtp_desegment && pinfo->can_desegment);
+ if (linelen == -1) {
+ /*
+ * We didn't find a line ending, and we're doing desegmentation;
+ * tell the TCP dissector where the data for this message starts
+ * in the data it handed us, and tell it we need one more byte
+ * (we may need more, but we'll try again if what we get next
+ * isn't enough), and return.
+ */
+ pinfo->desegment_offset = offset;
+ pinfo->desegment_len = 1;
+ return;
+ }
line = tvb_get_ptr(tvb, offset, linelen);
frame_data = p_get_proto_data(pinfo->fd, proto_smtp);
/*
* Find the end of the line.
*/
- tvb_find_line_end(tvb, offset, -1, &next_offset);
+ tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
/*
* Put this line.
/*
* Find the end of the line.
*/
- linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
+ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
/*
* Is it a continuation line?
static gint *ett[] = {
&ett_smtp
};
- /*module_t *smtp_module = NULL; */ /* Not yet used */
+ module_t *smtp_module;
/* No Configuration options to register? */
proto_register_subtree_array(ett, array_length(ett));
register_init_routine(&smtp_init_protocol);
+ smtp_module = prefs_register_protocol(proto_smtp, NULL);
+ prefs_register_bool_preference(smtp_module, "desegment_lines",
+ "Desegment all SMTP command and response lines spanning multiple TCP segments",
+ "Whether the SMTP dissector should desegment all command and response lines spanning multiple TCP segments",
+ &smtp_desegment);
}
/* The registration hand-off routine */