- Timestamp:
- 02/23/05 11:45:44 (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:
- b06e535
- Parents:
- cb8c1b9
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libtrace.h
r488432b r68667ee 248 248 struct libtrace_tcp *trace_get_tcp(struct libtrace_packet_t *packet); 249 249 250 /** get a pointer to the TCP header (if any) given a pointer to the IP header 251 * @param ip The IP header 252 * @param[out] skipped An output variable of the number of bytes skipped 253 * 254 * @returns a pointer to the TCP header, or NULL if this is not a TCP packet 255 * 256 * Skipped can be NULL, in which case it will be ignored by the program. 257 * 258 * @author Perry Lorier 259 */ 260 struct libtrace_tcp *trace_get_tcp_from_ip(struct libtrace_ip *ip,int *skipped); 261 250 262 /** get a pointer to the UDP header (if any) 251 263 * @param packet the packet opaque pointer … … 255 267 struct libtrace_udp *trace_get_udp(struct libtrace_packet_t *packet); 256 268 269 /** get a pointer to the UDP header (if any) given a pointer to the IP header 270 * @param ip The IP header 271 * @param[out] skipped An output variable of the number of bytes skipped 272 * 273 * @returns a pointer to the UDP header, or NULL if this is not an UDP packet 274 * 275 * Skipped may be NULL, in which case it will be ignored by this function. 276 */ 277 struct libtrace_udp *trace_get_udp_from_ip(struct libtrace_ip *ip,int *skipped); 278 257 279 /** get a pointer to the ICMP header (if any) 258 280 * @param packet the packet opaque pointer … … 261 283 */ 262 284 struct libtrace_icmp *trace_get_icmp(struct libtrace_packet_t *packet); 285 286 /** get a pointer to the ICMP header (if any) given a pointer to the IP header 287 * @param ip The IP header 288 * @param[out] skipped An output variable of the number of bytes skipped 289 * 290 * @returns a pointer to the ICMP header, or NULL if this is not an ICMP packet 291 * 292 * Skipped may be NULL, in which case it will be ignored by this function 293 */ 294 struct libtrace_icmp *trace_get_icmp_from_ip(struct libtrace_ip *ip,int *skipped); 295 296 /** parse an ip or tcp option 297 * @param[in,out] ptr the pointer to the current option 298 * @param[in,out] len the length of the remaining buffer 299 * @param[out] type the type of the option 300 * @param[out] optlen the length of the option 301 * @param[out] data the data of the option 302 * 303 * @returns bool true if there is another option (and the fields are filled in) 304 * or false if this was the last option. 305 * 306 * This updates ptr to point to the next option after this one, and updates 307 * len to be the number of bytes remaining in the options area. Type is updated 308 * to be the code of this option, and data points to the data of this option, 309 * with optlen saying how many bytes there are. 310 * 311 * @note Beware of fragmented packets. 312 */ 313 int trace_get_next_option(unsigned char **ptr,int *len, 314 unsigned char *type, 315 unsigned char *optlen, 316 unsigned char **data); 317 263 318 264 319 /** Get the current time in DAG time format … … 269 324 * @author Daniel Lawson 270 325 */ 271 uint64_t trace_get_erf_timestamp( struct libtrace_packet_t *packet);326 uint64_t trace_get_erf_timestamp(const struct libtrace_packet_t *packet); 272 327 273 328 /** Get the current time in struct timeval … … 278 333 * @author Perry Lorier 279 334 */ 280 struct timeval trace_get_timeval( struct libtrace_packet_t *packet);335 struct timeval trace_get_timeval(const struct libtrace_packet_t *packet); 281 336 282 337 /** Get the current time in floating point seconds … … 286 341 * @author Perry Lorier 287 342 */ 288 double trace_get_seconds( struct libtrace_packet_t *packet);343 double trace_get_seconds(const struct libtrace_packet_t *packet); 289 344 290 345 /** Get the size of the packet in the trace … … 300 355 */ 301 356 302 int trace_get_capture_length( struct libtrace_packet_t *packet);357 int trace_get_capture_length(const struct libtrace_packet_t *packet); 303 358 304 359 /** Get the size of the packet as it was seen on the wire. … … 311 366 */ 312 367 313 int trace_get_wire_length( struct libtrace_packet_t *packet);368 int trace_get_wire_length(const struct libtrace_packet_t *packet); 314 369 315 370 /** Link layer types … … 330 385 */ 331 386 332 inline libtrace_linktype_t trace_get_link_type( struct libtrace_packet_t *packet);387 inline libtrace_linktype_t trace_get_link_type(const struct libtrace_packet_t *packet); 333 388 334 389 /** Get the destination MAC addres … … 338 393 * @author Perry Lorier 339 394 */ 340 uint8_t *trace_get_destination_mac( struct libtrace_packet_t *packet);395 uint8_t *trace_get_destination_mac(const struct libtrace_packet_t *packet); 341 396 342 397 /** Get the source MAC addres … … 345 400 * @author Perry Lorier 346 401 */ 347 uint8_t *trace_get_source_mac( struct libtrace_packet_t *packet);402 uint8_t *trace_get_source_mac(const, struct libtrace_packet_t *packet); 348 403 349 404 /** Truncate the packet at the suggested length … … 369 424 * @author Daniel Lawson 370 425 */ 371 int8_t trace_get_direction( struct libtrace_packet_t *packet);426 int8_t trace_get_direction(const struct libtrace_packet_t *packet); 372 427 373 428 /** Event types */ … … 378 433 } libtrace_event_t; 379 434 435 /** structure returned by libtrace_event explaining what the current event is */ 380 436 struct libtrace_eventobj_t { 381 libtrace_event_t type; 382 int fd; 383 double seconds; 437 libtrace_event_t type; /**< event type (iowait,sleep,packet */ 438 int fd; /**< if IOWAIT, the fd to sleep on */ 439 double seconds; /**< if SLEEP, the amount of time to sleep for */ 384 440 }; 385 441 -
lib/trace.c
r850630f r68667ee 37 37 * @author Perry Lorier 38 38 * 39 * @internal 39 40 */ 40 41 #define _GNU_SOURCE … … 129 130 130 131 #if HAVE_BPF 132 /** A type encapsulating a bpf filter 133 * This type covers the compiled bpf filter, as well as the original filter 134 * string 135 * 136 */ 131 137 struct libtrace_filter_t { 132 138 struct bpf_insn *filter; … … 135 141 #endif 136 142 143 /** The information about traces that are open 144 * @internal 145 */ 137 146 struct libtrace_t { 138 format_t format; 139 source_t sourcetype; 147 format_t format; /**< The format that this trace is in */ 148 source_t sourcetype; /**< The type (device,file, etc */ 140 149 union { 150 /** Information about rtclients */ 141 151 struct { 142 152 char *hostname; 143 153 short port; 144 154 } rt; 145 char *path; 146 char *interface; 155 char *path; /**< information for local sockets */ 156 char *interface; /**< intormation for reading of network 157 interfaces */ 147 158 } conn_info; 159 /** Information about the current state of the input device */ 148 160 union { 149 161 int fd; … … 925 937 } 926 938 939 /** get a pointer to the TCP header (if any) given a pointer to the IP header 940 * @param ip The IP header 941 * @param[out] skipped An output variable of the number of bytes skipped 942 * 943 * @returns a pointer to the TCP header, or NULL if this is not a TCP packet 944 * 945 * Skipped can be NULL, in which case it will be ignored by the program. 946 */ 947 struct libtrace_tcp *get_tcp_from_ip(struct libtrace_ip *ip, int *skipped) 948 { 949 #define SW_IP_OFFMASK 0xff1f 950 struct libtrace_tcp *tcpptr = 0; 951 952 if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0)) { 953 tcpptr = (struct libtrace_tcp *)((ptrdiff_t)ip+ (ip->ip_hl * 4)); 954 } 955 956 if (skipped) 957 *skipped=(ip->ip_hl*4); 958 959 return tcpptr; 960 } 961 927 962 /** get a pointer to the UDP header (if any) 928 963 * @param packet a pointer to a libtrace_packet structure … … 940 975 udpptr = (struct libtrace_udp *)((ptrdiff_t)ipptr + (ipptr->ip_hl * 4)); 941 976 } 977 942 978 return udpptr; 943 979 } 980 981 /** get a pointer to the UDP header (if any) given a pointer to the IP header 982 * @param ip The IP header 983 * @param[out] skipped An output variable of the number of bytes skipped 984 * 985 * @returns a pointer to the UDP header, or NULL if this is not a UDP packet 986 * 987 * Skipped can be NULL, in which case it will be ignored by the program. 988 */ 989 struct libtrace_udp *get_udp_from_ip(struct libtrace_ip *ip, int *skipped) 990 { 991 struct libtrace_udp *udpptr = 0; 992 993 if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0)) { 994 udpptr = (struct libtrace_udp *)((ptrdiff_t)ip+ (ip->ip_hl * 4)); 995 } 996 997 if (skipped) 998 *skipped=(ip->ip_hl*4); 999 1000 return udpptr; 1001 } 1002 944 1003 945 1004 /** get a pointer to the ICMP header (if any) … … 960 1019 return icmpptr; 961 1020 } 1021 1022 /** get a pointer to the ICMP header (if any) given a pointer to the IP header 1023 * @param ip The IP header 1024 * @param[out] skipped An output variable of the number of bytes skipped 1025 * 1026 * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet 1027 * 1028 * Skipped can be NULL, in which case it will be ignored by the program. 1029 */ 1030 struct libtrace_icmp *get_icmp_from_ip(struct libtrace_ip *ip, int *skipped) 1031 { 1032 struct libtrace_icmp *icmpptr = 0; 1033 1034 if ((ip->ip_p == 6) && ((ip->ip_off & SW_IP_OFFMASK) == 0)) { 1035 icmpptr = (struct libtrace_icmp *)((ptrdiff_t)ip+ (ip->ip_hl * 4)); 1036 } 1037 1038 if (skipped) 1039 *skipped=(ip->ip_hl*4); 1040 1041 return icmpptr; 1042 } 1043 /** parse an ip or tcp option 1044 * @param[in,out] ptr the pointer to the current option 1045 * @param[in,out] len the length of the remaining buffer 1046 * @param[out] type the type of the option 1047 * @param[out] optlen the length of the option 1048 * @param[out] data the data of the option 1049 * 1050 * @returns bool true if there is another option (and the fields are filled in) 1051 * or false if this was the last option. 1052 * 1053 * This updates ptr to point to the next option after this one, and updates 1054 * len to be the number of bytes remaining in the options area. Type is updated 1055 * to be the code of this option, and data points to the data of this option, 1056 * with optlen saying how many bytes there are. 1057 * 1058 * @note Beware of fragmented packets. 1059 * @author Perry Lorier 1060 */ 1061 int trace_get_next_option(unsigned char **ptr,int *len, 1062 unsigned char *type, 1063 unsigned char *optlen, 1064 unsigned char **data) 1065 { 1066 if (*len<=0) 1067 return 0; 1068 *type=**ptr; 1069 switch(*type) { 1070 case 0: /* End of options */ 1071 return 0; 1072 case 1: /* Pad */ 1073 (*ptr)++; 1074 (*len)--; 1075 return 1; 1076 default: 1077 *optlen = *(*ptr+1); 1078 if (*optlen<2) 1079 return 0; // I have no idea wtf is going on 1080 // with these packets 1081 (*len)-=*optlen; 1082 (*data)=(*ptr+2); 1083 (*ptr)+=*optlen; 1084 if (*len<0) 1085 return 0; 1086 return 1; 1087 } 1088 assert(0); 1089 } 1090 962 1091 963 1092 /** Get the current time in DAG time format … … 1244 1373 * @param packet the libtrace_packet opaque pointer 1245 1374 * @returns 1246 * TRACE_EVENT_IOWAIT Waiting on I/O on <fd>1247 * TRACE_EVENT_SLEEP Next event in <seconds>1248 * TRACE_EVENT_PACKET Packet arrived in <buffer> with size <size>1375 * TRACE_EVENT_IOWAIT Waiting on I/O on fd 1376 * TRACE_EVENT_SLEEP Next event in seconds 1377 * TRACE_EVENT_PACKET Packet arrived in buffer with size size 1249 1378 * FIXME currently keeps a copy of the packet inside the trace pointer, 1250 1379 * which in turn is stored inside the new packet object...
Note: See TracChangeset
for help on using the changeset viewer.