1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. |
---|
5 | * Authors: Perry Lorier |
---|
6 | * |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * This code has been developed by the University of Waikato WAND |
---|
10 | * research group. For further information please see http://www.wand.net.nz/ |
---|
11 | * |
---|
12 | * libtrace is free software; you can redistribute it and/or modify |
---|
13 | * it under the terms of the GNU General Public License as published by |
---|
14 | * the Free Software Foundation; either version 2 of the License, or |
---|
15 | * (at your option) any later version. |
---|
16 | * |
---|
17 | * libtrace is distributed in the hope that it will be useful, |
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | * GNU General Public License for more details. |
---|
21 | * |
---|
22 | * You should have received a copy of the GNU General Public License |
---|
23 | * along with libtrace; if not, write to the Free Software |
---|
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
25 | * |
---|
26 | * $Id: test-rtclient.c,v 1.2 2006/02/27 03:41:12 perry Exp $ |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | |
---|
31 | #include <stdio.h> |
---|
32 | #include <stdlib.h> |
---|
33 | #include <assert.h> |
---|
34 | #include <string.h> |
---|
35 | #include <sys/time.h> |
---|
36 | #include <sys/types.h> |
---|
37 | #include <time.h> |
---|
38 | |
---|
39 | #include <netinet/in.h> |
---|
40 | #include <netinet/in_systm.h> |
---|
41 | #include <netinet/tcp.h> |
---|
42 | #include <netinet/ip.h> |
---|
43 | #include <netinet/ip_icmp.h> |
---|
44 | #include <arpa/inet.h> |
---|
45 | #include <sys/socket.h> |
---|
46 | #include <string.h> |
---|
47 | #include "dagformat.h" |
---|
48 | #include "libtrace.h" |
---|
49 | |
---|
50 | char *lookup_out_uri(const char *type) { |
---|
51 | if (!strcmp(type,"erf")) |
---|
52 | return "erf:traces/100_packets.out.erf"; |
---|
53 | if (!strcmp(type,"pcap")) |
---|
54 | return "pcap:traces/100_packets.out.pcap"; |
---|
55 | if (!strcmp(type,"wtf")) |
---|
56 | return "wtf:traces/wed.out.wtf"; |
---|
57 | if (!strcmp(type,"duck")) |
---|
58 | return "duck:traces/100_packets.out.duck"; |
---|
59 | return "unknown"; |
---|
60 | } |
---|
61 | |
---|
62 | void iferr_out(libtrace_out_t *trace) |
---|
63 | { |
---|
64 | libtrace_err_t err = trace_get_err_output(trace); |
---|
65 | if (err.err_num==0) |
---|
66 | return; |
---|
67 | printf("Error: %s\n",err.problem); |
---|
68 | exit(1); |
---|
69 | } |
---|
70 | |
---|
71 | void iferr(libtrace_t *trace) |
---|
72 | { |
---|
73 | libtrace_err_t err = trace_get_err(trace); |
---|
74 | if (err.err_num==0) |
---|
75 | return; |
---|
76 | printf("Error: %s\n",err.problem); |
---|
77 | exit(1); |
---|
78 | } |
---|
79 | |
---|
80 | char buffer[] = { |
---|
81 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, /* Dest Mac */ |
---|
82 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x06, /* Src Mac */ |
---|
83 | 0x01, 0x01, /* Ethertype = Experimental */ |
---|
84 | 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, /* payload */ |
---|
85 | }; |
---|
86 | |
---|
87 | int main(int argc, char *argv[]) { |
---|
88 | libtrace_out_t *trace; |
---|
89 | libtrace_packet_t *packet; |
---|
90 | |
---|
91 | if (argc<2) { |
---|
92 | fprintf(stderr,"usage: %s type\n",argv[0]); |
---|
93 | return 1; |
---|
94 | } |
---|
95 | |
---|
96 | trace = trace_create_output(lookup_out_uri(argv[1])); |
---|
97 | iferr_out(trace); |
---|
98 | |
---|
99 | trace_start_output(trace); |
---|
100 | iferr_out(trace); |
---|
101 | |
---|
102 | packet=trace_create_packet(); |
---|
103 | |
---|
104 | trace_construct_packet(packet,TRACE_TYPE_ETH,buffer,sizeof(buffer)); |
---|
105 | |
---|
106 | if (trace_write_packet(trace,packet)==-1) { |
---|
107 | iferr_out(trace); |
---|
108 | } |
---|
109 | trace_destroy_packet(packet); |
---|
110 | trace_destroy_output(trace); |
---|
111 | return 0; |
---|
112 | } |
---|