Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00050 #ifndef LIBTRACE_INT_H
00051 #define LIBTRACE_INT_H
00052
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056
00057 #include "config.h"
00058 #include "common.h"
00059 #include "libtrace.h"
00060 #include "wandio.h"
00061
00062 #ifdef _MSC_VER
00063
00064 #pragma warning(disable:4996)
00065
00066 #pragma warning(disable:4142)
00067 #endif
00068
00069 #ifdef HAVE_INTTYPES_H
00070 # include <inttypes.h>
00071 #else
00072 # include "lt_inttypes.h"
00073 #endif
00074
00075 #ifdef HAVE_STDDEF_H
00076 # include <stddef.h>
00077 #else
00078 #ifndef WIN32
00079 # error "Can't find stddev.h -- do you define ptrdiff_t elsewhere?"
00080 #endif
00081 #endif
00082
00083
00084 #include "rt_protocol.h"
00085
00086
00087 #ifdef HAVE_NET_BPF_H
00088 # include <net/bpf.h>
00089 # define HAVE_BPF 1
00090 #else
00091 #ifdef HAVE_PCAP_BPF_H
00092 # include <pcap-bpf.h>
00093 # define HAVE_BPF 1
00094 #endif
00095 #endif
00096
00097 #ifdef HAVE_PCAP_H
00098 # include <pcap.h>
00099 # ifdef HAVE_PCAP_INT_H
00100 # include <pcap-int.h>
00101 # endif
00102 #endif
00103
00104 #ifdef HAVE_ZLIB_H
00105 # include <zlib.h>
00106 #endif
00107
00108 #ifndef HAVE_STRNDUP
00109 char *strndup(const char *s, size_t size);
00110 #endif
00111
00112 #ifndef HAVE_STRNCASECMP
00113 # ifndef HAVE__STRNICMP
00114
00115 int strncasecmp(const char *str1, const char *str2, size_t n);
00116 # else
00117 # define strncasecmp _strnicmp
00118 # endif
00119 #endif
00120
00121 #ifndef HAVE_SNPRINTF
00122 # ifndef HAVE_SPRINTF_S
00123
00124 int snprintf(char *str, size_t size, const char *format, ...);
00125 # else
00126 # define snprintf sprintf_s
00127 # endif
00128 #endif
00129
00130 #include "daglegacy.h"
00131
00132 #ifdef HAVE_DAG_API
00133 # include "dagnew.h"
00134 # include "dagapi.h"
00135 # if DAG_VERSION == 24
00136 # include <erftypes.h>
00137 # else
00138 # include <daginf.h>
00139 # endif
00140 # include "erftypes.h"
00141 #else
00142 # include "dagformat.h"
00143 #endif
00144
00145 #ifdef HAVE_LLVM
00146 #include "bpf-jit/bpf-jit.h"
00147 #endif
00148
00149
00150
00152 struct libtrace_event_status_t {
00154 libtrace_packet_t *packet;
00157 double tdelta;
00159 double trace_last_ts;
00161 int psize;
00164 bool waiting;
00165 };
00166
00170 struct libtrace_t {
00172 struct libtrace_format_t *format;
00174 struct libtrace_event_status_t event;
00176 void *format_data;
00179 struct libtrace_filter_t *filter;
00182 size_t snaplen;
00184 uint64_t accepted_packets;
00186 uint64_t filtered_packets;
00188 char *uridata;
00190 io_t *io;
00192 libtrace_err_t err;
00194 bool started;
00195 };
00196
00200 struct libtrace_out_t {
00202 struct libtrace_format_t *format;
00204 void *format_data;
00206 char *uridata;
00208 libtrace_err_t err;
00210 bool started;
00211 };
00212
00219 void trace_set_err(libtrace_t *trace, int errcode,const char *msg,...)
00220
00221 PRINTF(3,4);
00228 void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...)
00229 PRINTF(3,4);
00230
00235 void trace_clear_cache(libtrace_packet_t *packet);
00236
00265 int trace_prepare_packet(libtrace_t *trace, libtrace_packet_t *packet,
00266 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags);
00267
00269 enum {
00272 TRACE_PREP_OWN_BUFFER =1,
00273
00276 TRACE_PREP_DO_NOT_OWN_BUFFER =0
00277 };
00278
00280 typedef struct libtrace_sll_header_t {
00281 uint16_t pkttype;
00282 uint16_t hatype;
00283 uint16_t halen;
00284 unsigned char addr[8];
00285 uint16_t protocol;
00286 } libtrace_sll_header_t;
00287
00288
00289
00290
00292 #define TRACE_SLL_HOST 0
00293
00294 #define TRACE_SLL_BROADCAST 1
00295
00296 #define TRACE_SLL_MULTICAST 2
00297
00299 #define TRACE_SLL_OTHERHOST 3
00300
00301 #define TRACE_SLL_OUTGOING 4
00302
00303 #ifndef PF_RULESET_NAME_SIZE
00304 #define PF_RULESET_NAME_SIZE 16
00305 #endif
00306
00307 #ifndef IFNAMSIZ
00308 #define IFNAMSIZ 16
00309 #endif
00310
00311
00313 typedef struct libtrace_pflog_header_t {
00314 uint8_t length;
00315 sa_family_t af;
00316 uint8_t action;
00317 uint8_t reason;
00318 char ifname[IFNAMSIZ];
00319 char ruleset[PF_RULESET_NAME_SIZE];
00320 uint32_t rulenr;
00321 uint32_t subrulenr;
00322 uint8_t dir;
00323 uint8_t pad[3];
00324 } PACKED libtrace_pflog_header_t;
00325
00326
00327
00329
00330 struct libtrace_format_t {
00333 const char *name;
00335 const char *version;
00337 enum base_format_t type;
00338
00339
00347 int (*probe_filename)(const char *fname);
00348
00356 int (*probe_magic)(io_t *io);
00357
00363 int (*init_input)(libtrace_t *libtrace);
00364
00374 int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value);
00380 int (*start_input)(libtrace_t *libtrace);
00381
00388 int (*pause_input)(libtrace_t *libtrace);
00389
00395 int (*init_output)(libtrace_out_t *libtrace);
00396
00406 int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t option, void *value);
00407
00417 int (*start_output)(libtrace_out_t *libtrace);
00418
00427 int (*fin_input)(libtrace_t *libtrace);
00428
00434 int (*fin_output)(libtrace_out_t *libtrace);
00435
00449 int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet);
00450
00470 int (*prepare_packet)(libtrace_t *libtrace, libtrace_packet_t *packet,
00471 void *buffer, libtrace_rt_types_t rt_type,
00472 uint32_t flags);
00473
00479 void (*fin_packet)(libtrace_packet_t *packet);
00480
00487 int (*write_packet)(libtrace_out_t *libtrace, libtrace_packet_t *packet);
00493 libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
00494
00501 libtrace_direction_t (*get_direction)(const libtrace_packet_t *packet);
00502
00513 libtrace_direction_t (*set_direction)(libtrace_packet_t *packet, libtrace_direction_t direction);
00514
00529 uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
00530
00544 struct timeval (*get_timeval)(const libtrace_packet_t *packet);
00545
00559 struct timespec (*get_timespec)(const libtrace_packet_t *packet);
00560
00575 double (*get_seconds)(const libtrace_packet_t *packet);
00576
00597 int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
00618 int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
00619
00641 int (*seek_seconds)(libtrace_t *trace, double seconds);
00642
00653 int (*get_capture_length)(const libtrace_packet_t *packet);
00654
00665 int (*get_wire_length)(const libtrace_packet_t *packet);
00666
00677 int (*get_framing_length)(const libtrace_packet_t *packet);
00678
00690 size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
00699 uint64_t (*get_received_packets)(libtrace_t *trace);
00700
00708 uint64_t (*get_filtered_packets)(libtrace_t *trace);
00709
00717 uint64_t (*get_dropped_packets)(libtrace_t *trace);
00718
00730 uint64_t (*get_captured_packets)(libtrace_t *trace);
00731
00738 int (*get_fd)(const libtrace_t *trace);
00739
00753 struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet);
00754
00756 void (*help)(void);
00757
00760 struct libtrace_format_t *next;
00761 };
00762
00764
00765
00769 extern int libtrace_halt;
00770
00775 void register_format(struct libtrace_format_t *format);
00776
00783 libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype);
00784
00790 libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype);
00791
00798 libtrace_dlt_t libtrace_to_pcap_linktype(libtrace_linktype_t type);
00799
00806 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type);
00807
00813 libtrace_dlt_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type);
00814
00821 libtrace_linktype_t erf_type_to_libtrace(uint8_t erf);
00822
00829 uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype);
00830
00837 libtrace_linktype_t arphrd_type_to_libtrace(unsigned int arphrd);
00838
00845 unsigned int libtrace_to_arphrd_type(libtrace_linktype_t type);
00846
00856 void promote_packet(libtrace_packet_t *packet);
00857
00867 bool demote_packet(libtrace_packet_t *packet);
00868
00890 void *trace_get_payload_from_linux_sll(const void *link,
00891 uint16_t *arphrd_type,
00892 uint16_t *next_header,
00893 uint32_t *remaining);
00894
00915 DLLEXPORT void *trace_get_payload_from_atm(void *link, uint8_t *type,
00916 uint32_t *remaining);
00917
00924 uint64_t byteswap64(uint64_t num);
00925
00932 uint32_t byteswap32(uint32_t num);
00933
00940 uint16_t byteswap16(uint16_t num);
00941
00947 #if BYTE_ORDER == BIG_ENDIAN
00948 #define bswap_host_to_be64(num) ((uint64_t)(num))
00949 #define bswap_host_to_le64(num) byteswap64(num)
00950 #define bswap_host_to_be32(num) ((uint32_t)(num))
00951 #define bswap_host_to_le32(num) byteswap32(num)
00952 #define bswap_host_to_be16(num) ((uint16_t)(num))
00953 #define bswap_host_to_le16(num) byteswap16(num)
00954
00955 #define bswap_be_to_host64(num) ((uint64_t)(num))
00956 #define bswap_le_to_host64(num) byteswap64(num)
00957 #define bswap_be_to_host32(num) ((uint32_t)(num))
00958 #define bswap_le_to_host32(num) byteswap32(num)
00959 #define bswap_be_to_host16(num) ((uint16_t)(num))
00960 #define bswap_le_to_host16(num) byteswap16(num)
00961
00962
00963
00964
00965 #elif BYTE_ORDER == LITTLE_ENDIAN
00966 #define bswap_host_to_be64(num) (byteswap64(num))
00967 #define bswap_host_to_le64(num) ((uint64_t)(num))
00968 #define bswap_host_to_be32(num) (htonl(num))
00969 #define bswap_host_to_le32(num) ((uint32_t)(num))
00970 #define bswap_host_to_be16(num) (htons(num))
00971 #define bswap_host_to_le16(num) ((uint16_t)(num))
00972
00973 #define bswap_be_to_host64(num) (byteswap64(num))
00974 #define bswap_le_to_host64(num) ((uint64_t)(num))
00975 #define bswap_be_to_host32(num) (ntohl(num))
00976 #define bswap_le_to_host32(num) ((uint32_t)(num))
00977 #define bswap_be_to_host16(num) (ntohs(num))
00978 #define bswap_le_to_host16(num) ((uint16_t)(num))
00979
00980 #else
00981 #error "Unknown byte order"
00982 #endif
00983
00985 #ifdef HAVE_BPF
00986
00987
00988
00989
00990
00991
00993 struct libtrace_filter_t {
00994 struct bpf_program filter;
00995 char * filterstring;
00996 int flag;
00997 struct bpf_jit_t *jitfilter;
00998 };
00999 #else
01000
01002 struct libtrace_filter_t {};
01003 #endif
01004
01006 typedef struct libtrace_pcapfile_pkt_hdr_t {
01007 uint32_t ts_sec;
01008 uint32_t ts_usec;
01009 uint32_t caplen;
01010 uint32_t wirelen;
01011 } libtrace_pcapfile_pkt_hdr_t;
01012
01013 #ifdef HAVE_DAG
01014
01015 void dag_constructor(void);
01016 #endif
01017
01018 void erf_constructor(void);
01020 void tsh_constructor(void);
01022 void legacy_constructor(void);
01024 void linuxnative_constructor(void);
01026 void pcap_constructor(void);
01028 void pcapfile_constructor(void);
01030 void rt_constructor(void);
01032 void duck_constructor(void);
01034 void atmhdr_constructor(void);
01035 #ifdef HAVE_BPF
01036
01037 void bpf_constructor(void);
01038 #endif
01039
01051 bool trace_get_wireless_flags(void *link, libtrace_linktype_t linktype, uint8_t *flags);
01052 #define TRACE_RADIOTAP_F_FCS 0x10
01053
01054 #ifdef __cplusplus
01055 }
01056 #endif
01057
01058 #endif