Ethereal-users: Re: [Ethereal-users] Questions on Text2Pcap

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

Date Prev Thread Prev
From: Guy Harris <gharris@xxxxxxxxx>
Date: Tue, 31 Jul 2001 20:19:57 -0700
On Tue, Jul 31, 2001 at 12:23:02PM -0700, Guy Harris wrote:
> "text2pcap" should be fixed to, instead, take a single argument with a
> comma-separated pair of port numbers, so you'd do
> 
> 	text2pcap -u 161,162 file.txt

I've attached a patch to text2pcap.c that changes it to work that way;
it also includes a patch to the man page.  If you have source, you can
apply the patch and rebuild; I tried the resulting text2pcap on the text
you put in the message, and the resulting capture file contained an SNMP
trap message.
Index: text2pcap.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/text2pcap.c,v
retrieving revision 1.3
diff -c -r1.3 text2pcap.c
*** text2pcap.c	2001/07/13 00:55:52	1.3
--- text2pcap.c	2001/08/01 03:17:50
***************
*** 603,608 ****
--- 603,609 ----
  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,652 ****
              
          case 'u':
              hdr_udp = TRUE;
!             if (!optarg || sscanf(optarg, "%ld", &hdr_udp_src) < 1) {
                  fprintf(stderr, "Bad src port for '-u'\n");
                  help(argv[0]);
              }
!             if (optind >= argc || sscanf(argv[optind], "%ld", &hdr_udp_dest) < 1) {
                  fprintf(stderr, "Bad dest port for '-u'\n");
                  help(argv[0]);
              }
--- 643,661 ----
              
          case 'u':
              hdr_udp = TRUE;
!             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 (*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]);
              }
Index: doc/text2pcap.pod
===================================================================
RCS file: /usr/local/cvsroot/ethereal/doc/text2pcap.pod,v
retrieving revision 1.3
diff -c -r1.3 doc/text2pcap.pod
*** doc/text2pcap.pod	2001/07/05 21:27:11	1.3
--- doc/text2pcap.pod	2001/08/01 03:17:50
***************
*** 6,18 ****
  =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]> 
  I<infile>
  I<outfile>
  
--- 6,18 ----
  =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 ]>
  I<infile>
  I<outfile>
  
***************
*** 123,136 ****
  Ethernet header as well. Example: I<-i 46> to specify an RSVP packet
  (IP protocol 46).
  
! =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.
  
  
  =head1 SEE ALSO
--- 123,136 ----
  Ethernet header as well. Example: I<-i 46> to specify an RSVP packet
  (IP protocol 46).
  
! =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.
  
  
  =head1 SEE ALSO