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
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
00045 #pragma warning(disable:4996)
00046
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 #ifdef HAVE_PCAP_BPF_H
00068 # include <pcap-bpf.h>
00069 # define HAVE_BPF 1
00070 #else
00071 # ifdef HAVE_NET_BPF_H
00072 # include <net/bpf.h>
00073 # define HAVE_BPF 1
00074 # endif
00075 #endif
00076
00077 #ifdef HAVE_PCAP_H
00078 # include <pcap.h>
00079 # ifdef HAVE_PCAP_INT_H
00080 # include <pcap-int.h>
00081 # endif
00082 #endif
00083
00084 #ifdef HAVE_ZLIB_H
00085 # include <zlib.h>
00086 #endif
00087
00088 #ifndef HAVE_STRNCASECMP
00089 # ifndef HAVE__STRNICMP
00090 int strncasecmp(const char *str1, const char *str2, size_t n);
00091 # else
00092 # define strncasecmp _strnicmp
00093 # endif
00094 #endif
00095
00096 #ifndef HAVE_SNPRINTF
00097 # ifndef HAVE_SPRINTF_S
00098 int snprintf(char *str, size_t size, const char *format, ...);
00099 # else
00100 # define snprintf sprintf_s
00101 # endif
00102 #endif
00103
00104 #include "wag.h"
00105 #include "daglegacy.h"
00106
00107 #ifdef HAVE_DAG_API
00108 # include "dagnew.h"
00109 # include "dagapi.h"
00110 # ifndef DAG_VERSION_2_4
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;
00162 uint16_t hatype;
00163 uint16_t halen;
00164 char addr[8];
00165 uint16_t 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
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_dlt_to_libtrace(libtrace_dlt_t dlt);
00363 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type);
00364 libtrace_rt_types_t pcap_dlt_to_rt(libtrace_dlt_t dlt);
00365 libtrace_dlt_t rt_to_pcap_dlt(libtrace_rt_types_t rt_type);
00366 libtrace_linktype_t erf_type_to_libtrace(uint8_t erf);
00367 uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype);
00368 libtrace_linktype_t arphrd_type_to_libtrace(unsigned int);
00369 unsigned int libtrace_to_arphrd_type(libtrace_linktype_t);
00370
00371 void promote_packet(libtrace_packet_t *packet);
00372 bool demote_packet(libtrace_packet_t *packet);
00373
00374 void *trace_get_payload_from_linux_sll(void *, uint16_t *, uint32_t *);
00375 void *trace_get_payload_from_pos(void *, uint16_t *, uint32_t *);
00376 DLLEXPORT void *trace_get_payload_from_atm(void *, uint8_t *, uint32_t *);
00377
00378 uint64_t byteswap64(uint64_t num);
00379 uint32_t byteswap32(uint32_t num);
00380 uint16_t byteswap16(uint16_t num);
00381
00382
00383
00384
00385
00386 #if BYTE_ORDER == BIG_ENDIAN
00387 #define bswap_host_to_be64(num) ((uint64_t)(num))
00388 #define bswap_host_to_le64(num) byteswap64(num)
00389 #define bswap_host_to_be32(num) ((uint32_t)(num))
00390 #define bswap_host_to_le32(num) byteswap32(num)
00391 #define bswap_host_to_be16(num) ((uint16_t)(num))
00392 #define bswap_host_to_le16(num) byteswap16(num)
00393
00394 #define bswap_be_to_host64(num) ((uint64_t)(num))
00395 #define bswap_le_to_host64(num) byteswap64(num)
00396 #define bswap_be_to_host32(num) ((uint32_t)(num))
00397 #define bswap_le_to_host32(num) byteswap32(num)
00398 #define bswap_be_to_host16(num) ((uint16_t)(num))
00399 #define bswap_le_to_host16(num) byteswap16(num)
00400
00401
00402
00403
00404 #elif BYTE_ORDER == LITTLE_ENDIAN
00405 #define bswap_host_to_be64(num) (byteswap64(num))
00406 #define bswap_host_to_le64(num) ((uint64_t)(num))
00407 #define bswap_host_to_be32(num) (htonl(num))
00408 #define bswap_host_to_le32(num) ((uint32_t)(num))
00409 #define bswap_host_to_be16(num) (htons(num))
00410 #define bswap_host_to_le16(num) ((uint16_t)(num))
00411
00412 #define bswap_be_to_host64(num) (byteswap64(num))
00413 #define bswap_le_to_host64(num) ((uint64_t)(num))
00414 #define bswap_be_to_host32(num) (ntohl(num))
00415 #define bswap_le_to_host32(num) ((uint32_t)(num))
00416 #define bswap_be_to_host16(num) (ntohs(num))
00417 #define bswap_le_to_host16(num) ((uint16_t)(num))
00418
00419 #else
00420 #error "Unknown byte order"
00421 #endif
00422
00423 #ifdef HAVE_BPF
00424
00425
00426
00427
00428
00429 struct libtrace_filter_t {
00430 struct bpf_program filter;
00431 int flag;
00432 char * filterstring;
00433 };
00434 #else
00435 struct libtrace_filter_t {};
00436 #endif
00437
00440 typedef struct libtrace_pcapfile_pkt_hdr_t {
00441 uint32_t ts_sec;
00442 uint32_t ts_usec;
00443 uint32_t caplen;
00444 uint32_t wirelen;
00445 } libtrace_pcapfile_pkt_hdr_t;
00446
00447 #ifdef HAVE_DAG
00448 void dag_constructor(void);
00449 #endif
00450 void erf_constructor(void);
00451 void legacy_constructor(void);
00452 void linuxnative_constructor(void);
00453 void pcap_constructor(void);
00454 void pcapfile_constructor(void);
00455 void rt_constructor(void);
00456 void wag_constructor(void);
00457 void duck_constructor(void);
00458
00459
00460
00461 #ifdef __cplusplus
00462 }
00463 #endif
00464
00465 #endif