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
00279
00280 #ifndef PF_RULESET_NAME_SIZE
00281 #define PF_RULESET_NAME_SIZE 16
00282 #endif
00283
00284 #ifndef IFNAMSIZ
00285 #define IFNAMSIZ 16
00286 #endif
00287
00288
00290 typedef struct libtrace_pflog_header_t {
00291 uint8_t length;
00292 sa_family_t af;
00293 uint8_t action;
00294 uint8_t reason;
00295 char ifname[IFNAMSIZ];
00296 char ruleset[PF_RULESET_NAME_SIZE];
00297 uint32_t rulenr;
00298 uint32_t subrulenr;
00299 uint8_t dir;
00300 uint8_t pad[3];
00301 } PACKED libtrace_pflog_header_t;
00302
00303
00304
00306
00307 struct libtrace_format_t {
00310 const char *name;
00312 const char *version;
00314 enum base_format_t type;
00315
00316
00324 int (*probe_filename)(const char *fname);
00325
00333 int (*probe_magic)(io_t *io);
00334
00340 int (*init_input)(libtrace_t *libtrace);
00341
00351 int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value);
00357 int (*start_input)(libtrace_t *libtrace);
00358
00365 int (*pause_input)(libtrace_t *libtrace);
00366
00372 int (*init_output)(libtrace_out_t *libtrace);
00373
00383 int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t option, void *value);
00384
00394 int (*start_output)(libtrace_out_t *libtrace);
00395
00404 int (*fin_input)(libtrace_t *libtrace);
00405
00411 int (*fin_output)(libtrace_out_t *libtrace);
00412
00426 int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet);
00427
00447 int (*prepare_packet)(libtrace_t *libtrace, libtrace_packet_t *packet,
00448 void *buffer, libtrace_rt_types_t rt_type,
00449 uint32_t flags);
00450
00456 void (*fin_packet)(libtrace_packet_t *packet);
00457
00464 int (*write_packet)(libtrace_out_t *libtrace, libtrace_packet_t *packet);
00470 libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
00471
00478 libtrace_direction_t (*get_direction)(const libtrace_packet_t *packet);
00479
00490 libtrace_direction_t (*set_direction)(libtrace_packet_t *packet, libtrace_direction_t direction);
00491
00506 uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
00507
00521 struct timeval (*get_timeval)(const libtrace_packet_t *packet);
00522
00536 struct timespec (*get_timespec)(const libtrace_packet_t *packet);
00537
00552 double (*get_seconds)(const libtrace_packet_t *packet);
00553
00574 int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
00595 int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
00596
00618 int (*seek_seconds)(libtrace_t *trace, double seconds);
00619
00630 int (*get_capture_length)(const libtrace_packet_t *packet);
00631
00642 int (*get_wire_length)(const libtrace_packet_t *packet);
00643
00654 int (*get_framing_length)(const libtrace_packet_t *packet);
00655
00667 size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
00676 uint64_t (*get_received_packets)(libtrace_t *trace);
00677
00685 uint64_t (*get_filtered_packets)(libtrace_t *trace);
00686
00694 uint64_t (*get_dropped_packets)(libtrace_t *trace);
00695
00707 uint64_t (*get_captured_packets)(libtrace_t *trace);
00708
00715 int (*get_fd)(const libtrace_t *trace);
00716
00730 struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet);
00731
00733 void (*help)(void);
00734
00737 struct libtrace_format_t *next;
00738 };
00739
00741
00742
00746 extern int libtrace_halt;
00747
00752 void register_format(struct libtrace_format_t *format);
00753
00760 libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype);
00761
00767 libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype);
00768
00775 libtrace_dlt_t libtrace_to_pcap_linktype(libtrace_linktype_t type);
00776
00783 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type);
00784
00790 libtrace_dlt_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type);
00791
00798 libtrace_linktype_t erf_type_to_libtrace(uint8_t erf);
00799
00806 uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype);
00807
00814 libtrace_linktype_t arphrd_type_to_libtrace(unsigned int arphrd);
00815
00822 unsigned int libtrace_to_arphrd_type(libtrace_linktype_t type);
00823
00833 void promote_packet(libtrace_packet_t *packet);
00834
00844 bool demote_packet(libtrace_packet_t *packet);
00845
00867 void *trace_get_payload_from_linux_sll(const void *link,
00868 uint16_t *arphrd_type,
00869 uint16_t *next_header,
00870 uint32_t *remaining);
00871
00892 DLLEXPORT void *trace_get_payload_from_atm(void *link, uint8_t *type,
00893 uint32_t *remaining);
00894
00901 uint64_t byteswap64(uint64_t num);
00902
00909 uint32_t byteswap32(uint32_t num);
00910
00917 uint16_t byteswap16(uint16_t num);
00918
00924 #if BYTE_ORDER == BIG_ENDIAN
00925 #define bswap_host_to_be64(num) ((uint64_t)(num))
00926 #define bswap_host_to_le64(num) byteswap64(num)
00927 #define bswap_host_to_be32(num) ((uint32_t)(num))
00928 #define bswap_host_to_le32(num) byteswap32(num)
00929 #define bswap_host_to_be16(num) ((uint16_t)(num))
00930 #define bswap_host_to_le16(num) byteswap16(num)
00931
00932 #define bswap_be_to_host64(num) ((uint64_t)(num))
00933 #define bswap_le_to_host64(num) byteswap64(num)
00934 #define bswap_be_to_host32(num) ((uint32_t)(num))
00935 #define bswap_le_to_host32(num) byteswap32(num)
00936 #define bswap_be_to_host16(num) ((uint16_t)(num))
00937 #define bswap_le_to_host16(num) byteswap16(num)
00938
00939
00940
00941
00942 #elif BYTE_ORDER == LITTLE_ENDIAN
00943 #define bswap_host_to_be64(num) (byteswap64(num))
00944 #define bswap_host_to_le64(num) ((uint64_t)(num))
00945 #define bswap_host_to_be32(num) (htonl(num))
00946 #define bswap_host_to_le32(num) ((uint32_t)(num))
00947 #define bswap_host_to_be16(num) (htons(num))
00948 #define bswap_host_to_le16(num) ((uint16_t)(num))
00949
00950 #define bswap_be_to_host64(num) (byteswap64(num))
00951 #define bswap_le_to_host64(num) ((uint64_t)(num))
00952 #define bswap_be_to_host32(num) (ntohl(num))
00953 #define bswap_le_to_host32(num) ((uint32_t)(num))
00954 #define bswap_be_to_host16(num) (ntohs(num))
00955 #define bswap_le_to_host16(num) ((uint16_t)(num))
00956
00957 #else
00958 #error "Unknown byte order"
00959 #endif
00960
00962 #ifdef HAVE_BPF
00963
00964
00965
00966
00967
00968
00970 struct libtrace_filter_t {
00971 struct bpf_program filter;
00972 char * filterstring;
00973 int flag;
00974 struct bpf_jit_t *jitfilter;
00975 };
00976 #else
00977
00979 struct libtrace_filter_t {};
00980 #endif
00981
00983 typedef struct libtrace_pcapfile_pkt_hdr_t {
00984 uint32_t ts_sec;
00985 uint32_t ts_usec;
00986 uint32_t caplen;
00987 uint32_t wirelen;
00988 } libtrace_pcapfile_pkt_hdr_t;
00989
00990 #ifdef HAVE_DAG
00991
00992 void dag_constructor(void);
00993 #endif
00994
00995 void erf_constructor(void);
00997 void tsh_constructor(void);
00999 void legacy_constructor(void);
01001 void linuxnative_constructor(void);
01003 void pcap_constructor(void);
01005 void pcapfile_constructor(void);
01007 void rt_constructor(void);
01009 void duck_constructor(void);
01011 void atmhdr_constructor(void);
01012 #ifdef HAVE_BPF
01013
01014 void bpf_constructor(void);
01015 #endif
01016
01028 bool trace_get_wireless_flags(void *link, libtrace_linktype_t linktype, uint8_t *flags);
01029 #define TRACE_RADIOTAP_F_FCS 0x10
01030
01031 #ifdef __cplusplus
01032 }
01033 #endif
01034
01035 #endif