1999-09-10 05:15:17 +00:00
|
|
|
/*
|
|
|
|
* randpkt.c
|
|
|
|
* ---------
|
|
|
|
* Creates random packet traces. Useful for debugging sniffers by testing
|
|
|
|
* assumptions about the veracity of the data found in the packet.
|
|
|
|
*
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (C) 1999 by Gilbert Ramirez <gram@alumni.rice.edu>
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-10 05:15:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-10 05:15:17 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-10 05:15:17 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
1999-09-10 05:15:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2011-08-09 21:02:10 +00:00
|
|
|
#ifndef HAVE_GETOPT
|
|
|
|
#include "wsutil/wsgetopt.h"
|
|
|
|
#endif
|
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
1999-09-17 04:38:23 +00:00
|
|
|
#include "wiretap/wtap.h"
|
2011-06-23 13:51:26 +00:00
|
|
|
#include "wsutil/file_util.h"
|
1999-09-10 05:15:17 +00:00
|
|
|
|
2011-01-06 23:28:58 +00:00
|
|
|
#ifdef _WIN32
|
2011-05-24 00:07:56 +00:00
|
|
|
#include <wsutil/unicode-utils.h>
|
2011-01-06 23:28:58 +00:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
#define array_length(x) (sizeof x / sizeof x[0])
|
|
|
|
|
|
|
|
/* Types of produceable packets */
|
|
|
|
enum {
|
|
|
|
PKT_ARP,
|
2007-05-25 23:40:42 +00:00
|
|
|
PKT_BGP,
|
|
|
|
PKT_BVLC,
|
1999-10-06 20:29:26 +00:00
|
|
|
PKT_DNS,
|
1999-09-10 05:15:17 +00:00
|
|
|
PKT_ETHERNET,
|
|
|
|
PKT_FDDI,
|
2007-05-25 23:40:42 +00:00
|
|
|
PKT_GIOP,
|
1999-10-06 20:29:26 +00:00
|
|
|
PKT_ICMP,
|
1999-09-10 15:38:58 +00:00
|
|
|
PKT_IP,
|
1999-09-10 05:15:17 +00:00
|
|
|
PKT_LLC,
|
2007-05-25 23:40:42 +00:00
|
|
|
PKT_M2M,
|
|
|
|
PKT_MEGACO,
|
1999-10-07 07:55:12 +00:00
|
|
|
PKT_NBNS,
|
2007-05-25 23:40:42 +00:00
|
|
|
PKT_NCP2222,
|
|
|
|
PKT_SCTP,
|
2000-06-11 15:54:03 +00:00
|
|
|
PKT_SYSLOG,
|
1999-09-10 15:38:58 +00:00
|
|
|
PKT_TCP,
|
2005-03-27 04:43:49 +00:00
|
|
|
PKT_TDS,
|
2007-05-25 23:40:42 +00:00
|
|
|
PKT_TR,
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_UDP,
|
|
|
|
PKT_USB,
|
|
|
|
PKT_USB_LINUX
|
1999-09-10 05:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
2005-07-23 11:41:25 +00:00
|
|
|
const char *abbrev;
|
|
|
|
const char *longname;
|
|
|
|
int produceable_type;
|
|
|
|
int sample_wtap_encap;
|
2009-05-17 21:41:23 +00:00
|
|
|
guint8 *sample_buffer;
|
2005-07-23 11:41:25 +00:00
|
|
|
int sample_length;
|
2009-05-17 21:41:23 +00:00
|
|
|
guint8 *pseudo_buffer;
|
|
|
|
int pseudo_length;
|
1999-09-10 05:15:17 +00:00
|
|
|
} pkt_example;
|
|
|
|
|
|
|
|
/* Ethernet, indicating ARP */
|
|
|
|
guint8 pkt_arp[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x00, 0x00,
|
|
|
|
0x32, 0x25, 0x0f, 0xff,
|
|
|
|
0x08, 0x06
|
|
|
|
};
|
|
|
|
|
2000-06-11 15:54:03 +00:00
|
|
|
/* Ethernet+IP+UDP, indicating DNS */
|
1999-10-06 20:29:26 +00:00
|
|
|
guint8 pkt_dns[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x3c,
|
|
|
|
0xc5, 0x9e, 0x40, 0x00,
|
|
|
|
0xff, 0x11, 0xd7, 0xe0,
|
|
|
|
0xd0, 0x15, 0x02, 0xb8,
|
|
|
|
0x0a, 0x01, 0x01, 0x63,
|
|
|
|
|
|
|
|
0x05, 0xe8, 0x00, 0x35,
|
2005-03-16 16:44:06 +00:00
|
|
|
0xff, 0xff, 0x2a, 0xb9,
|
1999-10-06 20:29:26 +00:00
|
|
|
0x30
|
|
|
|
};
|
|
|
|
|
1999-10-07 07:55:12 +00:00
|
|
|
/* Ethernet+IP, indicating ICMP */
|
1999-10-06 20:29:26 +00:00
|
|
|
guint8 pkt_icmp[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x54,
|
|
|
|
0x8f, 0xb3, 0x40, 0x00,
|
|
|
|
0xfd, 0x01, 0x8a, 0x99,
|
|
|
|
0xcc, 0xfc, 0x66, 0x0b,
|
|
|
|
0xce, 0x41, 0x62, 0x12
|
|
|
|
};
|
|
|
|
|
1999-09-10 15:38:58 +00:00
|
|
|
/* Ethernet, indicating IP */
|
|
|
|
guint8 pkt_ip[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00
|
|
|
|
};
|
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
/* TR, indicating LLC */
|
|
|
|
guint8 pkt_llc[] = {
|
|
|
|
0x10, 0x40, 0x68, 0x00,
|
|
|
|
0x19, 0x69, 0x95, 0x8b,
|
|
|
|
0x00, 0x01, 0xfa, 0x68,
|
|
|
|
0xc4, 0x67
|
|
|
|
};
|
|
|
|
|
2007-05-25 23:40:42 +00:00
|
|
|
/* Ethernet, indicating WiMAX M2M */
|
|
|
|
guint8 pkt_m2m[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x00, 0x00,
|
|
|
|
0x32, 0x25, 0x0f, 0xff,
|
|
|
|
0x08, 0xf0
|
|
|
|
};
|
|
|
|
|
2002-05-18 14:58:00 +00:00
|
|
|
/* Ethernet+IP+UDP, indicating NBNS */
|
1999-10-07 07:55:12 +00:00
|
|
|
guint8 pkt_nbns[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x3c,
|
|
|
|
0xc5, 0x9e, 0x40, 0x00,
|
|
|
|
0xff, 0x11, 0xd7, 0xe0,
|
|
|
|
0xd0, 0x15, 0x02, 0xb8,
|
|
|
|
0x0a, 0x01, 0x01, 0x63,
|
|
|
|
|
|
|
|
0x00, 0x89, 0x00, 0x89,
|
|
|
|
0x00, 0x00, 0x2a, 0xb9,
|
|
|
|
0x30
|
|
|
|
};
|
|
|
|
|
2000-06-11 15:54:03 +00:00
|
|
|
/* Ethernet+IP+UDP, indicating syslog */
|
|
|
|
guint8 pkt_syslog[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x64,
|
|
|
|
0x20, 0x48, 0x00, 0x00,
|
|
|
|
0xfc, 0x11, 0xf8, 0x03,
|
|
|
|
0xd0, 0x15, 0x02, 0xb8,
|
|
|
|
0x0a, 0x01, 0x01, 0x63,
|
|
|
|
|
|
|
|
0x05, 0xe8, 0x02, 0x02,
|
|
|
|
0x00, 0x50, 0x51, 0xe1,
|
|
|
|
0x3c
|
|
|
|
};
|
|
|
|
|
1999-09-10 15:38:58 +00:00
|
|
|
/* TR+LLC+IP, indicating TCP */
|
|
|
|
guint8 pkt_tcp[] = {
|
|
|
|
0x10, 0x40, 0x68, 0x00,
|
|
|
|
0x19, 0x69, 0x95, 0x8b,
|
|
|
|
0x00, 0x01, 0xfa, 0x68,
|
|
|
|
0xc4, 0x67,
|
|
|
|
|
|
|
|
0xaa, 0xaa, 0x03, 0x00,
|
|
|
|
0x00, 0x00, 0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x28,
|
|
|
|
0x0b, 0x0b, 0x40, 0x00,
|
|
|
|
0x20, 0x06, 0x85, 0x37,
|
|
|
|
0xc0, 0xa8, 0x27, 0x01,
|
|
|
|
0xc0, 0xa8, 0x22, 0x3c
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Ethernet+IP, indicating UDP */
|
|
|
|
guint8 pkt_udp[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x3c,
|
|
|
|
0xc5, 0x9e, 0x40, 0x00,
|
|
|
|
0xff, 0x11, 0xd7, 0xe0,
|
|
|
|
0xd0, 0x15, 0x02, 0xb8,
|
|
|
|
0x0a, 0x01, 0x01, 0x63
|
|
|
|
};
|
|
|
|
|
2001-03-31 10:13:13 +00:00
|
|
|
/* Ethernet+IP+UDP, indicating BVLC */
|
|
|
|
guint8 pkt_bvlc[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x3c,
|
|
|
|
0xc5, 0x9e, 0x40, 0x00,
|
|
|
|
0xff, 0x11, 0x01, 0xaa,
|
|
|
|
0xc1, 0xff, 0x19, 0x1e,
|
|
|
|
0xc1, 0xff, 0x19, 0xff,
|
|
|
|
0xba, 0xc0, 0xba, 0xc0,
|
|
|
|
0x00, 0xff, 0x2d, 0x5e,
|
|
|
|
0x81
|
|
|
|
};
|
|
|
|
|
2002-02-14 17:45:07 +00:00
|
|
|
/* TR+LLC+IPX, indicating NCP, with NCP Type == 0x2222 */
|
|
|
|
guint8 pkt_ncp2222[] = {
|
|
|
|
0x10, 0x40, 0x00, 0x00,
|
|
|
|
0xf6, 0x7c, 0x9b, 0x70,
|
|
|
|
0x68, 0x00, 0x19, 0x69,
|
|
|
|
0x95, 0x8b, 0xe0, 0xe0,
|
|
|
|
0x03, 0xff, 0xff, 0x00,
|
|
|
|
0x25, 0x02, 0x11, 0x00,
|
|
|
|
0x00, 0x74, 0x14, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x01, 0x04, 0x51, 0x00,
|
|
|
|
0x00, 0x00, 0x04, 0x00,
|
|
|
|
0x02, 0x16, 0x19, 0x7a,
|
|
|
|
0x84, 0x40, 0x01, 0x22,
|
|
|
|
0x22
|
|
|
|
};
|
|
|
|
|
2002-05-18 14:58:00 +00:00
|
|
|
/* Ethernet+IP+TCP, indicating GIOP */
|
|
|
|
guint8 pkt_giop[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0xa6,
|
|
|
|
0x00, 0x2f, 0x40, 0x00,
|
|
|
|
0x40, 0x06, 0x3c, 0x21,
|
|
|
|
0x7f, 0x00, 0x00, 0x01,
|
|
|
|
0x7f, 0x00, 0x00, 0x01,
|
|
|
|
|
|
|
|
0x30, 0x39, 0x04, 0x05,
|
|
|
|
0xac, 0x02, 0x1e, 0x69,
|
|
|
|
0xab, 0x74, 0xab, 0x64,
|
|
|
|
0x80, 0x18, 0x79, 0x60,
|
|
|
|
0xc4, 0xb8, 0x00, 0x00,
|
|
|
|
0x01, 0x01, 0x08, 0x0a,
|
|
|
|
0x00, 0x00, 0x48, 0xf5,
|
|
|
|
0x00, 0x00, 0x48, 0xf5,
|
|
|
|
|
|
|
|
0x47, 0x49, 0x4f, 0x50,
|
|
|
|
0x01, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x30,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x01,
|
|
|
|
0x01
|
|
|
|
};
|
|
|
|
|
2002-10-15 02:29:54 +00:00
|
|
|
/* Ethernet+IP+TCP, indicating BGP */
|
|
|
|
guint8 pkt_bgp[] = {
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0xa6,
|
|
|
|
0x00, 0x2f, 0x40, 0x00,
|
|
|
|
0x40, 0x06, 0x3c, 0x21,
|
|
|
|
0x7f, 0x00, 0x00, 0x01,
|
|
|
|
0x7f, 0x00, 0x00, 0x01,
|
|
|
|
|
|
|
|
0x30, 0x39, 0x00, 0xb3,
|
|
|
|
0xac, 0x02, 0x1e, 0x69,
|
|
|
|
0xab, 0x74, 0xab, 0x64,
|
|
|
|
0x80, 0x18, 0x79, 0x60,
|
|
|
|
0xc4, 0xb8, 0x00, 0x00,
|
|
|
|
0x01, 0x01, 0x08, 0x0a,
|
|
|
|
0x00, 0x00, 0x48, 0xf5,
|
|
|
|
0x00, 0x00, 0x48, 0xf5,
|
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
2002-11-17 21:47:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Ethernet+IP+TCP, indicating TDS NetLib */
|
|
|
|
guint8 pkt_tds[] = {
|
|
|
|
0x00, 0x50, 0x8b, 0x0d,
|
|
|
|
0x7a, 0xed, 0x00, 0x08,
|
|
|
|
0xa3, 0x98, 0x39, 0x81,
|
|
|
|
0x08, 0x00,
|
2002-10-15 02:29:54 +00:00
|
|
|
|
2002-11-17 21:47:41 +00:00
|
|
|
0x45, 0x00, 0x03, 0x8d,
|
|
|
|
0x90, 0xd4, 0x40, 0x00,
|
|
|
|
0x7c, 0x06, 0xc3, 0x1b,
|
|
|
|
0xac, 0x14, 0x02, 0x22,
|
|
|
|
0x0a, 0xc2, 0xee, 0x82,
|
|
|
|
|
|
|
|
0x05, 0x99, 0x08, 0xf8,
|
|
|
|
0xff, 0x4e, 0x85, 0x46,
|
|
|
|
0xa2, 0xb4, 0x42, 0xaa,
|
|
|
|
0x50, 0x18, 0x3c, 0x28,
|
|
|
|
0x0f, 0xda, 0x00, 0x00,
|
2002-10-15 02:29:54 +00:00
|
|
|
};
|
|
|
|
|
2005-03-27 04:43:49 +00:00
|
|
|
/* Ethernet+IP, indicating SCTP */
|
|
|
|
guint8 pkt_sctp[] = {
|
|
|
|
0x00, 0xa0, 0x80, 0x00,
|
|
|
|
0x5e, 0x46, 0x08, 0x00,
|
|
|
|
0x03, 0x4a, 0x00, 0x35,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x7c,
|
|
|
|
0x14, 0x1c, 0x00, 0x00,
|
|
|
|
0x3b, 0x84, 0x4a, 0x54,
|
|
|
|
0x0a, 0x1c, 0x06, 0x2b,
|
|
|
|
0x0a, 0x1c, 0x06, 0x2c,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Ethernet+IP+SCTP, indicating MEGACO */
|
|
|
|
guint8 pkt_megaco[] = {
|
|
|
|
0x00, 0xa0, 0x80, 0x00,
|
|
|
|
0x5e, 0x46, 0x08, 0x00,
|
|
|
|
0x03, 0x4a, 0x00, 0x35,
|
|
|
|
0x08, 0x00,
|
|
|
|
|
|
|
|
0x45, 0x00, 0x00, 0x7c,
|
|
|
|
0x14, 0x1c, 0x00, 0x00,
|
|
|
|
0x3b, 0x84, 0x4a, 0x54,
|
|
|
|
0x0a, 0x1c, 0x06, 0x2b,
|
|
|
|
0x0a, 0x1c, 0x06, 0x2c,
|
|
|
|
|
|
|
|
0x40, 0x00, 0x0b, 0x80,
|
|
|
|
0x00, 0x01, 0x6f, 0x0a,
|
|
|
|
0x6d, 0xb0, 0x18, 0x82,
|
|
|
|
0x00, 0x03, 0x00, 0x5b,
|
|
|
|
0x28, 0x02, 0x43, 0x45,
|
|
|
|
0x00, 0x00, 0xa0, 0xbd,
|
|
|
|
0x00, 0x00, 0x00, 0x07,
|
|
|
|
};
|
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
/* This little data table drives the whole program */
|
|
|
|
pkt_example examples[] = {
|
|
|
|
{ "arp", "Address Resolution Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_ARP, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_arp, array_length(pkt_arp),
|
|
|
|
NULL, 0 },
|
1999-09-10 05:15:17 +00:00
|
|
|
|
2005-03-27 04:43:49 +00:00
|
|
|
{ "bgp", "Border Gateway Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_BGP, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_bgp, array_length(pkt_bgp),
|
|
|
|
NULL, 0 },
|
2005-03-27 04:43:49 +00:00
|
|
|
|
|
|
|
{ "bvlc", "BACnet Virtual Link Control",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_BVLC, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_bvlc, array_length(pkt_bvlc),
|
|
|
|
NULL, 0 },
|
2005-03-27 04:43:49 +00:00
|
|
|
|
1999-10-06 20:29:26 +00:00
|
|
|
{ "dns", "Domain Name Service",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_DNS, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_dns, array_length(pkt_dns),
|
|
|
|
NULL, 0 },
|
1999-10-06 20:29:26 +00:00
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
{ "eth", "Ethernet",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_ETHERNET, WTAP_ENCAP_ETHERNET,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, 0 },
|
1999-09-10 05:15:17 +00:00
|
|
|
|
|
|
|
{ "fddi", "Fiber Distributed Data Interface",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_FDDI, WTAP_ENCAP_FDDI,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, 0 },
|
1999-09-10 05:15:17 +00:00
|
|
|
|
2005-03-27 04:43:49 +00:00
|
|
|
{ "giop", "General Inter-ORB Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_GIOP, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_giop, array_length(pkt_giop),
|
|
|
|
NULL, 0 },
|
2005-03-27 04:43:49 +00:00
|
|
|
|
1999-10-06 20:29:26 +00:00
|
|
|
{ "icmp", "Internet Control Message Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_ICMP, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_icmp, array_length(pkt_icmp),
|
|
|
|
NULL, 0 },
|
1999-10-06 20:29:26 +00:00
|
|
|
|
1999-09-10 15:38:58 +00:00
|
|
|
{ "ip", "Internet Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_IP, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_ip, array_length(pkt_ip),
|
|
|
|
NULL, 0 },
|
1999-09-10 15:38:58 +00:00
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
{ "llc", "Logical Link Control",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_LLC, WTAP_ENCAP_TOKEN_RING,
|
|
|
|
pkt_llc, array_length(pkt_llc),
|
|
|
|
NULL, 0 },
|
1999-09-10 05:15:17 +00:00
|
|
|
|
2007-05-25 23:40:42 +00:00
|
|
|
{ "m2m", "WiMAX M2M Encapsulation Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_M2M, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_m2m, array_length(pkt_m2m),
|
|
|
|
NULL, 0 },
|
2007-05-25 23:40:42 +00:00
|
|
|
|
2005-03-27 04:43:49 +00:00
|
|
|
{ "megaco", "MEGACO",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_MEGACO, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_megaco, array_length(pkt_megaco),
|
|
|
|
NULL, 0 },
|
2005-03-27 04:43:49 +00:00
|
|
|
|
1999-10-07 07:55:12 +00:00
|
|
|
{ "nbns", "NetBIOS-over-TCP Name Service",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_NBNS, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_nbns, array_length(pkt_nbns),
|
|
|
|
NULL, 0 },
|
1999-10-07 07:55:12 +00:00
|
|
|
|
2005-03-27 04:43:49 +00:00
|
|
|
{ "ncp2222", "NetWare Core Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_NCP2222, WTAP_ENCAP_TOKEN_RING,
|
|
|
|
pkt_ncp2222, array_length(pkt_ncp2222),
|
|
|
|
NULL, 0 },
|
2005-03-27 04:43:49 +00:00
|
|
|
|
|
|
|
{ "sctp", "Stream Control Transmission Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_SCTP, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_sctp, array_length(pkt_sctp),
|
|
|
|
NULL, 0 },
|
2005-03-27 04:43:49 +00:00
|
|
|
|
2000-06-11 15:54:03 +00:00
|
|
|
{ "syslog", "Syslog message",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_SYSLOG, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_syslog, array_length(pkt_syslog),
|
|
|
|
NULL, 0 },
|
2000-06-11 15:54:03 +00:00
|
|
|
|
2005-03-27 04:43:49 +00:00
|
|
|
{ "tds", "TDS NetLib",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_TDS, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_tds, array_length(pkt_tds),
|
|
|
|
NULL, 0 },
|
2005-03-27 04:43:49 +00:00
|
|
|
|
1999-09-10 15:38:58 +00:00
|
|
|
{ "tcp", "Transmission Control Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_TCP, WTAP_ENCAP_TOKEN_RING,
|
|
|
|
pkt_tcp, array_length(pkt_tcp),
|
|
|
|
NULL, 0 },
|
1999-09-10 15:38:58 +00:00
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
{ "tr", "Token-Ring",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_TR, WTAP_ENCAP_TOKEN_RING,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, 0 },
|
1999-09-10 15:38:58 +00:00
|
|
|
|
|
|
|
{ "udp", "User Datagram Protocol",
|
2009-05-17 21:41:23 +00:00
|
|
|
PKT_UDP, WTAP_ENCAP_ETHERNET,
|
|
|
|
pkt_udp, array_length(pkt_udp),
|
|
|
|
NULL, 0 },
|
|
|
|
|
|
|
|
{ "usb", "Universal Serial Bus",
|
|
|
|
PKT_USB, WTAP_ENCAP_USB,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, 0 },
|
|
|
|
|
|
|
|
{ "usb-linux", "Universal Serial Bus with Linux specific header",
|
|
|
|
PKT_USB_LINUX, WTAP_ENCAP_USB_LINUX,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, 0 },
|
2002-02-14 17:45:07 +00:00
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int parse_type(char *string);
|
2013-12-31 16:17:09 +00:00
|
|
|
static void usage(gboolean is_error);
|
1999-09-10 05:15:17 +00:00
|
|
|
static void seed(void);
|
|
|
|
|
|
|
|
static pkt_example* find_example(int type);
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wtap_dumper *dump;
|
1999-09-10 05:15:17 +00:00
|
|
|
struct wtap_pkthdr pkthdr;
|
2012-10-16 21:50:57 +00:00
|
|
|
union wtap_pseudo_header *ps_header = &pkthdr.pseudo_header;
|
1999-09-10 05:15:17 +00:00
|
|
|
int i, j, len_this_pkt, len_random, err;
|
|
|
|
guint8 buffer[65536];
|
|
|
|
|
|
|
|
int opt;
|
2011-01-06 23:28:58 +00:00
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
int produce_count = 1000; /* number of pkts to produce */
|
|
|
|
int produce_type = PKT_ETHERNET;
|
|
|
|
char *produce_filename = NULL;
|
|
|
|
int produce_max_bytes = 5000;
|
|
|
|
pkt_example *example;
|
|
|
|
|
2011-01-06 23:28:58 +00:00
|
|
|
#ifdef _WIN32
|
2011-05-24 00:07:56 +00:00
|
|
|
arg_list_utf_16to8(argc, argv);
|
2013-02-20 01:19:42 +00:00
|
|
|
create_app_running_mutex();
|
2011-01-06 23:28:58 +00:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2008-11-17 21:46:57 +00:00
|
|
|
while ((opt = getopt(argc, argv, "b:c:ht:")) != -1) {
|
1999-09-10 05:15:17 +00:00
|
|
|
switch (opt) {
|
|
|
|
case 'b': /* max bytes */
|
|
|
|
produce_max_bytes = atoi(optarg);
|
|
|
|
if (produce_max_bytes > 65536) {
|
2008-10-31 20:11:14 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"randpkt: Max bytes is 65536\n");
|
|
|
|
exit(1);
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c': /* count */
|
|
|
|
produce_count = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': /* type of packet to produce */
|
|
|
|
produce_type = parse_type(optarg);
|
|
|
|
break;
|
|
|
|
|
2008-11-17 21:46:57 +00:00
|
|
|
case 'h':
|
2013-12-31 16:17:09 +00:00
|
|
|
usage(FALSE);
|
|
|
|
break;
|
1999-09-10 05:15:17 +00:00
|
|
|
default:
|
2013-12-31 16:17:09 +00:00
|
|
|
usage(TRUE);
|
1999-09-10 05:15:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* any more command line parameters? */
|
|
|
|
if (argc > optind) {
|
|
|
|
produce_filename = argv[optind];
|
|
|
|
}
|
|
|
|
else {
|
2013-12-31 16:17:09 +00:00
|
|
|
usage(TRUE);
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
example = find_example(produce_type);
|
|
|
|
|
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
dump = wtap_dump_open(produce_filename, WTAP_FILE_TYPE_SUBTYPE_PCAP,
|
2005-09-14 21:57:30 +00:00
|
|
|
example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */, &err);
|
2008-10-31 20:11:14 +00:00
|
|
|
if (!dump) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"randpkt: Error writing to %s\n", produce_filename);
|
|
|
|
exit(2);
|
|
|
|
}
|
1999-09-10 05:15:17 +00:00
|
|
|
|
|
|
|
seed();
|
|
|
|
|
|
|
|
/* reduce max_bytes by # of bytes already in sample */
|
|
|
|
if (produce_max_bytes <= example->sample_length) {
|
2008-10-31 20:11:14 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"randpkt: Sample packet length is %d, which is greater than or equal to\n",
|
|
|
|
example->sample_length);
|
|
|
|
fprintf(stderr, "your requested max_bytes value of %d\n",
|
|
|
|
produce_max_bytes);
|
|
|
|
exit(1);
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
produce_max_bytes -= example->sample_length;
|
|
|
|
}
|
|
|
|
|
2009-05-17 21:41:23 +00:00
|
|
|
memset(&pkthdr, 0, sizeof(pkthdr));
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
pkthdr.rec_type = REC_TYPE_PACKET;
|
2014-05-23 23:23:58 +00:00
|
|
|
pkthdr.presence_flags = WTAP_HAS_TS;
|
2009-05-17 21:41:23 +00:00
|
|
|
pkthdr.pkt_encap = example->sample_wtap_encap;
|
|
|
|
|
|
|
|
/* Load the sample pseudoheader into our pseudoheader buffer */
|
|
|
|
if (example->pseudo_buffer)
|
2012-10-16 21:50:57 +00:00
|
|
|
memcpy(ps_header, example->pseudo_buffer, example->pseudo_length);
|
2009-05-17 21:41:23 +00:00
|
|
|
|
1999-09-10 05:15:17 +00:00
|
|
|
/* Load the sample into our buffer */
|
|
|
|
if (example->sample_buffer)
|
|
|
|
memcpy(&buffer[0], example->sample_buffer, example->sample_length);
|
|
|
|
|
|
|
|
/* Produce random packets */
|
|
|
|
for (i = 0; i < produce_count; i++) {
|
|
|
|
if (produce_max_bytes > 0) {
|
|
|
|
len_random = (rand() % produce_max_bytes + 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len_random = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
len_this_pkt = example->sample_length + len_random;
|
|
|
|
|
|
|
|
pkthdr.caplen = len_this_pkt;
|
|
|
|
pkthdr.len = len_this_pkt;
|
2005-08-24 23:53:40 +00:00
|
|
|
pkthdr.ts.secs = i; /* just for variety */
|
1999-09-10 05:15:17 +00:00
|
|
|
|
2012-10-16 21:50:57 +00:00
|
|
|
for (j = example->pseudo_length; j < (int) sizeof(*ps_header); j++) {
|
|
|
|
((guint8*)ps_header)[j] = (rand() % 0x100);
|
2009-05-17 21:41:23 +00:00
|
|
|
}
|
|
|
|
|
2005-07-26 16:54:08 +00:00
|
|
|
for (j = example->sample_length; j < len_this_pkt; j++) {
|
2005-03-17 16:06:20 +00:00
|
|
|
/* Add format strings here and there */
|
|
|
|
if ((int) (100.0*rand()/(RAND_MAX+1.0)) < 3 && j < (len_random - 3)) {
|
|
|
|
memcpy(&buffer[j], "%s", 3);
|
|
|
|
j += 2;
|
|
|
|
} else {
|
|
|
|
buffer[j] = (rand() % 0x100);
|
|
|
|
}
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 21:50:57 +00:00
|
|
|
wtap_dump(dump, &pkthdr, &buffer[0], &err);
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wtap_dump_close(dump, &err);
|
1999-09-10 05:15:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print usage statement and exit program */
|
2013-12-31 16:17:09 +00:00
|
|
|
static void
|
|
|
|
usage(gboolean is_error)
|
1999-09-10 05:15:17 +00:00
|
|
|
{
|
2013-12-31 16:17:09 +00:00
|
|
|
FILE *output;
|
|
|
|
int num_entries = array_length(examples);
|
|
|
|
int i;
|
1999-09-10 05:15:17 +00:00
|
|
|
|
2013-12-31 16:17:09 +00:00
|
|
|
if (!is_error) {
|
|
|
|
output = stdout;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
output = stderr;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(output, "Usage: randpkt [-b maxbytes] [-c count] [-t type] filename\n");
|
|
|
|
fprintf(output, "Default max bytes (per packet) is 5000\n");
|
|
|
|
fprintf(output, "Default count is 1000.\n");
|
|
|
|
fprintf(output, "Types:\n");
|
1999-09-10 05:15:17 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) {
|
2013-12-31 16:17:09 +00:00
|
|
|
fprintf(output, "\t%-16s%s\n", examples[i].abbrev, examples[i].longname);
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
|
2013-12-31 16:17:09 +00:00
|
|
|
fprintf(output, "\n");
|
1999-09-10 05:15:17 +00:00
|
|
|
|
2013-12-31 16:17:09 +00:00
|
|
|
exit(is_error ? 1 : 0);
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse command-line option "type" and return enum type */
|
|
|
|
static
|
|
|
|
int parse_type(char *string)
|
|
|
|
{
|
|
|
|
int num_entries = array_length(examples);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) {
|
|
|
|
if (strcmp(examples[i].abbrev, string) == 0) {
|
|
|
|
return examples[i].produceable_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-14 17:45:07 +00:00
|
|
|
/* Complain */
|
2008-10-31 20:11:14 +00:00
|
|
|
fprintf(stderr, "randpkt: Type %s not known.\n", string);
|
2002-02-14 17:45:07 +00:00
|
|
|
exit(1);
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find pkt_example record and return pointer to it */
|
|
|
|
static
|
|
|
|
pkt_example* find_example(int type)
|
|
|
|
{
|
|
|
|
int num_entries = array_length(examples);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) {
|
|
|
|
if (examples[i].produceable_type == type) {
|
|
|
|
return &examples[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-31 20:11:14 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"randpkt: Internal error. Type %d has no entry in examples table.\n",
|
|
|
|
type);
|
2002-02-14 17:45:07 +00:00
|
|
|
exit(1);
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Seed the random-number generator */
|
|
|
|
void
|
|
|
|
seed(void)
|
|
|
|
{
|
|
|
|
unsigned int randomness;
|
2013-12-31 16:17:09 +00:00
|
|
|
time_t now;
|
2008-10-31 20:11:14 +00:00
|
|
|
#ifndef _WIN32
|
1999-09-10 05:15:17 +00:00
|
|
|
int fd;
|
2008-10-31 20:11:14 +00:00
|
|
|
ssize_t ret;
|
|
|
|
|
2010-01-06 17:18:57 +00:00
|
|
|
#define RANDOM_DEV "/dev/urandom"
|
|
|
|
|
2008-10-31 20:11:14 +00:00
|
|
|
/*
|
2010-01-06 17:18:57 +00:00
|
|
|
* Assume it's at least worth trying /dev/urandom on UN*X.
|
2008-10-31 20:11:14 +00:00
|
|
|
* If it doesn't exist, fall back on time().
|
|
|
|
*
|
2010-01-06 17:18:57 +00:00
|
|
|
* XXX - Use CryptGenRandom on Windows?
|
2008-10-31 20:11:14 +00:00
|
|
|
*/
|
2011-06-23 13:51:26 +00:00
|
|
|
fd = ws_open(RANDOM_DEV, O_RDONLY);
|
2008-10-31 20:11:14 +00:00
|
|
|
if (fd == -1) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
fprintf(stderr,
|
2010-01-06 17:18:57 +00:00
|
|
|
"randpkt: Could not open " RANDOM_DEV " for reading: %s\n",
|
2011-06-28 09:00:11 +00:00
|
|
|
g_strerror(errno));
|
2008-10-31 20:11:14 +00:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
goto fallback;
|
1999-09-10 05:15:17 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 13:51:26 +00:00
|
|
|
ret = ws_read(fd, &randomness, sizeof randomness);
|
2008-10-31 20:11:14 +00:00
|
|
|
if (ret == -1) {
|
|
|
|
fprintf(stderr,
|
2010-01-06 17:18:57 +00:00
|
|
|
"randpkt: Could not read from " RANDOM_DEV ": %s\n",
|
2011-06-28 09:00:11 +00:00
|
|
|
g_strerror(errno));
|
2008-10-31 20:11:14 +00:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
if ((size_t)ret != sizeof randomness) {
|
|
|
|
fprintf(stderr,
|
2010-01-06 17:18:57 +00:00
|
|
|
"randpkt: Tried to read %lu bytes from " RANDOM_DEV ", got %ld\n",
|
2008-10-31 20:11:14 +00:00
|
|
|
(unsigned long)sizeof randomness, (long)ret);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
srand(randomness);
|
2011-06-23 13:51:26 +00:00
|
|
|
ws_close(fd);
|
2008-10-31 20:11:14 +00:00
|
|
|
return;
|
1999-09-10 05:15:17 +00:00
|
|
|
|
2008-10-31 20:11:14 +00:00
|
|
|
fallback:
|
|
|
|
#endif
|
1999-09-10 05:15:17 +00:00
|
|
|
now = time(NULL);
|
|
|
|
randomness = (unsigned int) now;
|
|
|
|
|
|
|
|
srand(randomness);
|
|
|
|
}
|
2013-12-31 16:17:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|