Make infiniband plugin compile.
[obnox/wireshark/wip.git] / randpkt.c
index 8b486daef72ca7a99fd68724355ae141eb0793dc..ab88c2c907f4efc1fa35e722e4fd34290b30d31e 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
@@ -4,7 +4,7 @@
  * Creates random packet traces. Useful for debugging sniffers by testing
  * assumptions about the veracity of the data found in the packet.
  *
- * $Id: randpkt.c,v 1.18 2002/11/17 21:47:41 gerald Exp $
+ * $Id$
  *
  * Copyright (C) 1999 by Gilbert Ramirez <gram@alumni.rice.edu>
  *
 /* Types of produceable packets */
 enum {
        PKT_ARP,
+       PKT_BGP,
+       PKT_BVLC,
        PKT_DNS,
        PKT_ETHERNET,
        PKT_FDDI,
+       PKT_GIOP,
        PKT_ICMP,
        PKT_IP,
        PKT_LLC,
+       PKT_M2M,
+       PKT_MEGACO,
        PKT_NBNS,
+       PKT_NCP2222,
+       PKT_SCTP,
        PKT_SYSLOG,
        PKT_TCP,
-       PKT_TR,
-       PKT_UDP,
-       PKT_BVLC,
-       PKT_NCP2222,
-       PKT_GIOP,
-       PKT_BGP,
        PKT_TDS,
+       PKT_TR,
+       PKT_UDP
 };
 
 typedef struct {
-       char    *abbrev;
-       char    *longname;
-       int     produceable_type;
-       guint8  *sample_buffer;
-       int     sample_wtap_encap;
-       int     sample_length;
+       const char      *abbrev;
+       const char      *longname;
+       int             produceable_type;
+       guint8          *sample_buffer;
+       int             sample_wtap_encap;
+       int             sample_length;
 } pkt_example;
 
 /* Ethernet, indicating ARP */
@@ -102,7 +105,7 @@ guint8 pkt_dns[] = {
        0x0a, 0x01, 0x01, 0x63,
 
        0x05, 0xe8, 0x00, 0x35,
-       0x00, 0x00, 0x2a, 0xb9,
+       0xff, 0xff, 0x2a, 0xb9,
        0x30
 };
 
@@ -136,6 +139,14 @@ guint8 pkt_llc[] = {
        0xc4, 0x67
 };
 
+/* Ethernet, indicating WiMAX M2M */
+guint8 pkt_m2m[] = {
+       0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0x00, 0x00,
+       0x32, 0x25, 0x0f, 0xff,
+       0x08, 0xf0
+};
+
 /* Ethernet+IP+UDP, indicating NBNS */
 guint8 pkt_nbns[] = {
        0xff, 0xff, 0xff, 0xff,
@@ -315,11 +326,54 @@ guint8 pkt_tds[] = {
        0x0f, 0xda, 0x00, 0x00,
 };
 
+/* 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,
+};
+
 /* This little data table drives the whole program */
 pkt_example examples[] = {
        { "arp", "Address Resolution Protocol",
                PKT_ARP,        pkt_arp,        WTAP_ENCAP_ETHERNET,    array_length(pkt_arp) },
 
+       { "bgp", "Border Gateway Protocol",
+               PKT_BGP,        pkt_bgp,        WTAP_ENCAP_ETHERNET,    array_length(pkt_bgp) },
+
+       { "bvlc", "BACnet Virtual Link Control",
+               PKT_BVLC,       pkt_bvlc,       WTAP_ENCAP_ETHERNET,    array_length(pkt_bvlc) },
+
        { "dns", "Domain Name Service",
                PKT_DNS,        pkt_dns,        WTAP_ENCAP_ETHERNET,    array_length(pkt_dns) },
 
@@ -329,6 +383,9 @@ pkt_example examples[] = {
        { "fddi", "Fiber Distributed Data Interface",
                PKT_FDDI,       NULL,           WTAP_ENCAP_FDDI,        0 },
 
+       { "giop", "General Inter-ORB Protocol",
+               PKT_GIOP,       pkt_giop,       WTAP_ENCAP_ETHERNET,    array_length(pkt_giop) },
+
        { "icmp", "Internet Control Message Protocol",
                PKT_ICMP,       pkt_icmp,       WTAP_ENCAP_ETHERNET,    array_length(pkt_icmp) },
 
@@ -338,12 +395,27 @@ pkt_example examples[] = {
        { "llc", "Logical Link Control",
                PKT_LLC,        pkt_llc,        WTAP_ENCAP_TOKEN_RING,  array_length(pkt_llc) },
 
+       { "m2m", "WiMAX M2M Encapsulation Protocol",
+               PKT_M2M,        pkt_m2m,        WTAP_ENCAP_ETHERNET,    array_length(pkt_m2m) },
+
+       { "megaco", "MEGACO",
+               PKT_MEGACO,     pkt_megaco,     WTAP_ENCAP_ETHERNET,    array_length(pkt_megaco) },
+
        { "nbns", "NetBIOS-over-TCP Name Service",
                PKT_NBNS,       pkt_nbns,       WTAP_ENCAP_ETHERNET,    array_length(pkt_nbns) },
 
+       { "ncp2222", "NetWare Core Protocol",
+               PKT_NCP2222,    pkt_ncp2222,    WTAP_ENCAP_TOKEN_RING,  array_length(pkt_ncp2222) },
+
+       { "sctp", "Stream Control Transmission Protocol",
+               PKT_SCTP,       pkt_sctp,       WTAP_ENCAP_ETHERNET,    array_length(pkt_sctp) },
+
        { "syslog", "Syslog message",
                PKT_SYSLOG,     pkt_syslog,     WTAP_ENCAP_ETHERNET,    array_length(pkt_syslog) },
 
+       { "tds", "TDS NetLib",
+               PKT_TDS,        pkt_tds,        WTAP_ENCAP_ETHERNET,    array_length(pkt_tds) },
+
        { "tcp", "Transmission Control Protocol",
                PKT_TCP,        pkt_tcp,        WTAP_ENCAP_TOKEN_RING,  array_length(pkt_tcp) },
 
@@ -353,21 +425,6 @@ pkt_example examples[] = {
        { "udp", "User Datagram Protocol",
                PKT_UDP,        pkt_udp,        WTAP_ENCAP_ETHERNET,    array_length(pkt_udp) },
 
-       { "bvlc", "BACnet Virtual Link Control",
-               PKT_BVLC,       pkt_bvlc,       WTAP_ENCAP_ETHERNET,    array_length(pkt_bvlc) },
-
-       { "ncp2222", "NetWare Core Protocol",
-               PKT_NCP2222,    pkt_ncp2222,    WTAP_ENCAP_TOKEN_RING,  array_length(pkt_ncp2222) },
-
-       { "giop", "General Inter-ORB Protocol",
-               PKT_GIOP,       pkt_giop,       WTAP_ENCAP_ETHERNET,    array_length(pkt_giop) },
-
-       { "bgp", "Border Gateway Protocol",
-               PKT_BGP,        pkt_bgp,        WTAP_ENCAP_ETHERNET,    array_length(pkt_bgp) },
-
-       { "tds", "TDS NetLib",
-               PKT_TDS,        pkt_tds,        WTAP_ENCAP_ETHERNET,    array_length(pkt_tds) },
-
 };
 
 
@@ -432,12 +489,16 @@ main(int argc, char **argv)
 
        example = find_example(produce_type);
 
-       pkthdr.ts.tv_sec = 0;
-       pkthdr.ts.tv_usec = 0;
+       pkthdr.ts.secs = 0;
+       pkthdr.ts.nsecs = 0;
        pkthdr.pkt_encap = example->sample_wtap_encap;
 
        dump = wtap_dump_open(produce_filename, WTAP_FILE_PCAP,
-               example->sample_wtap_encap, produce_max_bytes, &err);
+               example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */, &err);
+    if (!dump) {
+        printf("Error writing to %s\n", produce_filename);
+        exit(1);
+    }
 
        seed();
 
@@ -468,10 +529,16 @@ main(int argc, char **argv)
 
                pkthdr.caplen = len_this_pkt;
                pkthdr.len = len_this_pkt;
-               pkthdr.ts.tv_sec = i; /* just for variety */
-
-               for (j = example->sample_length; j < len_random; j++) {
-                       buffer[j] = (rand() % 0x100);
+               pkthdr.ts.secs = i; /* just for variety */
+
+               for (j = example->sample_length; j < len_this_pkt; j++) {
+                       /* 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);
+                       }
                }
 
                wtap_dump(dump, &pkthdr, &ps_header, &buffer[0], &err);