- Timestamp:
- 05/11/06 16:57:27 (16 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:
- da34e20
- Parents:
- 4e65f42
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libtrace.h.in
r3fcb8b4 r83445f0 140 140 typedef struct libtrace_filter_t libtrace_filter_t; 141 141 142 /** if a packet has memory allocated142 /** If a packet has memory allocated 143 143 * If the packet has allocated it's own memory it's buffer_control should 144 144 * be TRACE_CTRL_PACKET, when the packet is destroyed it's memory will be … … 152 152 TRACE_CTRL_EXTERNAL='e' 153 153 } buf_control_t; 154 /** Structure holding information about a packet*/154 /** The size of a packet's buffer when managed by libtrace */ 155 155 #define LIBTRACE_PACKET_BUFSIZE 65536 156 156 157 /** The libtrace structure, applications shouldn't be meddling around in here 157 /** The libtrace packet structure, applications shouldn't be 158 * meddling around in here 158 159 */ 159 160 typedef struct libtrace_packet_t { … … 184 185 /** Unknown config option */ 185 186 TRACE_ERR_UNKNOWN_OPTION= -3, 186 /** Option known, but unsupported by this format */187 TRACE_ERR_OPTION_UNAVAIL= -6,188 187 /** This output uri cannot write packets of this type */ 189 188 TRACE_ERR_NO_CONVERSION = -4, 190 189 /** This packet is corrupt, or unusable for the action required */ 191 190 TRACE_ERR_BAD_PACKET = -5, 191 /** Option known, but unsupported by this format */ 192 TRACE_ERR_OPTION_UNAVAIL= -6, 192 193 /** This feature is unsupported */ 193 194 TRACE_ERR_UNSUPPORTED = -7 194 195 }; 195 196 197 /** Enumeration of DLT types supported by libtrace */ 196 198 typedef enum { 197 199 TRACE_DLT_NULL = 0, … … 203 205 } libtrace_dlt_t ; 204 206 205 /** Link layer types 206 * This enumates the various different link types that libtrace understands 207 */ 207 /** Enumeration of link layer types supported by libtrace */ 208 208 typedef enum { 209 209 TRACE_TYPE_HDLC_POS = 1, 210 210 TRACE_TYPE_ETH, /**< 802.3 style Ethernet */ 211 TRACE_TYPE_ATM, 211 TRACE_TYPE_ATM, /**< ATM frame */ 212 212 TRACE_TYPE_AAL5, 213 213 TRACE_TYPE_80211, /**< 802.11 frames */ … … 241 241 #endif 242 242 243 /** Structure for dealing with IP packets*/243 /** Generic IP header structure */ 244 244 typedef struct libtrace_ip 245 245 { 246 246 #if BYTE_ORDER == LITTLE_ENDIAN 247 uint8_t ip_hl:4; /**< header length */248 uint8_t ip_v:4; /**< version */247 uint8_t ip_hl:4; /**< Header Length */ 248 uint8_t ip_v:4; /**< Version */ 249 249 #elif BYTE_ORDER == BIG_ENDIAN 250 uint8_t ip_v:4; /**< version */251 uint8_t ip_hl:4; /**< header length */250 uint8_t ip_v:4; /**< Version */ 251 uint8_t ip_hl:4; /**< Header Length */ 252 252 #else 253 253 # error "Adjust your <bits/endian.h> defines" 254 254 #endif 255 uint8_t ip_tos; /**< type of service */256 uint16_t ip_len; /**< total length */257 int16_t ip_id; /**< identification */255 uint8_t ip_tos; /**< Type of Service */ 256 uint16_t ip_len; /**< Total Length */ 257 int16_t ip_id; /**< Identification */ 258 258 #if BYTE_ORDER == LITTLE_ENDIAN 259 uint16_t ip_off:12; /**< fragment offset */260 uint16_t ip_mf:1; /**< more fragments flag */261 uint16_t ip_df:1; /**< dont fragment flag */262 uint16_t ip_rf:1; /**< reserved fragment flag */259 uint16_t ip_off:12; /**< Fragment Offset */ 260 uint16_t ip_mf:1; /**< More Fragments Flag */ 261 uint16_t ip_df:1; /**< Dont Fragment Flag */ 262 uint16_t ip_rf:1; /**< Reserved Fragment Flag */ 263 263 #elif BYTE_ORDER == BIG_ENDIAN 264 uint16_t ip_rf:1; 265 uint16_t ip_df:1; 266 uint16_t ip_mf:1; 267 uint16_t ip_off:12; 264 uint16_t ip_rf:1; /**< Fragment Offset */ 265 uint16_t ip_df:1; /**< More Fragments Flag */ 266 uint16_t ip_mf:1; /**< Dont Fragment Flag */ 267 uint16_t ip_off:12; /**< Reserved Fragment Flag */ 268 268 #else 269 269 # error "Adjust your <bits/endian.h> defines" 270 270 #endif 271 uint8_t ip_ttl; /**< time to live */272 uint8_t ip_p; /**< protocol */273 uint16_t ip_sum; /**< checksum */274 struct in_addr ip_src; /**< source address */275 struct in_addr ip_dst; /**< dest address */271 uint8_t ip_ttl; /**< Time to Live */ 272 uint8_t ip_p; /**< Protocol */ 273 uint16_t ip_sum; /**< Checksum */ 274 struct in_addr ip_src; /**< Source Address */ 275 struct in_addr ip_dst; /**< Destination Address */ 276 276 } PACKED libtrace_ip_t; 277 277 278 /** IPv6 header extension structure */ 278 279 typedef struct libtrace_ip6_ext 279 280 { … … 282 283 } PACKED libtrace_ip6_ext_t; 283 284 284 /** IPv6 header structure */285 /** Generic IPv6 header structure */ 285 286 typedef struct libtrace_ip6 286 287 { … … 293 294 } PACKED libtrace_ip6_t; 294 295 295 /** Structure for dealing with TCP packets*/296 /** Generic TCP header structure */ 296 297 typedef struct libtrace_tcp 297 298 { … … 302 303 # if BYTE_ORDER == LITTLE_ENDIAN 303 304 uint8_t res1:4; /**< Reserved bits */ 304 uint8_t doff:4; /**< data offset */305 uint8_t doff:4; /**< Data Offset */ 305 306 uint8_t fin:1; /**< FIN */ 306 307 uint8_t syn:1; /**< SYN flag */ … … 328 329 } PACKED libtrace_tcp_t; 329 330 330 /** UDP Header for dealing with UDP packets*/331 /** Generic UDP header structure */ 331 332 typedef struct libtrace_udp { 332 333 uint16_t source; /**< Source port */ … … 336 337 } PACKED libtrace_udp_t; 337 338 338 /** ICMP Header for dealing with icmp packets*/339 /** Generic ICMP header structure */ 339 340 typedef struct libtrace_icmp 340 341 { 341 uint8_t type; /**< message type */342 uint8_t code; /**< type sub-code */343 uint16_t checksum; /**< checksum */342 uint8_t type; /**< Message Type */ 343 uint8_t code; /**< Type Sub-code */ 344 uint16_t checksum; /**< Checksum */ 344 345 union 345 346 { … … 348 349 uint16_t id; 349 350 uint16_t sequence; 350 } echo; /**< echo datagram */351 uint32_t gateway; /**< gateway address */351 } echo; /**< Echo Datagram */ 352 uint32_t gateway; /**< Gateway Address */ 352 353 struct 353 354 { 354 355 uint16_t unused; 355 356 uint16_t mtu; 356 } frag; /**< path mtu discovery */357 } un; /**< Union for payloads of various icmp codes */357 } frag; /**< Path MTU Discovery */ 358 } un; /**< Union for Payloads of Various ICMP Codes */ 358 359 } PACKED libtrace_icmp_t; 359 360 360 /** LLC/SNAP header*/361 /** Generic LLC/SNAP header structure */ 361 362 typedef struct libtrace_llcsnap 362 363 { … … 373 374 typedef struct libtrace_ether 374 375 { 375 uint8_t ether_dhost[6]; /**< destination ether addr */376 uint8_t ether_shost[6]; /**< source ether addr */377 uint16_t ether_type; /**< packet type ID field (next-header) */376 uint8_t ether_dhost[6]; /**< Destination Ether Addr */ 377 uint8_t ether_shost[6]; /**< Source Ether Addr */ 378 uint16_t ether_type; /**< Packet Type ID Field (next-header) */ 378 379 } PACKED libtrace_ether_t; 379 380 … … 381 382 typedef struct libtrace_8021q 382 383 { 383 uint16_t vlan_pri:3; /**< vlan user priority */384 uint16_t vlan_cfi:1; /**< vlan format indicator,384 uint16_t vlan_pri:3; /**< VLAN User Priority */ 385 uint16_t vlan_cfi:1; /**< VLAN Format Indicator, 385 386 * 0 for ethernet, 1 for token ring */ 386 uint16_t vlan_id:12; /**< vlan id */387 uint16_t vlan_ether_type; /**< vlan sub-packet type ID field387 uint16_t vlan_id:12; /**< VLAN Id */ 388 uint16_t vlan_ether_type; /**< VLAN Sub-packet Type ID Field 388 389 * (next-header)*/ 389 390 } PACKED libtrace_8021q_t; … … 404 405 { 405 406 uint16_t header; 406 uint16_t ether_type; /**< ether type */407 uint16_t ether_type; /**< Ether Type */ 407 408 } PACKED libtrace_pos_t; 408 409 … … 442 443 DLLEXPORT void trace_help(); 443 444 444 /** Gets the output format for a given output trace445 *446 * @param libtrace the output trace to get the name of the format fo447 * @return callee-owned null-terminated char* containing the output format448 *449 */450 DLLEXPORT SIMPLE_FUNCTION451 char *trace_get_output_format(const libtrace_out_t *libtrace);452 453 445 /** @name Trace management 454 446 * These members deal with creating, configuring, starting, pausing and … … 460 452 * 461 453 * @param uri containing a valid libtrace URI 462 * @return opaque pointer to a libtrace_t454 * @return an opaque pointer to a libtrace_t 463 455 * 464 456 * Valid URI's are: 465 457 * - erf:/path/to/erf/file 466 * - erf:/path/to/erf/file.gz467 * - erf:/path/to/rtclient/socket468 458 * - erf:- (stdin) 469 459 * - dag:/dev/dagcard … … 471 461 * - pcap:/path/to/pcap/file 472 462 * - pcap:- 473 * - rtclient:hostname 474 * - rtclient:hostname:port 475 * - wag:- 476 * - wag:/path/to/wag/file 477 * - wag:/path/to/wag/file.gz 478 * - wag:/path/to/wag/socket 463 * - rt:hostname 464 * - rt:hostname:port 465 * - rtclient:hostname (deprecated) 466 * - rtclient:hostname:port (deprecated) 467 * - wag:/dev/wagcard 468 * - wtf:- 469 * - wtf:/path/to/wtf/file 479 470 * 480 471 * If an error occured when attempting to open the trace file, an error … … 487 478 /** Creates a "dummy" trace file that has only the format type set. 488 479 * 489 * @return opaque pointer to a (sparsely initialised) libtrace_t480 * @return an opaque pointer to a (sparsely initialised) libtrace_t 490 481 * 491 482 * IMPORTANT: Do not attempt to call trace_read_packet or other such functions … … 498 489 * 499 490 * @param uri the uri string describing the output format and destination 500 * @return opaque pointer to a libtrace_output_t 501 * @author Shane Alcock 491 * @return an opaque pointer to a libtrace_output_t 502 492 * 503 493 * Valid URI's are: 504 * - gzerf:/path/to/erf/file.gz 505 * - gzerf:/path/to/erf/file 506 * - rtserver:hostname 507 * - rtserver:hostname:port 494 * - erf:/path/to/erf/file 495 * - pcap:/path/to/pcap/file 496 * - wtf:/path/to/wtf/file 508 497 * 509 498 * If an error occured when attempting to open the output trace, NULL is returned … … 514 503 /** Start the capture 515 504 * @param libtrace The trace to start 516 * @return 0 on success 505 * @return 0 on success, -1 on failure 517 506 * 518 507 * This does the actual work with starting the trace capture, and applying … … 523 512 /** Pause the capture 524 513 * @param libtrace The trace to pause 525 * @return 0 on success 514 * @return 0 on success, -1 on failure 526 515 * 527 516 * This stops a capture in progress and returns you to the configuration … … 533 522 /** Start an output trace 534 523 * @param libtrace The trace to start 535 * @return 0 on success 524 * @return 0 on success, -1 on failure 536 525 * 537 526 * This does the actual work with starting a trace for write. This generally … … 591 580 /** Close a trace output file, freeing up any resources it may have been using 592 581 * @param trace the output trace file to be destroyed 593 *594 * @author Shane Alcock595 582 */ 596 583 DLLEXPORT void trace_destroy_output(libtrace_out_t *trace); … … 672 659 673 660 674 /** Read one packet from the trace into buffer661 /** Read one packet from the trace 675 662 * 676 663 * @param trace the libtrace opaque pointer … … 697 684 } libtrace_event_t; 698 685 699 /** structure returned by libtrace_event explaining what the current event is */686 /** Structure returned by libtrace_event explaining what the current event is */ 700 687 typedef struct libtrace_eventobj_t { 701 688 libtrace_event_t type; /**< event type (iowait,sleep,packet) */ … … 708 695 } libtrace_eventobj_t; 709 696 710 /** process alibtrace event697 /** Processes the next libtrace event 711 698 * @param trace the libtrace opaque pointer 712 699 * @param packet the libtrace_packet opaque pointer … … 744 731 * @return a pointer to the link layer, or NULL if there is no link layer 745 732 * 746 * @note you should call getLinkType() to find out what type of link layer747 * this is733 * @note you should call trace_get_link_type to find out what type of link 734 * layer this is 748 735 */ 749 736 DLLEXPORT SIMPLE_FUNCTION … … 753 740 * @param packet the packet opaque pointer 754 741 * 755 * @return a pointer to the IP header, or NULL if there is no t an IP packet742 * @return a pointer to the IP header, or NULL if there is no IP header 756 743 */ 757 744 DLLEXPORT SIMPLE_FUNCTION … … 831 818 * @note This is similar to trace_get_payload_from_icmp in libtrace2 832 819 */ 833 DLLEXPORT void *trace_get_payload_from_icmp(libtrace_icmp_t *icmp, uint32_t * skipped);820 DLLEXPORT void *trace_get_payload_from_icmp(libtrace_icmp_t *icmp, uint32_t *remaining); 834 821 835 822 /** get a pointer to the TCP header (if any) … … 975 962 * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds 976 963 * past 1970-01-01, the lower 32bits are partial seconds) 977 * @author Daniel Lawson978 964 */ 979 965 DLLEXPORT SIMPLE_FUNCTION … … 984 970 * 985 971 * @return time that this packet was seen in a struct timeval 986 * @author Daniel Lawson987 * @author Perry Lorier988 972 */ 989 973 DLLEXPORT SIMPLE_FUNCTION … … 994 978 * 995 979 * @return time that this packet was seen in 64bit floating point seconds 996 * @author Daniel Lawson997 * @author Perry Lorier998 980 */ 999 981 DLLEXPORT SIMPLE_FUNCTION … … 1043 1025 * @param packet the packet opaque pointer 1044 1026 * @return the size of the packet in the trace 1045 * @author Perry Lorier1046 1027 * @note Due to this being a header capture, or anonymisation, this may not 1047 1028 * be the same size as the original packet. See get_wire_length() for the … … 1050 1031 * @note This is sometimes called the "snaplen". 1051 1032 * @note The return size refers to the network-level payload of the packet and 1052 * does not include any capture headers. For example, an Ethernet packet with1053 * an empty TCP packet will return sizeof(ethernet_header) + sizeof(ip_header)1054 * + sizeof(tcp_header).1033 * does not include any capture framing headers. For example, an Ethernet 1034 * packet with an empty TCP packet will return sizeof(ethernet_header) + 1035 * sizeof(ip_header) + sizeof(tcp_header). 1055 1036 */ 1056 1037 DLLEXPORT SIMPLE_FUNCTION … … 1070 1051 * @param packet the packet opaque pointer 1071 1052 * @return the size of the packet as it was on the wire. 1072 * @author Perry Lorier1073 * @author Daniel Lawson1074 1053 * @note this length corresponds to the difference between the size of a 1075 1054 * captured packet in memory, and the captured length of the packet … … 1092 1071 * @param packet the packet opaque pointer 1093 1072 * @return libtrace_linktype_t 1094 * @author Perry Lorier1095 * @author Daniel Lawson1096 1073 */ 1097 1074 DLLEXPORT SIMPLE_FUNCTION … … 1112 1089 * Other values are possible, which might be overloaded to mean special things 1113 1090 * for a special trace. 1114 * @author Daniel Lawson1115 1091 */ 1116 1092 DLLEXPORT SIMPLE_FUNCTION … … 1124 1100 * @param filterstring a char * containing the bpf filter string 1125 1101 * @return opaque pointer pointer to a libtrace_filter_t object 1126 * @author Daniel Lawson1127 1102 * @note The filter is not actually compiled at this point, so no correctness 1128 1103 * tests are performed here. trace_bpf_setfilter will always return ok, but … … 1200 1175 /** Get the source port 1201 1176 * @param packet the packet to read from 1202 * @return a port in \em HOST byte order, or equiv ilent to ports for this1177 * @return a port in \em HOST byte order, or equivalent to ports for this 1203 1178 * protocol, or 0 if this protocol has no ports. 1204 * @author Perry Lorier1205 1179 */ 1206 1180 DLLEXPORT SIMPLE_FUNCTION … … 1211 1185 * @return a port in \em HOST byte order, or equivilent to ports for this 1212 1186 * protocol, or 0 if this protocol has no ports. 1213 * @author Perry Lorier1214 1187 */ 1215 1188 DLLEXPORT SIMPLE_FUNCTION … … 1222 1195 * @return one of USE_SOURCE or USE_DEST depending on which one you should use 1223 1196 * @note ports must be in \em HOST byte order! 1224 * @author Daniel Lawson1225 1197 */ 1226 1198 DLLEXPORT SIMPLE_FUNCTION … … 1228 1200 1229 1201 /** Takes a uri and splits it into a format and uridata component. 1230 * Primarily for internal use but made available for external use.1231 1202 * @param uri the uri to be parsed 1232 1203 * @param format destination location for the format component of the uri 1233 1204 * @return 0 if an error occured, otherwise return the uridata component 1234 * @author Shane Alcock1235 1205 */ 1236 1206 DLLEXPORT const char *trace_parse_uri(const char *uri, char **format); … … 1251 1221 }; 1252 1222 1253 /** Gets the f raming headertype for a given packet.1223 /** Gets the format type for a given packet. 1254 1224 * @param packet the packet opaque pointer 1255 1225 * @return the format of the packet … … 1257 1227 DLLEXPORT 1258 1228 enum base_format_t trace_get_format(struct libtrace_packet_t *packet); 1229 1259 1230 1260 1231 #ifdef __cplusplus -
lib/trace.c
r4e65f42 r83445f0 252 252 #define URI_PROTO_LINE 16 253 253 254 /* Gets the name of the output format for a given output trace.255 *256 * @params libtrace the output trace to get the name of the format for257 * @returns callee-owned null-terminated char* containing the output format258 *259 */260 DLLEXPORT SIMPLE_FUNCTION261 char *trace_get_output_format(const libtrace_out_t *libtrace) {262 char * format = libtrace->format->name;263 264 return format;265 }266 267 254 268 255 /* Create a trace file from a URI
Note: See TracChangeset
for help on using the changeset viewer.