summaryrefslogtreecommitdiff
path: root/text2pcap.c
diff options
context:
space:
mode:
authorMichael Tüxen <tuexen@fh-muenster.de>2012-12-25 22:37:40 +0000
committerMichael Tüxen <tuexen@fh-muenster.de>2012-12-25 22:37:40 +0000
commit22df071cef956db166c1dce5f01ee93cf4cc95e3 (patch)
tree67137f4ea5c555177d902af0f066aa589b8dad4a /text2pcap.c
parentc8f3c1d9a3c0ba9fabb44d14ea8a55a234449e0b (diff)
downloadwireshark-22df071cef956db166c1dce5f01ee93cf4cc95e3.tar.gz
Add support for -D option. The preamble will start with
an I or O indicating the direction of the packet. This will be stored in the generated file if the pcap-ng format is used. Thanks to Jaap for suggesting to integrate this into the preamble! svn path=/trunk/; revision=46744
Diffstat (limited to 'text2pcap.c')
-rw-r--r--text2pcap.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/text2pcap.c b/text2pcap.c
index ba85995581..e01c7ed6c0 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -185,6 +185,9 @@ static unsigned long hdr_data_chunk_ppid = 0;
/* ASCII text dump identification */
static int identify_ascii = FALSE;
+static gboolean has_direction = FALSE;
+static guint32 direction = 0;
+
/*--- Local date -----------------------------------------------------------------*/
/* This is where we store the packet currently being built */
@@ -745,7 +748,7 @@ write_current_packet(gboolean cont)
length, length,
0,
1000000,
- packet_buf, 0,
+ packet_buf, direction,
&bytes_written, &err);
} else {
success = libpcap_write_packet(output_file,
@@ -907,12 +910,38 @@ parse_preamble (void)
* If no "-t" flag was specified, don't attempt to parse a packet
* preamble to extract a time stamp.
*/
- if (ts_fmt == NULL) {
+ if ((ts_fmt == NULL) && !has_direction) {
/* Clear Preamble */
packet_preamble_len = 0;
return;
}
+ if (has_direction) {
+ switch (packet_preamble[0]) {
+ case 'i':
+ case 'I':
+ direction = 0x00000001;
+ packet_preamble[0] = ' ';
+ break;
+ case 'o':
+ case 'O':
+ direction = 0x00000002;
+ packet_preamble[0] = ' ';
+ break;
+ default:
+ direction = 0x00000000;
+ break;
+ }
+ i = 0;
+ while (packet_preamble[i] == ' ' ||
+ packet_preamble[i] == '\r' ||
+ packet_preamble[i] == '\t') {
+ i++;
+ }
+ packet_preamble_len -= i;
+ memmove(packet_preamble, packet_preamble+i, packet_preamble_len);
+ }
+
/*
* Initialize to today localtime, just in case not all fields
* of the date and time are specified.
@@ -1272,6 +1301,9 @@ usage (void)
" number is assumed to be fractions of a second.\n"
" NOTE: Date/time fields from the current date/time are\n"
" used as the default for unspecified fields.\n"
+ " -D the text before the packet starts either with an I or O\n"
+ " indicating that the packet is inbound or outbound.\n"
+ " This is only stored if the output format is PCAP-NG.\n"
" -a enable ASCII text dump identification.\n"
" It allows to identify the start of the ASCII text\n"
" dump and not include it in the packet even if it\n"
@@ -1340,11 +1372,12 @@ parse_options (int argc, char *argv[])
#endif /* _WIN32 */
/* Scan CLI parameters */
- while ((c = getopt(argc, argv, "dhqe:i:l:m:no:u:s:S:t:T:a")) != -1) {
+ while ((c = getopt(argc, argv, "Ddhqe:i:l:m:no:u:s:S:t:T:a")) != -1) {
switch(c) {
case '?': usage(); break;
case 'h': usage(); break;
case 'd': if (!quiet) debug++; break;
+ case 'D': has_direction = TRUE; break;
case 'q': quiet = TRUE; debug = FALSE; break;
case 'l': pcap_link_type = strtol(optarg, NULL, 0); break;
case 'm': max_offset = strtol(optarg, NULL, 0); break;