source: test/test-vlan.c @ e78e408

develop
Last change on this file since e78e408 was e78e408, checked in by Jacob van Walraven <jacobvw@…>, 21 months ago

Add some tests for trace_get_outermost_vlan, trace_get_outermost_mpls and trace_get_layer2_headers

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include "libtrace.h"
2#include <stdio.h>
3#include <stdlib.h>
4
5void iferr(libtrace_t *trace)
6{
7        libtrace_err_t err = trace_get_err(trace);
8        if (err.err_num==0)
9                return;
10        printf("Error: %s\n",err.problem);
11        exit(1);
12}
13
14
15int main(int argc, char *argv[]) {
16
17        libtrace_t *trace = NULL;
18        libtrace_packet_t *packet = NULL;
19        int i = 0;
20        uint16_t vlanid;
21        uint8_t *vlanptr;
22        uint32_t remaining;
23        int error = 0;
24
25        packet = trace_create_packet();
26
27        trace = trace_create("pcapfile:traces/vlan.pcap");
28        iferr(trace);
29
30        trace_start(trace);
31        iferr(trace);
32
33        /* read a packet */
34        trace_read_packet(trace, packet);
35        /* first packet in this trace should have a vlan tag of 32 */
36        vlanid = trace_get_outermost_vlan(packet, &vlanptr, &remaining);
37        if (vlanid != 32) {
38                printf("Failed to find correct outermost vlan tag\n");
39                error = 1;
40        }
41
42        /* read a packet */
43        trace_read_packet(trace, packet);
44        vlanid = trace_get_outermost_vlan(packet, &vlanptr, &remaining);
45        if (vlanid != 32) {
46                printf("Failed to find correct outermost vlan tag\n");
47                error = 1;
48        }
49
50        if (error == 0) {
51                printf("success\n");
52        } else {
53                iferr(trace);
54        }
55
56        trace_destroy(trace);
57        trace_destroy_packet(packet);
58
59        return error;
60}
Note: See TracBrowser for help on using the repository browser.