aboutsummaryrefslogtreecommitdiffstats
path: root/text2pcap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-05-21 03:17:14 +0000
committerGuy Harris <guy@alum.mit.edu>2001-05-21 03:17:14 +0000
commit1caea2c3612be3438670bf2214a8f3136c47bff2 (patch)
tree78070673438eab81362f2a6319d0b7292b94f256 /text2pcap.c
parenteee7f58e2d51f8e6befd325ebe51f062e33c51f3 (diff)
Build text2pcap on Windows.
Fix text2pcap.c so that it can be compiled with Microsoft Visual C++ 6.0: protect some includes with #ifdefs, as not all the header files in question exist in the MSVC++ build environment; include <winsock.h> if we have it, to declare "ntohs()" and the like; include "getopt.h" if we need it, to declare stuff for "getopt()"; include "config.h" if we have it, so we know whether the header files in question exist or are needed; rename "BYTE" to "READ_BYTE", as <winsock.h> defines BYTE as well, and that definition causes a conflict; get rid of references to "__FUNCTION__", as MSVC++ doesn't define it (I suspect at least some UNIX compilers don't define it, either). svn path=/trunk/; revision=3428
Diffstat (limited to 'text2pcap.c')
-rw-r--r--text2pcap.c65
1 files changed, 34 insertions, 31 deletions
diff --git a/text2pcap.c b/text2pcap.c
index 77e98da952..17508a172e 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -6,7 +6,7 @@
*
* (c) Copyright 2001 Ashok Narayanan <ashokn@cisco.com>
*
- * $Id: text2pcap.c,v 1.1 2001/05/16 21:32:04 ashokn Exp $
+ * $Id: text2pcap.c,v 1.2 2001/05/21 03:17:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -34,10 +34,10 @@
*
* This utility reads in an ASCII hexdump of this common format:
*
- * 00000000 00 E0 1E A7 05 6F 00 10 5A A0 B9 12 08 00 46 00 .....o..Z.....F.
- * 00000010 03 68 00 00 00 00 0A 2E EE 33 0F 19 08 7F 0F 19 .h.......3.....
- * 00000020 03 80 94 04 00 00 10 01 16 A2 0A 00 03 50 00 0C .............P..
- * 00000030 01 01 0F 19 03 80 11 01 1E 61 00 0C 03 01 0F 19 .........a......
+ * 00000000 00 E0 1E A7 05 6F 00 10 5A A0 B9 12 08 00 46 00 .....o..Z.....F.
+ * 00000010 03 68 00 00 00 00 0A 2E EE 33 0F 19 08 7F 0F 19 .h.......3.....
+ * 00000020 03 80 94 04 00 00 10 01 16 A2 0A 00 03 50 00 0C .............P..
+ * 00000030 01 01 0F 19 03 80 11 01 1E 61 00 0C 03 01 0F 19 .........a......
*
* Each bytestring line consists of an offset, one or more bytes, and
* text at the end. An offset is defined as a hex string of more than
@@ -79,15 +79,30 @@
* snaplength is automatically set to 64K.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
-#include <unistd.h>
-#include <netinet/in.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#ifdef HAVE_WINSOCK_H
+# include <winsock.h>
+#endif
#include <errno.h>
#include <assert.h>
+#ifdef NEED_GETOPT_H
+# include "getopt.h"
+#endif
+
#ifndef TRUE
#define TRUE 1
#endif
@@ -147,9 +162,9 @@ FILE *yyin;
typedef enum {
INIT, /* Waiting for start of new packet */
START_OF_LINE, /* Starting from beginning of line */
- OFFSET, /* Just read the offset */
- BYTE, /* Just read a byte */
- TEXT, /* Just read text - ignore until EOL */
+ READ_OFFSET, /* Just read the offset */
+ READ_BYTE, /* Just read a byte */
+ READ_TEXT, /* Just read text - ignore until EOL */
} parser_state_t;
parser_state_t state = INIT;
@@ -262,9 +277,6 @@ write_byte (char *str)
{
unsigned long num;
- if (debug>=2)
- fprintf(stderr, __FUNCTION__);
-
num = parse_num(str, FALSE);
packet_buf[curr_offset] = num;
curr_offset ++;
@@ -379,9 +391,6 @@ write_file_header (void)
{
struct pcap_hdr fh;
- if (debug>=2)
- fprintf(stderr, __FUNCTION__);
-
fh.magic = PCAP_MAGIC;
fh.version_major = 2;
fh.version_minor = 4;
@@ -399,9 +408,6 @@ write_file_header (void)
static void
start_new_packet (void)
{
- if (debug>=2)
- fprintf(stderr, __FUNCTION__);
-
if (debug>=1)
fprintf(stderr, "Start new packet\n");
@@ -417,9 +423,6 @@ start_new_packet (void)
static void
process_directive (char *str)
{
- if (debug>=2)
- fprintf(stderr, __FUNCTION__);
-
fprintf(stderr, "\n--- Directive [%s] currently unsupported ---\n", str+10);
}
@@ -460,7 +463,7 @@ parse_token (token_t token, char *str)
if (num==0) {
/* New packet starts here */
start_new_packet();
- state = OFFSET;
+ state = READ_OFFSET;
}
break;
default:
@@ -479,7 +482,7 @@ parse_token (token_t token, char *str)
if (num==0) {
/* New packet starts here */
start_new_packet();
- state = OFFSET;
+ state = READ_OFFSET;
} else if (num != curr_offset) {
/* Bad offset; switch to INIT state */
if (debug>=1)
@@ -488,7 +491,7 @@ parse_token (token_t token, char *str)
write_current_packet();
state = INIT;
} else
- state = OFFSET;
+ state = READ_OFFSET;
break;
default:
break;
@@ -496,17 +499,17 @@ parse_token (token_t token, char *str)
break;
/* ----- Processing packet, read offset -----------------------------------*/
- case OFFSET:
+ case READ_OFFSET:
switch(token) {
case T_BYTE:
/* Record the byte */
- state = BYTE;
+ state = READ_BYTE;
write_byte(str);
break;
case T_TEXT:
case T_DIRECTIVE:
case T_OFFSET:
- state = TEXT;
+ state = READ_TEXT;
break;
case T_EOL:
state = START_OF_LINE;
@@ -517,7 +520,7 @@ parse_token (token_t token, char *str)
break;
/* ----- Processing packet, read byte -------------------------------------*/
- case BYTE:
+ case READ_BYTE:
switch(token) {
case T_BYTE:
/* Record the byte */
@@ -526,7 +529,7 @@ parse_token (token_t token, char *str)
case T_TEXT:
case T_DIRECTIVE:
case T_OFFSET:
- state = TEXT;
+ state = READ_TEXT;
break;
case T_EOL:
state = START_OF_LINE;
@@ -537,7 +540,7 @@ parse_token (token_t token, char *str)
break;
/* ----- Processing packet, read text -------------------------------------*/
- case TEXT:
+ case READ_TEXT:
switch(token) {
case T_EOL:
state = START_OF_LINE;