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

libtrace_int.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of libtrace
00003  *
00004  * Copyright (c) 2007 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 1266 2007-09-05 05:46:41Z 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         int psize;
00122         double tdelta;
00123         double trace_last_ts;
00124 };
00125 
00129 struct libtrace_t {
00130         struct libtrace_format_t *format; 
00131         void *format_data; 
00132         bool started;                   
00133         libtrace_err_t err;             
00134         struct libtrace_event_status_t event;   
00135         char *uridata;                  
00136         struct libtrace_filter_t *filter; 
00139         size_t snaplen;         
00142 };
00143 
00147 struct libtrace_out_t {
00148         struct libtrace_format_t *format;       
00149         void *format_data;              
00150         bool started;                   
00151         libtrace_err_t err;             
00152         char *uridata;                  
00153 };
00154 
00155 void trace_set_err(libtrace_t *trace, int errcode,const char *msg,...) 
00156                                                                 PRINTF(3,4);
00157 void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...)
00158                                                                 PRINTF(3,4);
00159 
00160 typedef struct libtrace_sll_header_t {
00161         uint16_t pkttype;               /* packet type */
00162         uint16_t hatype;                /* link-layer address type */
00163         uint16_t halen;                 /* link-layer address length */
00164         char addr[8];                   /* link-layer address */
00165         uint16_t protocol;              /* protocol */
00166 } libtrace_sll_header_t;
00167 
00168 #define TRACE_SLL_HOST          0
00169 #define TRACE_SLL_BROADCAST     1
00170 #define TRACE_SLL_MULTICAST     2
00171 #define TRACE_SLL_OTHERHOST     3
00172 #define TRACE_SLL_OUTGOING      4
00173 
00174 #ifndef PF_RULESET_NAME_SIZE
00175 #define PF_RULESET_NAME_SIZE 16
00176 #endif
00177 
00178 #ifndef IFNAMSIZ
00179 #define IFNAMSIZ 16
00180 #endif
00181 
00182 typedef struct libtrace_pflog_header_t {
00183         uint8_t    length;
00184         sa_family_t   af;
00185         uint8_t    action;
00186         uint8_t    reason;
00187         char       ifname[IFNAMSIZ];
00188         char       ruleset[PF_RULESET_NAME_SIZE];
00189         uint32_t   rulenr;
00190         uint32_t   subrulenr;
00191         uint8_t    dir;
00192         uint8_t    pad[3];
00193 } libtrace_pflog_header_t;
00194 
00195 
00196 
00198 /* all of these should return -1, or NULL on failure */
00199 struct libtrace_format_t {
00201         const char *name;
00203         const char *version;
00205         enum base_format_t type;
00208         int (*init_input)(libtrace_t *libtrace);
00210         int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value);
00212         int (*start_input)(libtrace_t *libtrace);
00214         int (*pause_input)(libtrace_t *libtrace);
00218         int (*init_output)(libtrace_out_t *libtrace);
00220         int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t option, void *);
00225         int (*start_output)(libtrace_out_t *libtrace);
00231         int (*fin_input)(libtrace_t *libtrace);
00233         int (*fin_output)(libtrace_out_t *libtrace);
00239         int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet);
00244         void (*fin_packet)(libtrace_packet_t *packet);
00248         int (*write_packet)(libtrace_out_t *libtrace, libtrace_packet_t *packet);
00252         libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
00256         libtrace_direction_t (*get_direction)(const libtrace_packet_t *packet);
00260         libtrace_direction_t (*set_direction)(libtrace_packet_t *packet, libtrace_direction_t direction);
00268         uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
00276         struct timeval (*get_timeval)(const libtrace_packet_t *packet);
00284         double (*get_seconds)(const libtrace_packet_t *packet);
00294         int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
00304         int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
00314         int (*seek_seconds)(libtrace_t *trace, double seconds);
00321         int (*get_capture_length)(const libtrace_packet_t *packet);
00328         int (*get_wire_length)(const libtrace_packet_t *packet);
00336         int (*get_framing_length)(const libtrace_packet_t *packet);
00341         size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
00347         int (*get_fd)(const libtrace_t *trace);
00351         struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet);        
00353         void (*help)(void);
00355         struct libtrace_format_t *next;
00356 };
00357 
00358 extern struct libtrace_format_t *form;
00359 
00360 void register_format(struct libtrace_format_t *format);
00361 
00362 libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype);
00363 libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype);
00364 libtrace_dlt_t libtrace_to_pcap_linktype(libtrace_linktype_t type);
00365 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type);
00366 libtrace_dlt_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type);
00367 libtrace_linktype_t erf_type_to_libtrace(uint8_t erf);
00368 uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype);
00369 libtrace_linktype_t arphrd_type_to_libtrace(unsigned int);
00370 unsigned int libtrace_to_arphrd_type(libtrace_linktype_t);
00371 
00372 void promote_packet(libtrace_packet_t *packet);
00373 bool demote_packet(libtrace_packet_t *packet);
00374 
00375 void *trace_get_payload_from_linux_sll(void *, uint16_t *, uint32_t *);
00376 void *trace_get_payload_from_pos(void *, uint16_t *, uint32_t *);
00377 DLLEXPORT void *trace_get_payload_from_atm(void *, uint8_t *, uint32_t *);
00378 
00379 uint64_t byteswap64(uint64_t num);
00380 uint32_t byteswap32(uint32_t num);
00381 uint16_t byteswap16(uint16_t num);
00382 
00383 /* Because some traces/protocols are defined as
00384  * being "big endian" or "little endian" we have
00385  * this series of macros.
00386  */
00387 #if BYTE_ORDER == BIG_ENDIAN
00388 #define bswap_host_to_be64(num) ((uint64_t)(num))
00389 #define bswap_host_to_le64(num) byteswap64(num)
00390 #define bswap_host_to_be32(num) ((uint32_t)(num))
00391 #define bswap_host_to_le32(num) byteswap32(num)
00392 #define bswap_host_to_be16(num) ((uint16_t)(num))
00393 #define bswap_host_to_le16(num) byteswap16(num)
00394 
00395 #define bswap_be_to_host64(num) ((uint64_t)(num))
00396 #define bswap_le_to_host64(num) byteswap64(num)
00397 #define bswap_be_to_host32(num) ((uint32_t)(num))
00398 #define bswap_le_to_host32(num) byteswap32(num)
00399 #define bswap_be_to_host16(num) ((uint16_t)(num))
00400 #define bswap_le_to_host16(num) byteswap16(num)
00401 
00402 /* We use ntoh*() here, because the compiler may
00403  * attempt to optimise it
00404  */
00405 #elif BYTE_ORDER == LITTLE_ENDIAN
00406 #define bswap_host_to_be64(num) (byteswap64(num))
00407 #define bswap_host_to_le64(num) ((uint64_t)(num))
00408 #define bswap_host_to_be32(num) (htonl(num))
00409 #define bswap_host_to_le32(num) ((uint32_t)(num))
00410 #define bswap_host_to_be16(num) (htons(num))
00411 #define bswap_host_to_le16(num) ((uint16_t)(num))
00412 
00413 #define bswap_be_to_host64(num) (byteswap64(num))
00414 #define bswap_le_to_host64(num) ((uint64_t)(num))
00415 #define bswap_be_to_host32(num) (ntohl(num))
00416 #define bswap_le_to_host32(num) ((uint32_t)(num))
00417 #define bswap_be_to_host16(num) (ntohs(num))
00418 #define bswap_le_to_host16(num) ((uint16_t)(num))
00419 
00420 #else
00421 #error "Unknown byte order"
00422 #endif
00423 
00424 #ifdef HAVE_BPF
00425 /* A type encapsulating a bpf filter
00426  * This type covers the compiled bpf filter, as well as the original filter
00427  * string
00428  *
00429  */
00430 struct libtrace_filter_t {
00431         struct bpf_program filter;
00432         int flag;
00433         char * filterstring;
00434 };
00435 #else
00436 struct libtrace_filter_t {};
00437 #endif
00438 
00441 typedef struct libtrace_pcapfile_pkt_hdr_t {
00442         uint32_t ts_sec;
00443         uint32_t ts_usec;
00444         uint32_t caplen;
00445         uint32_t wirelen;
00446 } libtrace_pcapfile_pkt_hdr_t;
00447 
00448 #ifdef HAVE_DAG
00449 void dag_constructor(void);
00450 #endif
00451 void erf_constructor(void);
00452 void tsh_constructor(void);
00453 void legacy_constructor(void);
00454 void linuxnative_constructor(void);
00455 void pcap_constructor(void);
00456 void pcapfile_constructor(void);
00457 void rt_constructor(void);
00458 void duck_constructor(void);
00459 void atmhdr_constructor(void);
00460 #ifdef HAVE_BPF
00461 void bpf_constructor(void);
00462 #endif
00463 
00464 /* Used internally by get_wire_length() methods */
00465 bool trace_get_wireless_flags(void *link, libtrace_linktype_t linktype, uint8_t *flags);
00466 #define TRACE_RADIOTAP_F_FCS 0x10
00467         
00468 #ifdef __cplusplus
00469 }
00470 #endif
00471 
00472 #endif /* LIBTRACE_INT_H */

Generated on Wed Sep 5 17:48:05 2007 for WAND Trace processing by  doxygen 1.4.2