Changeset e2aebe7
- Timestamp:
- 05/29/06 11:27:11 (15 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- f208f92
- Parents:
- ad96d00
- Location:
- lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/dagformat.h
rbf66333 re2aebe7 46 46 /** Flags */ 47 47 typedef struct flags { 48 uint8_t iface:2; 49 uint8_t vlen:1; 50 uint8_t trunc:1; 51 uint8_t rxerror:1; 52 uint8_t dserror:1; 53 uint8_t pad:2; 48 LT_BITFIELD8 iface:2; /**< Interface (direction) */ 49 LT_BITFIELD8 vlen:1; 50 LT_BITFIELD8 trunc:1; /**< Trunacted */ 51 LT_BITFIELD8 rxerror:1; /**< RX Error in this packet/before 52 * this packet 53 */ 54 LT_BITFIELD8 dserror:1; /**< Data stream error */ 55 LT_BITFIELD8 pad:2; /**< Unused */ 54 56 } PACKED flags_t; 55 57 -
lib/format_helper.c
r64444f9 re2aebe7 140 140 /* TODO: finalise packet */ 141 141 *packet = *trace->event.packet; 142 trace_destroy_packet(&trace->event.packet); 142 trace_destroy_packet(trace->event.packet); 143 trace->event.packet = NULL; 143 144 144 145 event.type = TRACE_EVENT_PACKET; -
lib/libtrace.h.in
r01459e4 re2aebe7 69 69 typedef unsigned __int32 uint32_t; 70 70 typedef unsigned __int64 uint64_t; 71 #ifdef BUILDING_DLL 72 #define DLLEXPORT __declspec(dllexport) 73 #else 74 #define DLLEXPORT __declspec(dllimport) 75 #endif 71 #ifdef BUILDING_DLL 72 #define DLLEXPORT __declspec(dllexport) 73 #else 74 #define DLLEXPORT __declspec(dllimport) 75 #endif 76 #define DLLLOCAL 77 /* Windows pads bitfields out to to the size of their parent type 78 * however gcc warns that this doesn't meet with the iso C specification 79 * so produces warnings for this behaviour. sigh. 80 */ 81 #define LT_BITFIELD8 uint8_t 82 #define LT_BITFIELD16 uint16_t 83 #define LT_BITFIELD32 uint32_t 84 #define LT_BITFIELD32 uint64_t 85 #else 86 #ifdef HAVE_GCCVISIBILITYPATCH 87 #define DLLEXPORT __attribute__ (visibility("default")) 88 #define DLLLOCAL __attribute__ (visibility("hidden")) 89 #else 90 #define DLLEXPORT 76 91 #define DLLLOCAL 77 #else 78 #ifdef HAVE_GCCVISIBILITYPATCH 79 #define DLLEXPORT __attribute__ (visibility("default")) 80 #define DLLLOCAL __attribute__ (visibility("hidden")) 81 #else 82 #define DLLEXPORT 83 #define DLLLOCAL 84 #endif 92 #endif 93 /* GCC warns if the bitfield type is not "unsigned int", however windows 94 * generates incorrect code for this (see above), so we define these 95 * macros. How Hidious. So much for C's portability. 96 */ 97 #define LT_BITFIELD8 unsigned int 98 #define LT_BITFIELD16 unsigned int 99 #define LT_BITFIELD32 unsigned int 100 #define LT_BITFIELD32 unsigned int 85 101 #endif 86 102 … … 217 233 TRACE_TYPE_POS, 218 234 TRACE_TYPE_80211_PRISM = 12, 219 TRACE_TYPE_DUCK ,/**< Pseudo link layer for DUCK packets */235 TRACE_TYPE_DUCK /**< Pseudo link layer for DUCK packets */ 220 236 } libtrace_linktype_t; 221 237 … … 246 262 { 247 263 #if BYTE_ORDER == LITTLE_ENDIAN 248 uint8_tip_hl:4; /**< Header Length */249 uint8_tip_v:4; /**< Version */264 LT_BITFIELD8 ip_hl:4; /**< Header Length */ 265 LT_BITFIELD8 ip_v:4; /**< Version */ 250 266 #elif BYTE_ORDER == BIG_ENDIAN 251 uint8_tip_v:4; /**< Version */252 uint8_tip_hl:4; /**< Header Length */267 LT_BITFIELD8 ip_v:4; /**< Version */ 268 LT_BITFIELD8 ip_hl:4; /**< Header Length */ 253 269 #else 254 270 # error "Adjust your <bits/endian.h> defines" … … 258 274 int16_t ip_id; /**< Identification */ 259 275 #if BYTE_ORDER == LITTLE_ENDIAN 260 uint16_tip_off:12; /**< Fragment Offset */261 uint16_tip_mf:1; /**< More Fragments Flag */262 uint16_tip_df:1; /**< Dont Fragment Flag */263 uint16_tip_rf:1; /**< Reserved Fragment Flag */276 LT_BITFIELD16 ip_off:12; /**< Fragment Offset */ 277 LT_BITFIELD16 ip_mf:1; /**< More Fragments Flag */ 278 LT_BITFIELD16 ip_df:1; /**< Dont Fragment Flag */ 279 LT_BITFIELD16 ip_rf:1; /**< Reserved Fragment Flag */ 264 280 #elif BYTE_ORDER == BIG_ENDIAN 265 uint16_tip_rf:1; /**< Fragment Offset */266 uint16_tip_df:1; /**< More Fragments Flag */267 uint16_tip_mf:1; /**< Dont Fragment Flag */268 uint16_tip_off:12; /**< Reserved Fragment Flag */281 LT_BITFIELD16 ip_rf:1; /**< Fragment Offset */ 282 LT_BITFIELD16 ip_df:1; /**< More Fragments Flag */ 283 LT_BITFIELD16 ip_mf:1; /**< Dont Fragment Flag */ 284 LT_BITFIELD16 ip_off:12; /**< Reserved Fragment Flag */ 269 285 #else 270 286 # error "Adjust your <bits/endian.h> defines" … … 303 319 uint32_t ack_seq; /**< Acknowledgement Number */ 304 320 # if BYTE_ORDER == LITTLE_ENDIAN 305 uint8_tres1:4; /**< Reserved bits */306 uint8_tdoff:4; /**< Data Offset */307 uint8_tfin:1; /**< FIN */308 uint8_tsyn:1; /**< SYN flag */309 uint8_trst:1; /**< RST flag */310 uint8_tpsh:1; /**< PuSH flag */311 uint8_tack:1; /**< ACK flag */312 uint8_turg:1; /**< URG flag */313 uint8_tres2:2; /**< Reserved */321 LT_BITFIELD8 res1:4; /**< Reserved bits */ 322 LT_BITFIELD8 doff:4; /**< Data Offset */ 323 LT_BITFIELD8 fin:1; /**< FIN */ 324 LT_BITFIELD8 syn:1; /**< SYN flag */ 325 LT_BITFIELD8 rst:1; /**< RST flag */ 326 LT_BITFIELD8 psh:1; /**< PuSH flag */ 327 LT_BITFIELD8 ack:1; /**< ACK flag */ 328 LT_BITFIELD8 urg:1; /**< URG flag */ 329 LT_BITFIELD8 res2:2; /**< Reserved */ 314 330 # elif BYTE_ORDER == BIG_ENDIAN 315 uint8_tdoff:4; /**< Data offset */316 uint8_tres1:4; /**< Reserved bits */317 uint8_tres2:2; /**< Reserved */318 uint8_turg:1; /**< URG flag */319 uint8_tack:1; /**< ACK flag */320 uint8_tpsh:1; /**< PuSH flag */321 uint8_trst:1; /**< RST flag */322 uint8_tsyn:1; /**< SYN flag */323 uint8_tfin:1; /**< FIN flag */331 LT_BITFIELD8 doff:4; /**< Data offset */ 332 LT_BITFIELD8 res1:4; /**< Reserved bits */ 333 LT_BITFIELD8 res2:2; /**< Reserved */ 334 LT_BITFIELD8 urg:1; /**< URG flag */ 335 LT_BITFIELD8 ack:1; /**< ACK flag */ 336 LT_BITFIELD8 psh:1; /**< PuSH flag */ 337 LT_BITFIELD8 rst:1; /**< RST flag */ 338 LT_BITFIELD8 syn:1; /**< SYN flag */ 339 LT_BITFIELD8 fin:1; /**< FIN flag */ 324 340 # else 325 341 # error "Adjust your <bits/endian.h> defines" … … 368 384 uint8_t control; 369 385 /* SNAP */ 370 uint32_toui:24; /**< Organisationally Unique Identifier (scope)*/386 LT_BITFIELD32 oui:24; /**< Organisationally Unique Identifier (scope)*/ 371 387 uint16_t type; /**< Protocol within OUI */ 372 388 } PACKED libtrace_llcsnap_t; … … 383 399 typedef struct libtrace_8021q 384 400 { 385 uint16_tvlan_pri:3; /**< VLAN User Priority */386 uint16_tvlan_cfi:1; /**< VLAN Format Indicator,401 LT_BITFIELD16 vlan_pri:3; /**< VLAN User Priority */ 402 LT_BITFIELD16 vlan_cfi:1; /**< VLAN Format Indicator, 387 403 * 0 for ethernet, 1 for token ring */ 388 uint16_tvlan_id:12; /**< VLAN Id */404 LT_BITFIELD16 vlan_id:12; /**< VLAN Id */ 389 405 uint16_t vlan_ether_type; /**< VLAN Sub-packet Type ID Field 390 406 * (next-header)*/ … … 394 410 typedef struct libtrace_atm_cell 395 411 { 396 uint32_tgfc:4; /**< Generic Flow Control */397 uint32_tvpi:8; /**< Virtual Path Identifier */398 uint32_tvci:8; /**< Virtual Channel Identifier */399 uint32_tpt:3; /**< Payload Type */400 uint32_tclp:1; /**< Cell Loss Priority */401 uint32_thec:8; /**< Header Error Control */412 LT_BITFIELD32 gfc:4; /**< Generic Flow Control */ 413 LT_BITFIELD32 vpi:8; /**< Virtual Path Identifier */ 414 LT_BITFIELD32 vci:8; /**< Virtual Channel Identifier */ 415 LT_BITFIELD32 pt:3; /**< Payload Type */ 416 LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ 417 LT_BITFIELD32 hec:8; /**< Header Error Control */ 402 418 } PACKED libtrace_atm_cell_t; 403 419 … … 411 427 /** 802.11 header */ 412 428 typedef struct libtrace_80211_t { 413 uint16_tprotocol:2;414 uint16_ttype:2;415 uint16_tsubtype:4;416 uint16_tto_ds:1; /**< Packet to Distribution Service */417 uint16_tfrom_ds:1; /**< Packet from Distribution Service */418 uint16_tmore_frag:1; /**< Packet has more fragments */419 uint16_tretry:1; /**< Packet is a retry */420 uint16_tpower:1;421 uint16_tmore_data:1;422 uint16_twep:1;423 uint16_torder:1;429 LT_BITFIELD32 protocol:2; 430 LT_BITFIELD32 type:2; 431 LT_BITFIELD32 subtype:4; 432 LT_BITFIELD32 to_ds:1; /**< Packet to Distribution Service */ 433 LT_BITFIELD32 from_ds:1; /**< Packet from Distribution Service */ 434 LT_BITFIELD32 more_frag:1; /**< Packet has more fragments */ 435 LT_BITFIELD32 retry:1; /**< Packet is a retry */ 436 LT_BITFIELD32 power:1; 437 LT_BITFIELD32 more_data:1; 438 LT_BITFIELD32 wep:1; 439 LT_BITFIELD32 order:1; 424 440 uint16_t duration; 425 441 uint8_t mac1[6]; … … 658 674 * sideeffect: sets packet to NULL 659 675 */ 660 DLLEXPORT void trace_destroy_packet(libtrace_packet_t * *packet);676 DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet); 661 677 662 678 … … 777 793 uint32_t *remaining); 778 794 795 DLLEXPORT void *trace_get_payload_from_link(void *link, 796 libtrace_linktype_t linktype, 797 uint16_t *type, uint32_t *remaining) 798 779 799 /** Gets a pointer to the payload given a pointer to a tcp header 780 800 * @param tcp The tcp Header … … 1108 1128 */ 1109 1129 DLLEXPORT SIMPLE_FUNCTION 1110 libtrace_filter_t *trace_ bpf_setfilter(const char *filterstring);1130 libtrace_filter_t *trace_create_filter(const char *filterstring); 1111 1131 1112 1132 /** apply a BPF filter 1113 1133 * @param filter the filter opaque pointer 1114 1134 * @param packet the packet opaque pointer 1115 * @return 1 if the filter matches, 0 if it doesn't.1135 * @return >0 if the filter matches, 0 if it doesn't, -1 on error. 1116 1136 * @note Due to the way BPF filters are built, the filter is not actually 1117 * compiled until the first time trace_ bpf_filter is called. If your filter is1118 * i ncorrect, it will generate an error message and assert, exiting the1137 * compiled until the first time trace_create_filter is called. If your filter 1138 * is incorrect, it will generate an error message and assert, exiting the 1119 1139 * program. This behaviour may change to more graceful handling of this error 1120 1140 * in the future. 1121 1141 */ 1122 DLLEXPORT int trace_ bpf_filter(libtrace_filter_t *filter,1142 DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter, 1123 1143 const libtrace_packet_t *packet); 1124 1144 … … 1127 1147 * Deallocate all the resources associated with a BPF filter 1128 1148 */ 1129 DLLEXPORT void trace_destroy_ bpf(libtrace_filter_t *filter);1149 DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter); 1130 1150 /*@}*/ 1131 1151 -
lib/trace.c
rcd7eec7 re2aebe7 215 215 void rt_constructor(); 216 216 void wag_constructor(); 217 void duck_constructor(); 217 218 218 219 /* call all the constructors if they haven't yet all been called */ … … 630 631 * sideeffect: sets packet to NULL 631 632 */ 632 DLLEXPORT void trace_destroy_packet(libtrace_packet_t **packet) { 633 if ((*packet)->buf_control == TRACE_CTRL_PACKET) { 634 free((*packet)->buffer); 635 } 636 free((*packet)); 637 *packet = NULL; 633 DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet) { 634 if (packet->buf_control == TRACE_CTRL_PACKET) { 635 free(packet->buffer); 636 } 637 packet->buf_control='\0'; /* an "bad" value to force an assert 638 * if this packet is ever reused 639 */ 640 free(packet); 638 641 } 639 642 … … 667 670 * packet 668 671 */ 669 if (!trace_ bpf_filter(libtrace->filter,packet)){672 if (!trace_apply_filter(libtrace->filter,packet)){ 670 673 continue; 671 674 } … … 916 919 * @author Daniel Lawson 917 920 */ 918 DLLEXPORT libtrace_filter_t *trace_ bpf_setfilter(const char *filterstring) {921 DLLEXPORT libtrace_filter_t *trace_create_filter(const char *filterstring) { 919 922 #if HAVE_BPF 920 923 libtrace_filter_t *filter = (libtrace_filter_t*) … … 929 932 } 930 933 931 DLLEXPORT void trace_destroy_ bpf(libtrace_filter_t *filter)934 DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter) 932 935 { 933 936 #if HAVE_BPF … … 996 999 } 997 1000 998 DLLEXPORT int trace_ bpf_filter(libtrace_filter_t *filter,1001 DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter, 999 1002 const libtrace_packet_t *packet) { 1000 1003 #if HAVE_BPF
Note: See TracChangeset
for help on using the changeset viewer.