source: examples/protocol/protocol.c @ c792590

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since c792590 was c792590, checked in by Daniel Lawson <dlawson@…>, 16 years ago

accepts a filter on the cmdline

  • Property mode set to 100644
File size: 1.2 KB
Line 
1// $Id$
2
3#include <stdio.h> /* printf */
4#include <netinet/in.h> /* ntohs */
5#include <netdb.h>
6#include "dagformat.h"
7
8#include "libtrace.h"
9
10struct libtrace_t *trace;
11
12char *buffer[4096];
13
14int main(int argc, char *argv[]) {
15
16        char *hostname = "rtclient:chasm.cs.waikato.ac.nz";
17        char *filterstring = 0;
18        struct libtrace_ip *ipptr = 0;
19       
20        int status; // need to pass to rtclient_read_packet
21        int psize;
22        if (argc == 2) {
23                hostname = argv[1];
24        }
25        if (argc == 3) {
26                hostname = argv[1];
27                filterstring = argv[2];
28        }
29
30        // create an rtclient to hostname, on the default port
31        trace = create_trace(hostname);
32        if (filterstring) {
33                libtrace_bpf_setfilter(trace,filterstring);
34        }
35
36        for (;;) {
37                if ((psize = libtrace_read_packet(trace, buffer,4096, &status)) <= 0) {
38                        // terminate
39                        break;
40                }
41                if (!libtrace_bpf_filter(trace, buffer, 4096)) {
42                        continue;
43                }
44                ipptr = get_ip(trace,buffer,4096);
45                if (ipptr) {
46                        printf("%d:%d\n",ipptr->ip_p,get_link_type(trace,buffer,4096));
47                }
48        }
49        destroy_trace(trace);
50        return 0;
51}
Note: See TracBrowser for help on using the repository browser.