Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

libtrace_int.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of libtrace
00003  *
00004  * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand.
00005  * Authors: Daniel Lawson 
00006  *          Perry Lorier 
00007  *          
00008  * All rights reserved.
00009  *
00010  * This code has been developed by the University of Waikato WAND 
00011  * research group. For further information please see http://www.wand.net.nz/
00012  *
00013  * libtrace is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * libtrace is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with libtrace; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  * $Id: libtrace_int.h 1319 2008-01-02 21:10:07Z perry $
00028  *
00029  */
00032 #ifndef LIBTRACE_INT_H
00033 #define LIBTRACE_INT_H
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 #include "common.h"
00040 #include "config.h"
00041 #include "libtrace.h"
00042 
00043 #ifdef _MSC_VER
00044 // warning: deprecated function
00045 #pragma warning(disable:4996)
00046 // warning: benign redefinitions of types
00047 #pragma warning(disable:4142)
00048 #endif
00049 
00050 #ifdef HAVE_INTTYPES_H
00051 # include <inttypes.h>
00052 #else
00053 # include "lt_inttypes.h"
00054 #endif
00055 
00056 #ifdef HAVE_STDDEF_H
00057 # include <stddef.h>
00058 #else
00059 #ifndef WIN32
00060 # error "Can't find stddev.h -- do you define ptrdiff_t elsewhere?"
00061 #endif
00062 #endif
00063 
00064 
00065 #include "rt_protocol.h"
00066         
00067 /* Prefer net/bpf.h over pcap-bpf.h for format_bpf.c on MacOS */
00068 #ifdef HAVE_NET_BPF_H
00069 #    include <net/bpf.h>
00070 #    define HAVE_BPF 1
00071 #else
00072 #ifdef HAVE_PCAP_BPF_H
00073 #  include <pcap-bpf.h>
00074 #  define HAVE_BPF 1
00075 #endif
00076 #endif
00077 
00078 #ifdef HAVE_PCAP_H
00079 #  include <pcap.h>
00080 #  ifdef HAVE_PCAP_INT_H
00081 #    include <pcap-int.h>
00082 #  endif
00083 #endif 
00084 
00085 #ifdef HAVE_ZLIB_H
00086 #  include <zlib.h>
00087 #endif
00088 
00089 #ifndef HAVE_STRNCASECMP
00090 # ifndef HAVE__STRNICMP
00091 int strncasecmp(const char *str1, const char *str2, size_t n);
00092 # else
00093 # define strncasecmp _strnicmp
00094 # endif
00095 #endif
00096 
00097 #ifndef HAVE_SNPRINTF
00098 # ifndef HAVE_SPRINTF_S
00099 int snprintf(char *str, size_t size, const char *format, ...);
00100 # else
00101 # define snprintf sprintf_s
00102 # endif 
00103 #endif
00104 
00105 #include "daglegacy.h"
00106         
00107 #ifdef HAVE_DAG_API
00108 #  include "dagnew.h"
00109 #  include "dagapi.h"
00110 #       if DAG_VERSION == 25
00111 #               include <daginf.h>
00112 #       endif
00113 #else
00114 #  include "dagformat.h"
00115 #endif
00116 
00117 #define RP_BUFSIZE 65536U
00118 
00119 struct libtrace_event_status_t {
00120         libtrace_packet_t *packet;
00121         double tdelta;
00122         double trace_last_ts;
00123         int psize;
00124 };
00125 
00129 struct libtrace_t {
00130         struct libtrace_format_t *format; 
00131         struct libtrace_event_status_t event;   
00132         void *format_data;              
00133         struct libtrace_filter_t *filter; 
00136         size_t snaplen;                 
00139         uint64_t accepted_packets;      
00142         uint64_t filtered_packets;      
00145         char *uridata;                  
00147         libtrace_err_t err;             
00148         bool started;                   
00149 };
00150 
00154 struct libtrace_out_t {
00155         struct libtrace_format_t *format;       
00156         void *format_data;              
00157         char *uridata;                  
00158         libtrace_err_t err;             
00159         bool started;                   
00160 };
00161 
00162 void trace_set_err(libtrace_t *trace, int errcode,const char *msg,...) 
00163                                                                 PRINTF(3,4);
00164 void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...)
00165                                                                 PRINTF(3,4);
00166 
00167 typedef struct libtrace_sll_header_t {
00168         uint16_t pkttype;               /* packet type */
00169         uint16_t hatype;                /* link-layer address type */
00170         uint16_t halen;                 /* link-layer address length */
00171         char addr[8];                   /* link-layer address */
00172         uint16_t protocol;              /* protocol */
00173 } libtrace_sll_header_t;
00174 
00175 #define TRACE_SLL_HOST          0
00176 #define TRACE_SLL_BROADCAST     1
00177 #define TRACE_SLL_MULTICAST     2
00178 #define TRACE_SLL_OTHERHOST     3
00179 #define TRACE_SLL_OUTGOING      4
00180 
00181 #ifndef PF_RULESET_NAME_SIZE
00182 #define PF_RULESET_NAME_SIZE 16
00183 #endif
00184 
00185 #ifndef IFNAMSIZ
00186 #define IFNAMSIZ 16
00187 #endif
00188 
00189 typedef struct libtrace_pflog_header_t {
00190         uint8_t    length;
00191         sa_family_t   af;
00192         uint8_t    action;
00193         uint8_t    reason;
00194         char       ifname[IFNAMSIZ];
00195         char       ruleset[PF_RULESET_NAME_SIZE];
00196         uint32_t   rulenr;
00197         uint32_t   subrulenr;
00198         uint8_t    dir;
00199         uint8_t    pad[3];
00200 } PACKED libtrace_pflog_header_t;
00201 
00202 
00203 
00205 /* all of these should return -1, or NULL on failure */
00206 struct libtrace_format_t {
00208         const char *name;
00210         const char *version;
00212         enum base_format_t type;
00215         int (*init_input)(libtrace_t *libtrace);
00217         int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value);
00219         int (*start_input)(libtrace_t *libtrace);
00221         int (*pause_input)(libtrace_t *libtrace);
00225         int (*init_output)(libtrace_out_t *libtrace);
00227         int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t option, void *);
00232         int (*start_output)(libtrace_out_t *libtrace);
00238         int (*fin_input)(libtrace_t *libtrace);
00240         int (*fin_output)(libtrace_out_t *libtrace);
00246         int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet);
00251         void (*fin_packet)(libtrace_packet_t *packet);
00255         int (*write_packet)(libtrace_out_t *libtrace, libtrace_packet_t *packet);
00259         libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
00263         libtrace_direction_t (*get_direction)(const libtrace_packet_t *packet);
00267         libtrace_direction_t (*set_direction)(libtrace_packet_t *packet, libtrace_direction_t direction);
00275         uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
00283         struct timeval (*get_timeval)(const libtrace_packet_t *packet);
00291         double (*get_seconds)(const libtrace_packet_t *packet);
00301         int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
00311         int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
00321         int (*seek_seconds)(libtrace_t *trace, double seconds);
00328         int (*get_capture_length)(const libtrace_packet_t *packet);
00335         int (*get_wire_length)(const libtrace_packet_t *packet);
00343         int (*get_framing_length)(const libtrace_packet_t *packet);
00348         size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
00351         uint64_t (*get_received_packets)(libtrace_t *trace);
00354         uint64_t (*get_filtered_packets)(libtrace_t *trace);
00356         uint64_t (*get_dropped_packets)(libtrace_t *trace);
00359         uint64_t (*get_captured_packets)(libtrace_t *trace);
00365         int (*get_fd)(const libtrace_t *trace);
00369         struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet);        
00371         void (*help)(void);
00373         struct libtrace_format_t *next;
00374 };
00375 
00376 extern struct libtrace_format_t *form;
00377 
00378 void register_format(struct libtrace_format_t *format);
00379 
00380 libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype);
00381 libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype);
00382 libtrace_dlt_t libtrace_to_pcap_linktype(libtrace_linktype_t type);
00383 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type);
00384 libtrace_dlt_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type);
00385 libtrace_linktype_t erf_type_to_libtrace(uint8_t erf);
00386 uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype);
00387 libtrace_linktype_t arphrd_type_to_libtrace(unsigned int);
00388 unsigned int libtrace_to_arphrd_type(libtrace_linktype_t);
00389 
00390 void promote_packet(libtrace_packet_t *packet);
00391 bool demote_packet(libtrace_packet_t *packet);
00392 
00393 void *trace_get_payload_from_linux_sll(const void *, uint16_t *, uint32_t *);
00394 void *trace_get_payload_from_pos(void *, uint16_t *, uint32_t *);
00395 DLLEXPORT void *trace_get_payload_from_atm(void *, uint8_t *, uint32_t *);
00396 
00397 uint64_t byteswap64(uint64_t num);
00398 uint32_t byteswap32(uint32_t num);
00399 uint16_t byteswap16(uint16_t num);
00400 
00401 /* Because some traces/protocols are defined as
00402  * being "big endian" or "little endian" we have
00403  * this series of macros.
00404  */
00405 #if BYTE_ORDER == BIG_ENDIAN
00406 #define bswap_host_to_be64(num) ((uint64_t)(num))
00407 #define bswap_host_to_le64(num) byteswap64(num)
00408 #define bswap_host_to_be32(num) ((uint32_t)(num))
00409 #define bswap_host_to_le32(num) byteswap32(num)
00410 #define bswap_host_to_be16(num) ((uint16_t)(num))
00411 #define bswap_host_to_le16(num) byteswap16(num)
00412 
00413 #define bswap_be_to_host64(num) ((uint64_t)(num))
00414 #define bswap_le_to_host64(num) byteswap64(num)
00415 #define bswap_be_to_host32(num) ((uint32_t)(num))
00416 #define bswap_le_to_host32(num) byteswap32(num)
00417 #define bswap_be_to_host16(num) ((uint16_t)(num))
00418 #define bswap_le_to_host16(num) byteswap16(num)
00419 
00420 /* We use ntoh*() here, because the compiler may
00421  * attempt to optimise it
00422  */
00423 #elif BYTE_ORDER == LITTLE_ENDIAN
00424 #define bswap_host_to_be64(num) (byteswap64(num))
00425 #define bswap_host_to_le64(num) ((uint64_t)(num))
00426 #define bswap_host_to_be32(num) (htonl(num))
00427 #define bswap_host_to_le32(num) ((uint32_t)(num))
00428 #define bswap_host_to_be16(num) (htons(num))
00429 #define bswap_host_to_le16(num) ((uint16_t)(num))
00430 
00431 #define bswap_be_to_host64(num) (byteswap64(num))
00432 #define bswap_le_to_host64(num) ((uint64_t)(num))
00433 #define bswap_be_to_host32(num) (ntohl(num))
00434 #define bswap_le_to_host32(num) ((uint32_t)(num))
00435 #define bswap_be_to_host16(num) (ntohs(num))
00436 #define bswap_le_to_host16(num) ((uint16_t)(num))
00437 
00438 #else
00439 #error "Unknown byte order"
00440 #endif
00441 
00442 #ifdef HAVE_BPF
00443 /* A type encapsulating a bpf filter
00444  * This type covers the compiled bpf filter, as well as the original filter
00445  * string
00446  *
00447  */
00448 struct libtrace_filter_t {
00449         struct bpf_program filter;
00450         char * filterstring;
00451         int flag;
00452 };
00453 #else
00454 struct libtrace_filter_t {};
00455 #endif
00456 
00459 typedef struct libtrace_pcapfile_pkt_hdr_t {
00460         uint32_t ts_sec;
00461         uint32_t ts_usec;
00462         uint32_t caplen;
00463         uint32_t wirelen;
00464 } libtrace_pcapfile_pkt_hdr_t;
00465 
00466 #ifdef HAVE_DAG
00467 void dag_constructor(void);
00468 #endif
00469 void erf_constructor(void);
00470 void tsh_constructor(void);
00471 void legacy_constructor(void);
00472 void linuxnative_constructor(void);
00473 void pcap_constructor(void);
00474 void pcapfile_constructor(void);
00475 void rt_constructor(void);
00476 void duck_constructor(void);
00477 void atmhdr_constructor(void);
00478 #ifdef HAVE_BPF
00479 void bpf_constructor(void);
00480 #endif
00481 
00482 /* Used internally by get_wire_length() methods */
00483 bool trace_get_wireless_flags(void *link, libtrace_linktype_t linktype, uint8_t *flags);
00484 #define TRACE_RADIOTAP_F_FCS 0x10
00485         
00486 #ifdef __cplusplus
00487 }
00488 #endif
00489 
00490 #endif /* LIBTRACE_INT_H */

Generated on Thu Jan 3 10:28:47 2008 for WAND Trace processing by  doxygen 1.4.2