[5afbb78] | 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"; |
---|
[7e94aee] | 55 | if (!strcmp(type,"pcapfile")) |
---|
| 56 | return "pcapfile:traces/100_packets.out.pcap"; |
---|
[5afbb78] | 57 | if (!strcmp(type,"wtf")) |
---|
| 58 | return "wtf:traces/wed.out.wtf"; |
---|
| 59 | if (!strcmp(type,"duck")) |
---|
| 60 | return "duck:traces/100_packets.out.duck"; |
---|
| 61 | return "unknown"; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void iferr_out(libtrace_out_t *trace) |
---|
| 65 | { |
---|
| 66 | libtrace_err_t err = trace_get_err_output(trace); |
---|
| 67 | if (err.err_num==0) |
---|
| 68 | return; |
---|
| 69 | printf("Error: %s\n",err.problem); |
---|
| 70 | exit(1); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void iferr(libtrace_t *trace) |
---|
| 74 | { |
---|
| 75 | libtrace_err_t err = trace_get_err(trace); |
---|
| 76 | if (err.err_num==0) |
---|
| 77 | return; |
---|
| 78 | printf("Error: %s\n",err.problem); |
---|
| 79 | exit(1); |
---|
| 80 | } |
---|
| 81 | |
---|
[428c837] | 82 | unsigned char buffer[] = { |
---|
[5afbb78] | 83 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, /* Dest Mac */ |
---|
| 84 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x06, /* Src Mac */ |
---|
| 85 | 0x01, 0x01, /* Ethertype = Experimental */ |
---|
| 86 | 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, /* payload */ |
---|
| 87 | }; |
---|
| 88 | |
---|
| 89 | int main(int argc, char *argv[]) { |
---|
| 90 | libtrace_out_t *trace; |
---|
| 91 | libtrace_packet_t *packet; |
---|
| 92 | |
---|
| 93 | if (argc<2) { |
---|
| 94 | fprintf(stderr,"usage: %s type\n",argv[0]); |
---|
| 95 | return 1; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | trace = trace_create_output(lookup_out_uri(argv[1])); |
---|
| 99 | iferr_out(trace); |
---|
| 100 | |
---|
| 101 | trace_start_output(trace); |
---|
| 102 | iferr_out(trace); |
---|
| 103 | |
---|
| 104 | packet=trace_create_packet(); |
---|
| 105 | |
---|
| 106 | trace_construct_packet(packet,TRACE_TYPE_ETH,buffer,sizeof(buffer)); |
---|
| 107 | |
---|
| 108 | if (trace_write_packet(trace,packet)==-1) { |
---|
| 109 | iferr_out(trace); |
---|
| 110 | } |
---|
| 111 | trace_destroy_packet(packet); |
---|
| 112 | trace_destroy_output(trace); |
---|
| 113 | return 0; |
---|
| 114 | } |
---|