Add initial .gitignore files
[obnox/wireshark/wip.git] / doc / randpkt.txt
1 Random Packet Generator
2 -----------------------
3 $Id$
4
5 randpkt is a small utility creates a libpcap trace file full of random packets.
6 You can control the number of packets, the maximum size of each packet,
7 and the type of each packet. It is not build by default, but you
8 can create it in the top-level Wireshark directory by typing:
9
10 make randpkt
11
12 By creating many randomized packets of a certain type, you can
13 test packet sniffers to see how well they handle malformed packets.
14 The sniffer can never trust the data that it sees in the packet because
15 you can always sniff a very bad packet that conforms to no standard.
16 Randpkt produces __very bad__ packets.
17
18 When creating packets of a certain type, randpkt uses a sample
19 packet that is stored internally to randpkt. It uses this as the
20 starting point for your random packets, and then adds extra random
21 bytes to the end of this sample packet.
22
23 For example, if you choose to create random ARP packets, randpkt
24 will create a packet which contains a predetermined Ethernet II header,
25 with the Type field set to ARP. After the Ethernet II header, it will
26 put a random number of bytes with random values.
27
28 Run 'randpkt' with no options to see the usage statement. As of the
29 writing of this text, the usage is:
30
31 Usage: randpkt [-b maxbytes] [-c count] [-t type] filename
32
33 The usage statement produced by randpkt will list the legal types.
34
35 If you choose a maxbytes value that is less than the size of the
36 sample packet, then your packets would contain only the sample
37 packet... not much variance there! Randpkt exits on that condition.
38
39 To add a new packet type to randpkt, you must add information
40 in the following locations.
41
42 1) Add the packet type name to the enum of produceable packets:
43
44         /* Types of produceable packets */
45         enum {
46                 PKT_ARP,
47                 PKT_ETHERNET,
48                 PKT_FDDI,
49                 PKT_LLC,
50                 PKT_TR
51         };
52
53
54 2) Type in the bytes from your sample packet
55
56         /* Ethernet, indicating ARP */
57         guint8 pkt_arp[] = {
58                 0xff, 0xff, 0xff, 0xff,
59                 0xff, 0xff, 0x00, 0x00,
60                 0x32, 0x25, 0x0f, 0xff,
61                 0x08, 0x06
62         };
63
64
65 3) Add a record to the 'examples' array. The fields are
66                 1. Abbreviation (for use in '-t' command line argument)
67                 2. Full name (for use in usage statement)
68                 3. Enum type
69                 4. Array holding sample packet
70                 5. Wiretap encapsulation type of datalink layer in your
71                         sample packet
72                 6. Length of sample packet. Use the handy array_length()
73                         macro to avoid counting the bytes yourself.
74
75
76         pkt_example examples[] = {
77                 { "arp",
78                         "Address Resolution Protocol",
79                         PKT_ARP,
80                         pkt_arp,
81                         WTAP_ENCAP_ETHERNET,
82                         array_length(pkt_arp) },
83
84                 { "eth",
85                         "Ethernet",
86                         PKT_ETHERNET,
87                         NULL,
88                         WTAP_ENCAP_ETHERNET,
89                         0 },
90         };
91
92 Note that packets that designate only their datalink type have no sample
93 arrays, since the only thing that needs to be set is the datalink type,
94 which is a field in the libpcap frame record; it's not a part of the
95 packet itself.
96
97 Enjoy!