aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-08-01 03:22:15 +0000
committerGuy Harris <guy@alum.mit.edu>2001-08-01 03:22:15 +0000
commit97a90e0f6ca5b8a8737905a43881c18833032125 (patch)
tree9384ed58ca3308893fcc86488ea9ec2317783a45
parent26a68c20fc7d95691a6ecc330d4866e908acebec (diff)
"getopt()" doesn't support multiple option arguments to a flag; have
"-u" take a single argument with two port numbers separated by a comma. svn path=/trunk/; revision=3802
-rw-r--r--doc/text2pcap.pod18
-rw-r--r--text2pcap.c15
2 files changed, 21 insertions, 12 deletions
diff --git a/doc/text2pcap.pod b/doc/text2pcap.pod
index 280da4880a..372af834a2 100644
--- a/doc/text2pcap.pod
+++ b/doc/text2pcap.pod
@@ -6,13 +6,13 @@ text2pcap - Generate a capture file from an ASCII hexdump of packets
=head1 SYNOPSYS
B<text2pcap>
-S<[ B<-d> ]>
-S<[ B<-q> ]>
-S<[ B<-o> hex|oct ]>
-S<[ B<-l> typenum ]>
-S<[ B<-e> l3pid ]>
-S<[ B<-i> proto]>
-S<[ B<-u> srcport destport]>
+S<[ B<-d> ]>
+S<[ B<-q> ]>
+S<[ B<-o> hex|oct ]>
+S<[ B<-l> typenum ]>
+S<[ B<-e> l3pid ]>
+S<[ B<-i> proto ]>
+S<[ B<-u> srcport,destport ]>
I<infile>
I<outfile>
@@ -123,14 +123,14 @@ an IP header. Note that this automatically includes an appropriate
Ethernet header as well. Example: I<-i 46> to specify an RSVP packet
(IP protocol 46).
-=item -u srcport destport
+=item -u srcport,destport
Include dummy UDP headers before each packet. Specify the source and
destination UDP ports for the packet in decimal. Use this option if
your dump is the UDP payload of a packet but does not include any UDP,
IP or Ethernet headers. Note that this automatically includes
appropriate Ethernet and IP headers with each packet. Example: I<-u
-1000 69> to make the packets look like TFTP/UDP packets.
+1000,69> to make the packets look like TFTP/UDP packets.
=head1 SEE ALSO
diff --git a/text2pcap.c b/text2pcap.c
index dd089a39b3..d760828210 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -6,7 +6,7 @@
*
* (c) Copyright 2001 Ashok Narayanan <ashokn@cisco.com>
*
- * $Id: text2pcap.c,v 1.3 2001/07/13 00:55:52 guy Exp $
+ * $Id: text2pcap.c,v 1.4 2001/08/01 03:22:14 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -603,6 +603,7 @@ static void
parse_options (int argc, char *argv[])
{
int c;
+ char *p;
/* Scan CLI parameters */
while ((c = getopt(argc, argv, "dqr:w:e:i:l:o:u:")) != -1) {
@@ -642,11 +643,19 @@ parse_options (int argc, char *argv[])
case 'u':
hdr_udp = TRUE;
- if (!optarg || sscanf(optarg, "%ld", &hdr_udp_src) < 1) {
+ hdr_udp_src = strtol(optarg, &p, 10);
+ if (p == optarg || (*p != ',' && *p != '\0')) {
fprintf(stderr, "Bad src port for '-u'\n");
help(argv[0]);
}
- if (optind >= argc || sscanf(argv[optind], "%ld", &hdr_udp_dest) < 1) {
+ if (*p == '\0') {
+ fprintf(stderr, "No dest port specified for '-u'\n");
+ help(argv[0]);
+ }
+ p++;
+ optarg = p;
+ hdr_udp_dest = strtol(optarg, &p, 10);
+ if (p == optarg || *p != '\0') {
fprintf(stderr, "Bad dest port for '-u'\n");
help(argv[0]);
}