Changeset fba4ca0 for lib/trace.c
- Timestamp:
- 09/13/05 11:06:34 (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:
- 1e66c64
- Parents:
- d3e4697
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/trace.c
r5bbe424 rfba4ca0 30 30 31 31 32 /* *@file32 /* @file 33 33 * 34 34 * @brief Trace file processing library … … 120 120 121 121 #if HAVE_BPF 122 /* *A type encapsulating a bpf filter122 /* A type encapsulating a bpf filter 123 123 * This type covers the compiled bpf filter, as well as the original filter 124 124 * string … … 151 151 } 152 152 153 /* *Prints help information for libtrace153 /* Prints help information for libtrace 154 154 * 155 155 * Function prints out some basic help information regarding libtrace, … … 166 166 } 167 167 168 /* Prints error information 169 * 170 * Prints out a descriptive error message for the currently set trace_err value 171 */ 168 172 void trace_perror(char *caller) { 169 173 switch (trace_err.err_num) { … … 196 200 #define URI_PROTO_LINE 16 197 201 198 /* *Gets the name of the output format for a given output trace.202 /* Gets the name of the output format for a given output trace. 199 203 * 200 204 * @params libtrace the output trace to get the name of the format for 201 * @returns the output format205 * @returns callee-owned null-terminated char* containing the output format 202 206 * 203 207 */ … … 208 212 } 209 213 210 /** Create a trace file from a URI 211 * 214 /* Create a trace file from a URI 215 * 216 * @params char * containing a valid libtrace URI 212 217 * @returns opaque pointer to a libtrace_t 213 218 * … … 217 222 * erf:/path/to/rtclient/socket 218 223 * erf:- (stdin) 224 * dag:/dev/dagcard 219 225 * pcapint:pcapinterface (eg: pcapint:eth0) 220 226 * pcap:/path/to/pcap/file … … 226 232 * wag:/path/to/wag/file.gz 227 233 * wag:/path/to/wag/socket 228 * wagint:/dev/device229 *230 * URIs which have yet to be implemented are:231 * dag:/dev/dagcard232 * pcap:/path/to/pcap/socket233 234 * 234 235 * If an error occured when attempting to open a trace, NULL is returned … … 293 294 } 294 295 296 /* Creates a "dummy" trace file that has only the format type set. 297 * 298 * @returns opaque pointer to a (sparsely initialised) libtrace_t 299 * 300 * IMPORTANT: Do not attempt to call trace_read_packet or other such functions with 301 * the dummy trace. Its intended purpose is to act as a packet->trace for libtrace_packet_t's 302 * that are not associated with a libtrace_t structure. 303 */ 295 304 struct libtrace_t * trace_create_dead (char *uri) { 296 305 struct libtrace_t *libtrace = malloc(sizeof(struct libtrace_t)); … … 327 336 328 337 } 329 330 /** Creates a libtrace_out_t structure and the socket / file through which output will be directed. 331 * 332 * @param uri the uri string describing the output format and the destination 333 * @returns the newly created libtrace_out_t structure 334 * 338 339 /** Creates a trace output file from a URI. 340 * 341 * @param uri the uri string describing the output format and destination 342 * @returns opaque pointer to a libtrace_output_t 335 343 * @author Shane Alcock 336 * */ 344 * 345 * Valid URI's are: 346 * - gzerf:/path/to/erf/file.gz 347 * - gzerf:/path/to/erf/file 348 * - rtserver:hostname 349 * - rtserver:hostname:port 350 * 351 * If an error occured when attempting to open the output trace, NULL is returned 352 * and trace_errno is set. Use trace_perror() to get more information 353 */ 354 337 355 struct libtrace_out_t *trace_output_create(char *uri) { 338 356 struct libtrace_out_t *libtrace = malloc(sizeof(struct libtrace_out_t)); … … 388 406 } 389 407 390 /* *Parses an output options string and calls the appropriate function to deal with output options.408 /* Parses an output options string and calls the appropriate function to deal with output options. 391 409 * 392 410 * @param libtrace the output trace object to apply the options to … … 415 433 } 416 434 417 /* *Close a trace file, freeing up any resources it may have been using435 /* Close a trace file, freeing up any resources it may have been using 418 436 * 419 437 */ … … 432 450 free(libtrace); 433 451 } 434 /* *Close an output trace file, freeing up any resources it may have been using452 /* Close an output trace file, freeing up any resources it may have been using 435 453 * 436 454 * @param libtrace the output trace file to be destroyed … … 446 464 } 447 465 448 /* *Read one packet from the trace into buffer466 /* Read one packet from the trace into buffer 449 467 * 450 468 * @param libtrace the libtrace opaque pointer 451 469 * @param packet the packet opaque pointer 452 * @returns false if it failed to read a packet470 * @returns 0 on EOF, negative value on error 453 471 * 454 472 */ … … 470 488 } 471 489 472 /* *Writes a packet to the specified output490 /* Writes a packet to the specified output 473 491 * 474 492 * @param libtrace describes the output format, destination, etc. … … 488 506 } 489 507 490 /* *get a pointer to the link layer508 /* get a pointer to the link layer 491 509 * @param packet a pointer to a libtrace_packet structure 492 510 * 493 511 * @returns a pointer to the link layer, or NULL if there is no link layer 494 * you should call trace_get_link_type() to find out what type of link layer this is 512 * 513 * @note you should call trace_get_link_type() to find out what type of link layer this is 495 514 */ 496 515 void *trace_get_link(const struct libtrace_packet_t *packet) { … … 503 522 } 504 523 505 /* *get a pointer to the IP header (if any)524 /* get a pointer to the IP header (if any) 506 525 * @param packet a pointer to a libtrace_packet structure 507 526 * … … 542 561 case TRACE_TYPE_ETH: 543 562 { 544 struct ether_header *eth =563 struct libtrace_ether *eth = 545 564 trace_get_link(packet); 546 565 if (!eth) { … … 622 641 #define SW_IP_OFFMASK 0xff1f 623 642 624 /* *get a pointer to the TCP header (if any)643 /* get a pointer to the TCP header (if any) 625 644 * @param packet a pointer to a libtrace_packet structure 626 645 * … … 640 659 } 641 660 642 /* *get a pointer to the TCP header (if any) given a pointer to the IP header661 /* get a pointer to the TCP header (if any) given a pointer to the IP header 643 662 * @param ip The IP header 644 663 * @param[out] skipped An output variable of the number of bytes skipped … … 663 682 } 664 683 665 /* *get a pointer to the UDP header (if any)684 /* get a pointer to the UDP header (if any) 666 685 * @param packet a pointer to a libtrace_packet structure 667 686 * … … 682 701 } 683 702 684 /* *get a pointer to the UDP header (if any) given a pointer to the IP header703 /* get a pointer to the UDP header (if any) given a pointer to the IP header 685 704 * @param ip The IP header 686 705 * @param[out] skipped An output variable of the number of bytes skipped … … 705 724 706 725 707 /* *get a pointer to the ICMP header (if any)726 /* get a pointer to the ICMP header (if any) 708 727 * @param packet a pointer to a libtrace_packet structure 709 728 * … … 723 742 } 724 743 725 /* *get a pointer to the ICMP header (if any) given a pointer to the IP header744 /* get a pointer to the ICMP header (if any) given a pointer to the IP header 726 745 * @param ip The IP header 727 746 * @param[out] skipped An output variable of the number of bytes skipped … … 744 763 return icmpptr; 745 764 } 746 /* *parse an ip or tcp option765 /* parse an ip or tcp option 747 766 * @param[in,out] ptr the pointer to the current option 748 767 * @param[in,out] len the length of the remaining buffer … … 793 812 794 813 795 /* *Get the current time in DAG time format814 /* Get the current time in DAG time format 796 815 * @param packet a pointer to a libtrace_packet structure 797 816 * @returns a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds … … 821 840 } 822 841 823 /* *Get the current time in struct timeval842 /* Get the current time in struct timeval 824 843 * @param packet a pointer to a libtrace_packet structure 825 844 * … … 862 881 } 863 882 864 /* *Get the current time in floating point seconds883 /* Get the current time in floating point seconds 865 884 * @param packet a pointer to a libtrace_packet structure 866 885 * @returns time that this packet was seen in 64bit floating point seconds … … 888 907 } 889 908 890 /* *Get the size of the packet in the trace909 /* Get the size of the packet in the trace 891 910 * @param packet the packet opaque pointer 892 911 * @returns the size of the packet in the trace … … 907 926 } 908 927 909 /* *Get the size of the packet as it was seen on the wire.928 /* Get the size of the packet as it was seen on the wire. 910 929 * @param packet a pointer to a libtrace_packet structure 911 930 * … … 924 943 } 925 944 926 /* *Get the type of the link layer945 /* Get the type of the link layer 927 946 * @param packet a pointer to a libtrace_packet structure 928 947 * @returns libtrace_linktype_t … … 937 956 } 938 957 939 /* *Get the source MAC addres958 /* Get the source MAC addres 940 959 * @param packet a pointer to a libtrace_packet structure 941 960 * @returns a pointer to the source mac, (or NULL if there is no source MAC) … … 945 964 void *link = trace_get_link(packet); 946 965 struct ieee_802_11_header *wifi = link; 947 struct ether_header *ethptr = link;966 struct libtrace_ether *ethptr = link; 948 967 if (!link) 949 968 return NULL; … … 959 978 } 960 979 961 /* *Get the destination MAC addres980 /* Get the destination MAC addres 962 981 * @param packet a libtrace_packet pointer 963 982 * @returns a pointer to the destination mac, (or NULL if there is no … … 968 987 void *link = trace_get_link(packet); 969 988 struct ieee_802_11_header *wifi = link; 970 struct ether_header *ethptr = link;989 struct libtrace_ether *ethptr = link; 971 990 if (!link) 972 991 return NULL; … … 983 1002 984 1003 985 /* *process a libtrace event1004 /* process a libtrace event 986 1005 * @param trace the libtrace opaque pointer 987 1006 * @param packet the libtrace_packet opaque pointer … … 1017 1036 } 1018 1037 1019 /* *setup a BPF filter1038 /* setup a BPF filter 1020 1039 * @param filterstring a char * containing the bpf filter string 1021 1040 * @returns opaque pointer pointer to a libtrace_filter_t object … … 1034 1053 } 1035 1054 1036 /* *apply a BPF filter1055 /* apply a BPF filter 1037 1056 * @param filter the filter opaque pointer 1038 1057 * @param packet the packet opaque pointer … … 1096 1115 } 1097 1116 1098 /* *Set the direction flag, if it has one1117 /* Set the direction flag, if it has one 1099 1118 * @param packet the packet opaque pointer 1100 1119 * @param direction the new direction (0,1,2,3) … … 1110 1129 } 1111 1130 1112 /* *Get the direction flag, if it has one1131 /* Get the direction flag, if it has one 1113 1132 * @param packet a pointer to a libtrace_packet structure 1114 1133 * @returns a signed value containing the direction flag, or -1 if this is not supported … … 1146 1165 port = (struct ports_t *)((ptrdiff_t)ip + (ip->ip_hl * 4)); 1147 1166 1148 return htons(port->src);1167 return ntohs(port->src); 1149 1168 } 1150 1169 … … 1164 1183 port = (struct ports_t *)((ptrdiff_t)ip + (ip->ip_hl * 4)); 1165 1184 1166 return htons(port->dst);1185 return ntohs(port->dst); 1167 1186 } 1168 1187 … … 1282 1301 } 1283 1302 1284 /* *Truncate the packet at the suggested length1303 /* Truncate the packet at the suggested length 1285 1304 * @param packet the packet opaque pointer 1286 1305 * @param size the new length of the packet
Note: See TracChangeset
for help on using the changeset viewer.