Changeset 2137b49 for lib/libtrace.h
- Timestamp:
- 08/05/04 16:14:14 (17 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:
- 670d3de
- Parents:
- b535184
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libtrace.h
rbb313ef r2137b49 29 29 */ 30 30 31 #ifndef _LIBTRACE_H_32 #define _LIBTRACE_H_31 #ifndef LIBTRACE_H 32 #define LIBTRACE_H 33 33 34 34 #include <features.h> … … 77 77 78 78 /** Opaque structure holding information about a bpf filter */ 79 80 79 struct libtrace_filter_t; 80 81 /** Opaque structure holding information about a packet */ 82 #define LIBTRACE_PACKET_BUFSIZE 65536 83 struct libtrace_packet_t { 84 struct libtrace_t *trace; 85 char buffer[LIBTRACE_PACKET_BUFSIZE]; 86 size_t size; 87 uint8_t status; 88 }; 89 81 90 /** Structure for dealing with IP packets */ 82 91 struct libtrace_ip … … 197 206 * and an error is output to stdout. 198 207 */ 199 struct libtrace_t * create_trace(char *uri);208 struct libtrace_t *trace_create(char *uri); 200 209 201 210 /** Close a trace file, freeing up any resources it may have been using 202 211 * 203 212 */ 204 void destroy_trace(struct libtrace_t *rtclient);213 void trace_destroy(struct libtrace_t *trace); 205 214 206 215 /** Read one packet from the trace into buffer 207 216 * 208 * @param libtrace the trace to read from 209 * @param buffer the buffer to read into 210 * @param len the length of the buffer 211 * @param status status of the trace (only used for RTClients) 212 * @returns number of bytes copied, -1 on error, or 0 at EOF 213 * 214 * @note the buffer must be at least as large as the largest packet (plus 215 * link layer, and trace packet metadata overhead) 216 */ 217 int libtrace_read_packet(struct libtrace_t *rtclient, void *buffer, size_t len, int *status); 217 * @param libtrace the libtrace opaque pointer 218 * @param packet the packet opaque pointer 219 * @returns false if it failed to read a packet 220 * 221 */ 222 int trace_read_packet(struct libtrace_t *trace, struct libtrace_packet_t *packet); 218 223 219 224 /** get a pointer to the link layer 220 * @param libtrace a pointer to the trace object returned from gettrace 221 * @param buffer a pointer to a filled in buffer 222 * @param buflen a pointer to the size of the buffer 225 * @param packet the packet opaque pointer 223 226 * 224 227 * @returns a pointer to the link layer, or NULL if there is no link layer … … 227 230 * this is 228 231 */ 229 void * get_link(struct libtrace_t *libtrace, void *buffer, int buflen);232 void *trace_get_link(struct libtrace_packet_t *packet); 230 233 231 234 /** get a pointer to the IP header (if any) 232 * @param libtrace a pointer to the trace object returned from gettrace 233 * @param buffer a pointer to a filled in buffer 234 * @param buflen a pointer to the size of the buffer 235 * @param packet the packet opaque pointer 235 236 * 236 237 * @returns a pointer to the IP header, or NULL if there is not an IP packet 237 238 */ 238 struct libtrace_ip * get_ip(struct libtrace_t *libtrace, void *buffer, int buflen);239 struct libtrace_ip *trace_get_ip(struct libtrace_packet_t *packet); 239 240 240 241 /** get a pointer to the TCP header (if any) 241 * @param libtrace a pointer to the trace object returned from gettrace 242 * @param buffer a pointer to a filled in buffer 243 * @param buflen a pointer to the size of the buffer 242 * @param packet the packet opaque pointer 244 243 * 245 244 * @returns a pointer to the TCP header, or NULL if there is not a TCP packet 246 245 */ 247 struct libtrace_tcp * get_tcp(struct libtrace_t *libtrace, void *buffer, int buflen);246 struct libtrace_tcp *trace_get_tcp(struct libtrace_packet_t *packet); 248 247 249 248 /** get a pointer to the UDP header (if any) 250 * @param libtrace a pointer to the trace object returned from gettrace 251 * @param buffer a pointer to a filled in buffer 252 * @param buflen a pointer to the size of the buffer 249 * @param packet the packet opaque pointer 253 250 * 254 251 * @returns a pointer to the UDP header, or NULL if this is not a UDP packet 255 252 */ 256 struct libtrace_udp * get_udp(struct libtrace_t *libtrace, void *buffer, int buflen);253 struct libtrace_udp *trace_get_udp(struct libtrace_packet_t *packet); 257 254 258 255 /** get a pointer to the ICMP header (if any) 259 * @param libtrace a pointer to the trace object returned from gettrace 260 * @param buffer a pointer to a filled in buffer 261 * @param buflen a pointer to the size of the buffer 256 * @param packet the packet opaque pointer 262 257 * 263 258 * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet 264 259 */ 265 struct libtrace_icmp * get_icmp(struct libtrace_t *libtrace, void *buffer, int buflen);260 struct libtrace_icmp *trace_get_icmp(struct libtrace_packet_t *packet); 266 261 267 262 /** Get the current time in DAG time format 268 * @param libtrace the libtrace opaque pointer 269 * @param buffer a pointer to a filled in buffer 270 * @param buflen the length of the buffer 263 * @param packet the packet opaque pointer 264 * 271 265 * @returns a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds 272 266 * past 1970-01-01, the lower 32bits are partial seconds) 273 267 * @author Daniel Lawson 274 268 */ 275 uint64_t get_erf_timestamp(struct libtrace_t *libtrace, void *buffer, int buflen);269 uint64_t trace_get_erf_timestamp(struct libtrace_packet_t *packet); 276 270 277 271 /** Get the current time in struct timeval 278 * @param libtrace the libtrace opaque pointer 279 * @param buffer a pointer to a filled in buffer 280 * @param buflen the length of the buffer 272 * @param packet the packet opaque pointer 273 * 281 274 * @returns time that this packet was seen in a struct timeval 282 275 * @author Daniel Lawson 283 276 * @author Perry Lorier 284 277 */ 285 286 struct timeval get_timeval(struct libtrace_t *libtrace, void *buffer, int buflen); 278 struct timeval trace_get_timeval(struct libtrace_packet_t *packet); 287 279 288 280 /** Get the current time in floating point seconds 289 * @param libtrace the libtrace opaque pointer 290 * @param buffer a pointer to a filled in buffer 291 * @param buflen the length of the buffer 281 * @param packet the packet opaque pointer 282 * 292 283 * @returns time that this packet was seen in 64bit floating point seconds 293 284 * @author Perry Lorier 294 285 */ 295 double get_seconds(struct libtrace_t *libtrace, void *buffer, int buflen);286 double trace_get_seconds(struct libtrace_packet_t *packet); 296 287 297 288 /** Get the size of the packet in the trace 298 * @param libtrace the libtrace opaque pointer 299 * @param buffer a pointer to a filled in buffer 300 * @param buflen the length of the buffer 289 * @param packet the packet opaque pointer 301 290 * @returns the size of the packet in the trace 302 291 * @author Perry Lorier … … 309 298 */ 310 299 311 int get_capture_length(struct libtrace_t *libtrace, void *buffer, int buflen);300 int trace_get_capture_length(struct libtrace_packet_t *packet); 312 301 313 302 /** Get the size of the packet as it was seen on the wire. 314 * @param libtrace the libtrace opaque pointer 315 * @param buffer a pointer to a filled in buffer 316 * @param buflen the length of the buffer 303 * @param packet the packet opaque pointer 317 304 * @returns the size of the packet as it was on the wire. 318 305 * @author Perry Lorier … … 322 309 */ 323 310 324 int get_wire_length(struct libtrace_t *libtrace, void *buffer, int buflen);311 int trace_get_wire_length(struct libtrace_packet_t *packet); 325 312 326 313 /** Link layer types … … 335 322 336 323 /** Get the type of the link layer 337 * @param libtrace the libtrace opaque pointer 338 * @param buffer a pointer to a filled in buffer 339 * @param buflen the length of the buffer 324 * @param packet the packet opaque pointer 340 325 * @returns libtrace_linktype_t 341 326 * @author Perry Lorier … … 343 328 */ 344 329 345 inline libtrace_linktype_t get_link_type( 346 struct libtrace_t *libtrace, 347 void *buffer, 348 int buflen); 330 inline libtrace_linktype_t trace_get_link_type(struct libtrace_packet_t *packet); 349 331 350 332 /** Get the destination MAC addres 351 * @param libtrace the libtrace opaque pointer 352 * @param buffer a pointer to a filled in buffer 353 * @param buflen the length of the buffer 333 * @param packet the packet opaque pointer 354 334 * @returns a pointer to the destination mac, (or NULL if there is no 355 335 * destination MAC) 356 336 * @author Perry Lorier 357 337 */ 358 uint8_t *get_destination_mac(struct libtrace_t *libtrace, 359 void *buffer, 360 int buflen); 338 uint8_t *trace_get_destination_mac(struct libtrace_packet_t *packet); 361 339 362 340 /** Get the source MAC addres 363 * @param libtrace the libtrace opaque pointer 364 * @param buffer a pointer to a filled in buffer 365 * @param buflen the length of the buffer 341 * @param packet the packet opaque pointer 366 342 * @returns a pointer to the source mac, (or NULL if there is no source MAC) 367 343 * @author Perry Lorier 368 344 */ 369 uint8_t *get_source_mac(struct libtrace_t *libtrace, 370 void *buffer, 371 int buflen); 345 uint8_t *trace_get_source_mac(struct libtrace_packet_t *packet); 372 346 373 347 /** Get the direction flag, if it has one 374 * @param libtrace the libtrace opaque pointer 375 * @param buffer a point to a fille in buffer 376 * @param buflen the length of the buffer 348 * @param packet the packet opaque pointer 377 349 * @returns a signed value containing the direction flag, or -1 if this is not supported 378 350 * @author Daniel Lawson 379 351 */ 380 int8_t get_direction(struct libtrace_t *libtrace, 381 void *buffer, 382 int buflen); 352 int8_t trace_get_direction(struct libtrace_packet_t *packet); 383 353 384 354 /** Event types */ … … 395 365 * TRACE_EVENT_PACKET Packet arrived in <buffer> with size <size> 396 366 */ 397 libtrace_event_t libtrace_event(struct libtrace_t *trace, 398 int *fd,double *seconds, 399 void *buffer, size_t len, int *size); 367 libtrace_event_t trace_event(struct libtrace_packet_t *packet, 368 int *fd,double *seconds); 400 369 401 370 /** setup a BPF filter … … 404 373 * @author Daniel Lawson 405 374 */ 406 struct libtrace_filter_t * libtrace_bpf_setfilter(const char *filterstring);375 struct libtrace_filter_t *trace_bpf_setfilter(const char *filterstring); 407 376 408 377 /** apply a BPF filter 409 * @param libtrace the libtrace opaque pointer 410 * @param filter the filter opaque pointer 411 * @param buffer a pointer to a filled buffer 412 * @param buflen the length of the buffer 378 * @param filter the filter opaque pointer 379 * @param packet the packet opaque pointer 413 380 * @returns the return value from bpf_filter 414 381 * @author Daniel Lawson 415 382 */ 416 int libtrace_bpf_filter(struct libtrace_t *trace, 417 struct libtrace_filter_t *filter, 418 void *buffer, 419 int buflen); 383 int trace_bpf_filter(struct libtrace_filter_t *filter, 384 struct libtrace_packet_t *packet); 420 385 421 386 #ifdef __cplusplus 422 387 } // extern "C" 423 #endif // #ifdef _ cplusplus424 #endif // _LIBTRACE_H_388 #endif // #ifdef __cplusplus 389 #endif // LIBTRACE_H_
Note: See TracChangeset
for help on using the changeset viewer.