1tcp_dump_packets.c dumps network packets in a C source file.
2
3It is written to be added to the "pc" project ( Windows simulator ). It uses the file system to write 2 C source files:
4
5    PacketList.c
6    PacketList.h
7
8How to include 'tcp_dump_packets' into a project:
9
10● Make sure that tools/tcp_dump_packets.c is added to the source files
11● See if Network Interface has been adapted to call:
12    `iptraceDUMP_PACKET( ucBuffer, xLength, pdTRUE );     /* Incoming packet. */`
13    `iptraceDUMP_PACKET( ucBuffer, xLength, pdFALSE );    /* Outgoing packet. */`
14● Once the network is up, call `dump_packet_init()` with a file name and a pointer to
15  `DumpEntries_t`, which contains the requirements. For instance like this:
16   static DumpEntries_t xExampleEntries = {
17       .uxEntryCount = 4,	/* No more than 'dumpMAX_DUMP_ENTRIES' elements. */
18       .xEntries = {
19           { .ulMask = flag_IN | flag_UDP,   .uxMax = 2u },
20           { .ulMask = flag_IN | flag_ARP,   .uxMax = 2u },
21           { .ulMask = flag_IN | flag_TCP,   .uxMax = 5u },
22           { .ulMask = flag_IN | flag_SYN,   .uxMax = 1u },
23       }
24   };
25● Add the following lines to FreeRTOSIPConfig.h :
26    #define ipconfigUSE_DUMP_PACKETS                    ( 1 )
27    #include "../tools/tcp_dump_packets.h"
28
29Later on, the module can disabled by simply setting `ipconfigUSE_DUMP_PACKETS` to `0`.
30
31Here is some contents of the output file:
32
33    /* Packet_0001 */
34    uint8_t ucPacket_0001[ 60 ] =
35    {
36        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x74, 0xb5, 0x7e, 0xf0, 0x47, 0xee, 0x08, 0x06, 0x00, 0x01,
37        0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x74, 0xb5, 0x7e, 0xf0, 0x47, 0xee, 0xc0, 0xa8, 0x02, 0x01,
38        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x02, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
40    };
41
42    DumpPacket_t xPacket_0001 =
43    {
44        .pucData = ucPacket_0001,
45        .uxLength = 60,
46        .ulType = 0x6840, /* IN | FRAME_ARP | ARP | REQUEST */
47    };
48    /*-----------------------------------------------------------*/
49
50tcp_dump_packets has an enum of all possible properties of network packets:
51    ICMP4, ICMP6, UDP, TCP, DNS, REPLY, REQUEST, SYN,
52    FIN, RST, ACK, IN, OUT, ARP, FRAME_ARP, FRAME_4, and FRAME_6
53
54Each property is defined as a bit so they can be combined as in:
55    .ulType = 0x6840, /* IN | FRAME_ARP | ARP | REQUEST */
56
57Finishing: when there are enough packets of all required types, an array is added to the C-source output:
58
59    DumpPacket_t *xPacketList[ dumpPACKET_COUNT ] =
60    {
61        &xPacket_0000,
62        &xPacket_0001,
63        &xPacket_0002,
64        &xPacket_0003,
65        &xPacket_0004,
66        &xPacket_0005,
67        &xPacket_0006,
68        &xPacket_0007,
69        &xPacket_0008,
70    };
71
72The new source file PacketList.{c, h} can be used in testing software as sample packets.
73