source: test/test-wireless.c @ e111394

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since e111394 was 0c835744, checked in by Perry Lorier <perry@…>, 11 years ago

Update to avoid using deprecated trace_get_link()

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007 The University of Waikato, Hamilton, New Zealand.
5 * Authors: Daniel Lawson
6 *          Perry Lorier
7 *         
8 * All rights reserved.
9 *
10 * This code has been developed by the University of Waikato WAND
11 * research group. For further information please see http://www.wand.net.nz/
12 *
13 * libtrace is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * libtrace is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libtrace; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 *
27 * $Id: test-pcap-to-erf.c,v 1.3 2006/02/27 03:41:12 perry Exp $
28 *
29 */
30#ifndef WIN32
31#  include <sys/time.h>
32#  include <netinet/in.h>
33#  include <netinet/in_systm.h>
34#  include <netinet/tcp.h>
35#  include <netinet/ip.h>
36#  include <netinet/ip_icmp.h>
37#  include <arpa/inet.h>
38#  include <sys/socket.h>
39#endif
40
41#include <stdio.h>
42#include <stdlib.h>
43#include <assert.h>
44#include <string.h>
45#include <sys/types.h>
46#include <time.h>
47#include <string.h>
48
49#include "libtrace.h"
50
51void iferr(libtrace_t *trace)
52{
53        libtrace_err_t err = trace_get_err(trace);
54        if (err.err_num==0)
55                return;
56        printf("Error: %s\n",err.problem);
57        exit(1);
58}
59
60
61int main(int argc, char *argv[]) {
62        libtrace_t *trace;
63        libtrace_packet_t *packet;
64        int result;
65        uint64_t tsft;
66        uint16_t freq, tmp16;
67        uint8_t flags, rate, sdbm, ndbm, sdb, antenna, tmp8;
68       
69        uint16_t total_freq, expected_freq = 24170;
70       
71        void *l;
72        libtrace_linktype_t lt;
73        trace = trace_create("pcapfile:traces/10_packets_radiotap.pcap");
74        iferr(trace);
75
76        trace_start(trace);
77        iferr(trace);
78       
79        packet=trace_create_packet();
80
81        trace_read_packet(trace, packet);
82
83        l = trace_get_packet_buffer(packet, &lt,NULL);
84
85        /* Check that the right linktype is being reported for this trace */
86        assert(lt == TRACE_TYPE_80211_RADIO);
87
88        /* Check that fields that exist in this trace are reported as
89         * existing */
90        assert(trace_get_wireless_tsft(l,lt,&tsft));
91        assert(trace_get_wireless_rate(l,lt,&rate));
92        assert(trace_get_wireless_freq(l,lt,&freq));
93        assert(trace_get_wireless_signal_strength_dbm(l,lt,(int8_t *)&sdbm));
94        assert(trace_get_wireless_noise_strength_dbm(l,lt,(int8_t *)&ndbm));
95        assert(trace_get_wireless_signal_strength_db(l,lt,&sdb));
96        assert(trace_get_wireless_antenna(l,lt,&antenna));
97
98        /* Check that the fields that do not exist in this trace are
99         * reported as not existing */
100        assert(!trace_get_wireless_noise_strength_db(l,lt,&tmp8));
101        assert(!trace_get_wireless_tx_attenuation(l,lt,&tmp16));
102        assert(!trace_get_wireless_tx_attenuation_db(l,lt,&tmp16));
103        assert(!trace_get_wireless_tx_power_dbm(l,lt,(int8_t *)&tmp8));
104
105        /* Check that the functions are returning the right values for
106         * this trace
107         * TODO: Check all fields :)
108         */
109        total_freq = freq;
110       
111        while((result = trace_read_packet(trace, packet)) > 0) {
112                /* This trace has no FCS at the end of packets, so ensure
113                 * that wire-length is 4 bytes greater than capture length */
114                int caplen = trace_get_capture_length(packet);
115                int wirelen = trace_get_wire_length(packet);
116                assert(wirelen == caplen + 4);
117                if(trace_get_wireless_freq(l,lt,&freq)) 
118                        total_freq += freq;
119        }
120
121        assert(total_freq == expected_freq);
122
123        trace_destroy_packet(packet);
124        trace_destroy(trace);
125               
126        /* Now check that we don't process non-radiotap traces */
127       
128        trace = trace_create("pcapfile:traces/100_packets.pcap");
129        iferr(trace);
130        trace_start(trace);
131        iferr(trace);
132        packet = trace_create_packet();
133        trace_read_packet(trace,packet);
134        l = trace_get_packet_buffer(packet,&lt,NULL);
135        assert(lt != TRACE_TYPE_80211_RADIO);
136
137        assert(!trace_get_wireless_tsft(l,lt,&tsft));
138        assert(!trace_get_wireless_rate(l,lt,&rate));
139        assert(!trace_get_wireless_freq(l,lt,&freq));
140        assert(!trace_get_wireless_signal_strength_dbm(l,lt,(int8_t *)&sdbm));
141        assert(!trace_get_wireless_noise_strength_dbm(l,lt,(int8_t *)&ndbm));
142        assert(!trace_get_wireless_signal_strength_db(l,lt,&sdb));
143        assert(!trace_get_wireless_antenna(l,lt,&antenna));
144        assert(!trace_get_wireless_noise_strength_db(l,lt,&tmp8));
145        assert(!trace_get_wireless_tx_attenuation(l,lt,&tmp16));
146        assert(!trace_get_wireless_tx_attenuation_db(l,lt,&tmp16));
147        assert(!trace_get_wireless_tx_power_dbm(l,lt,(int8_t *)&tmp8));
148
149
150        trace_destroy_packet(packet);
151        trace_destroy(trace);
152        return 0;
153}
Note: See TracBrowser for help on using the repository browser.