1 #ifndef ETTERCAP_DECODE_H 2 #define ETTERCAP_DECODE_H 3 4 #include <ec_proto.h> 5 #include <ec_packet.h> 6 #include <ec_hook.h> 7 #include <pcap.h> 8 9 /* layer canonical name */ 10 11 enum { 12 IFACE_LAYER = 1, 13 LINK_LAYER = 2, 14 NET_LAYER = 3, 15 NET6_LAYER = 31, /* IPv6 options */ 16 PROTO_LAYER = 4, 17 APP_LAYER = 5, /* special case for the middleware decoder. don't use it */ 18 APP_LAYER_TCP = 51, 19 APP_LAYER_UDP = 52, 20 }; 21 22 #define FUNC_DECODER(func) void * func(u_char *buf, u_int16 buflen, int *len, struct packet_object *po) 23 #define FUNC_DECODER_PTR(func) void * (*func)(u_char *buf, u_int16 buflen, int *len, struct packet_object *po) 24 25 #define DECODE_DATALEN buflen 26 #define DECODE_DATA buf 27 #define DECODED_LEN *len 28 #define PACKET po 29 30 #define EXECUTE_DECODER(x) do{ \ 31 if (x) \ 32 x(DECODE_DATA+DECODED_LEN, DECODE_DATALEN-DECODED_LEN, len, PACKET); \ 33 }while(0) 34 35 #define DECLARE_REAL_PTR_END(x,y) u_char *x = po->DATA.data; \ 36 u_char *y = x + po->DATA.len 37 38 #define DECLARE_DISP_PTR_END(x,y) u_char *x = po->DATA.disp_data; \ 39 u_char *y = x + po->DATA.disp_len 40 41 #define DECLARE_DISP_PTR(x) u_char *x = po->DATA.disp_data 42 43 #define DISPLAY_DATA po->disp_data 44 #define DISPLAY_LEN po->disp_len 45 46 /* exported functions */ 47 48 EC_API_EXTERN void ec_decode(u_char *u, const struct pcap_pkthdr *pkthdr, const u_char *pkt); 49 EC_API_EXTERN void add_decoder(u_int8 level, u_int32 type, FUNC_DECODER_PTR(decoder)); 50 EC_API_EXTERN void del_decoder(u_int8 level, u_int32 type); 51 EC_API_EXTERN void *get_decoder(u_int8 level, u_int32 type); 52 53 #endif 54 55 /* EOF */ 56 57 // vim:ts=3:expandtab 58 59