bugfix: don't crash, if tag_save_literal == NULL
[obnox/wireshark/wip.git] / text2pcap.c
index b7cb2cef77c6ef853a5c4a84ea0d0a0458931255..9c5bedbb572e2448c1bac37c07aa4f11de05e75f 100644 (file)
@@ -6,7 +6,7 @@
  *
  * (c) Copyright 2001 Ashok Narayanan <ashokn@cisco.com>
  *
- * $Id: text2pcap.c,v 1.28 2004/01/05 19:31:44 ulfl Exp $
+ * $Id$
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -125,7 +125,7 @@ static unsigned long hdr_ethernet_proto = 0;
 
 /* Dummy IP header */
 static int hdr_ip = FALSE;
-static unsigned long hdr_ip_proto = 0;
+static long hdr_ip_proto = 0;
 
 /* Dummy UDP header */
 static int hdr_udp = FALSE;
@@ -176,10 +176,10 @@ static guint32 ts_usec = 0;
 static char *ts_fmt = NULL;
 
 /* Input file */
-static char *input_filename;
+static const char *input_filename;
 static FILE *input_file = NULL;
 /* Output file */
-static char *output_filename;
+static const char *output_filename;
 static FILE *output_file = NULL;
 
 /* Offset base to parse */
@@ -330,7 +330,7 @@ static unsigned long pcap_link_type = 1;   /* Default is DLT-EN10MB */
  * Pass in TRUE if this is an offset, FALSE if not
  */
 static unsigned long
-parse_num (char *str, int offset)
+parse_num (const char *str, int offset)
 {
     unsigned long num;
     char *c;
@@ -347,7 +347,7 @@ parse_num (char *str, int offset)
  * Write this byte into current packet
  */
 static void
-write_byte (char *str)
+write_byte (const char *str)
 {
     unsigned long num;
 
@@ -991,7 +991,7 @@ help (char *progname)
             "\n"
             "Usage: %s [-h] [-d] [-q] [-o h|o] [-l typenum] [-e l3pid] [-i proto] \n"
             "          [-m max-packet] [-u srcp,destp] [-T srcp,destp] [-s srcp,destp,tag]\n"
-            "          [-S srcp,destp,tag] [-t timefmt] <input-filename> <output-filename>\n"
+            "          [-S srcp,destp,ppi] [-t timefmt] <input-filename> <output-filename>\n"
             "\n"
             "where <input-filename> specifies input filename (use - for standard input)\n"
             "      <output-filename> specifies output filename (use - for standard output)\n"
@@ -1077,7 +1077,9 @@ parse_options (int argc, char *argv[])
 
         case 'i':
             hdr_ip = TRUE;
-            if (sscanf(optarg, "%ld", &hdr_ip_proto) < 1) {
+            hdr_ip_proto = strtol(optarg, &p, 10);
+            if (p == optarg || *p != '\0' || hdr_ip_proto < 0 ||
+                  hdr_ip_proto > 255) {
                 fprintf(stderr, "Bad argument for '-i': %s\n", optarg);
                 help(argv[0]);
             }