Changeset 277442c
- Timestamp:
- 07/16/04 17:48:50 (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:
- bb313ef
- Parents:
- 27615e9
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile
r7acdf97 r277442c 11 11 CURRENT=1 12 12 AGE=0 13 REVISION= 513 REVISION=8 14 14 15 15 INCLIBS=/usr/local/wand/lib/libzl.a /usr/local/wand/lib/libpcapl.a -
lib/trace.c
r14a9d05 r277442c 230 230 * 231 231 * Valid URI's are: 232 * - erf:/path/to/erf/file 233 * - erf:/path/to/erf/file.gz 234 * - erf:/path/to/rtclient/socket 235 * - erf:- (stdin) 236 * - dag:/dev/dagcard (not implementd) 237 * - pcap:pcapinterface (eg: pcap:eth0) 238 * - pcap:/path/to/pcap/file 239 * - pcap:/path/to/pcap/file.gz 240 * - pcap:/path/to/pcap/socket (not implemented) 241 * - pcap:- 242 * - rtclient:hostname 243 * - rtclient:hostname:port 244 * - wag:/path/to/wag/file 245 * - wag:/path/to/wag/file.gz 246 * - wag:/path/to/wag/socket 247 * - wag:/dev/device 248 * 249 * If an error occured why attempting to open the trace file, NULL is returned 250 * and an error is output to stdout. 232 * erf:/path/to/erf/file 233 * erf:/path/to/erf/file.gz 234 * erf:/path/to/rtclient/socket 235 * erf:- (stdin) 236 * pcap:pcapinterface (eg: pcap:eth0) 237 * pcap:/path/to/pcap/file 238 * pcap:/path/to/pcap/file.gz 239 * pcap:- 240 * rtclient:hostname 241 * rtclient:hostname:port 242 * wag:- 243 * wag:/path/to/wag/file 244 * wag:/path/to/wag/file.gz 245 * wag:/path/to/wag/socket 246 * wag:/dev/device 247 * 248 * URIs which have yet to be implemented are: 249 * dag:/dev/dagcard 250 * pcap:/path/to/pcap/socket 251 * 252 * If an error occured when attempting to open a trace, NULL is returned 253 * and an error is output to stdout. 251 254 */ 252 255 struct libtrace_t *create_trace(char *uri) { … … 407 410 * @param buffer the buffer to read into 408 411 * @param len the length of the buffer 412 * @param status a pointer to the status byte 409 413 * @returns number of bytes copied. 410 414 * … … 529 533 case DAG: 530 534 case RTCLIENT: 531 // DAG people are insane, deal with ethernet having532 // some extra padding and crap533 535 if (get_link_type(libtrace,buffer,buflen)==TRACE_TYPE_ETH) 534 ethptr = ((uint8_t *)buffer + 16 + 2); 536 ethptr = ((uint8_t *)buffer + 537 dag_record_size + 2); 535 538 else 536 ethptr = ((uint8_t *)buffer + 16 + 2); 539 ethptr = ((uint8_t *)buffer + 540 dag_record_size + 2); 537 541 break; 538 542 case PCAPINT: … … 801 805 case PCAP: 802 806 pcapptr = (struct pcap_pkthdr *)buffer; 803 return ntohs(pcapptr->caplen); 807 //return ntohs(pcapptr->caplen); 808 return pcapptr->caplen; 804 809 case WAGINT: 805 810 case WAG: … … 963 968 964 969 /** process a libtrace event 970 * @param libtrace the libtrace opaque pointer 971 * @param fd a pointer to a file descriptor to listen on 972 * @param seconds a pointer the time in seconds since to the next event 973 * @param buffer a pointer to a filled in buffer 974 * @param len the length of the buffer 975 * @param size the size of the event 965 976 * @returns 966 977 * TRACE_EVENT_IOWAIT Waiting on I/O on <fd> 967 978 * TRACE_EVENT_SLEEP Next event in <seconds> 968 979 * TRACE_EVENT_PACKET Packet arrived in <buffer> with size <size> 969 */ 970 libtrace_event_t libtrace_event(struct libtrace_t *trace, 980 * @author Perry Lorier 981 */ 982 libtrace_event_t libtrace_event(struct libtrace_t *libtrace, 971 983 int *fd,double *seconds, 972 void *buffer, int *size)984 void *buffer, size_t len, int *size) 973 985 { 974 986 *seconds = 0; 975 987 *fd = 0; 976 988 /* Is there a packet ready? */ 977 switch ( trace->sourcetype) {989 switch (libtrace->sourcetype) { 978 990 case INTERFACE: 979 991 { 980 992 int data; 981 *fd = pcap_fileno( trace->input.pcap);993 *fd = pcap_fileno(libtrace->input.pcap); 982 994 if(ioctl(*fd,FIONREAD,&data)==-1){ 983 995 perror("ioctl(FIONREAD)"); … … 993 1005 { 994 1006 int data; 995 if(ioctl( trace->input.fd,FIONREAD,&data)==-1){1007 if(ioctl(libtrace->input.fd,FIONREAD,&data)==-1){ 996 1008 perror("ioctl(FIONREAD)"); 997 1009 } … … 999 1011 return TRACE_EVENT_PACKET; 1000 1012 } 1001 *fd = trace->input.fd;1013 *fd = libtrace->input.fd; 1002 1014 return TRACE_EVENT_IOWAIT; 1003 1015 } … … 1008 1020 double ts; 1009 1021 /* "Prime" the pump */ 1010 if (!trace->packet.buffer) { 1011 trace->packet.buffer = malloc(4096); 1012 trace->packet.size=libtrace_read_packet(trace, 1013 trace->packet.buffer, 1022 if (!libtrace->packet.buffer) { 1023 libtrace->packet.buffer = malloc(4096); 1024 libtrace->packet.size= 1025 libtrace_read_packet(libtrace, 1026 libtrace->packet.buffer, 1014 1027 4096, 1015 1028 &status); 1016 1029 } 1017 ts=get_seconds( trace,1018 trace->packet.buffer,1019 trace->packet.size);1020 if ( trace->last_ts!=0) {1021 *seconds = ts - trace->last_ts;1022 if (*seconds>time(NULL)- trace->start_ts)1030 ts=get_seconds(libtrace, 1031 libtrace->packet.buffer, 1032 libtrace->packet.size); 1033 if (libtrace->last_ts!=0) { 1034 *seconds = ts - libtrace->last_ts; 1035 if (*seconds>time(NULL)-libtrace->start_ts) 1023 1036 return TRACE_EVENT_SLEEP; 1024 1037 } 1025 1038 else { 1026 trace->start_ts = time(NULL);1027 trace->last_ts = ts;1028 } 1029 1030 *size = trace->packet.size;1031 memcpy(buffer, trace->packet.buffer,*size);1032 1033 free( trace->packet.buffer);1034 trace->packet.buffer = 0;1039 libtrace->start_ts = time(NULL); 1040 libtrace->last_ts = ts; 1041 } 1042 1043 *size = libtrace->packet.size; 1044 memcpy(buffer,libtrace->packet.buffer,*size); 1045 1046 free(libtrace->packet.buffer); 1047 libtrace->packet.buffer = 0; 1035 1048 return TRACE_EVENT_PACKET; 1036 1049 } … … 1050 1063 struct libtrace_filter_t *filter = malloc(sizeof(struct libtrace_filter_t)); 1051 1064 filter->filterstring = strdup(filterstring); 1065 filter->filter = 0; 1052 1066 return filter; 1053 1067 } … … 1061 1075 * @author Daniel Lawson 1062 1076 */ 1063 int libtrace_bpf_filter(struct libtrace_t * trace,1077 int libtrace_bpf_filter(struct libtrace_t *libtrace, 1064 1078 struct libtrace_filter_t *filter, 1065 1079 void *buffer, 1066 1080 int buflen) { 1067 1081 1068 int linktype = get_link_type( trace,buffer,buflen);1069 void *linkptr = get_link( trace,buffer,buflen);1070 int clen = get_capture_length( trace,buffer,buflen);1071 assert( trace);1082 int linktype = get_link_type(libtrace,buffer,buflen); 1083 void *linkptr = get_link(libtrace,buffer,buflen); 1084 int clen = get_capture_length(libtrace,buffer,buflen); 1085 assert(libtrace); 1072 1086 assert(filter); 1073 1087 assert(buffer); 1088 assert(linkptr); 1074 1089 1075 1090 … … 1079 1094 1080 1095 switch (linktype) { 1081 case T YPE_ETH:1096 case TRACE_TYPE_ETH: 1082 1097 pcap = pcap_open_dead(DLT_EN10MB, 1500); 1083 1098 break; … … 1097 1112 } 1098 1113 1114 assert(filter->filter); 1115 printf("%d %d\n",clen,ntohs(clen)); 1099 1116 return bpf_filter(filter->filter, linkptr, clen, clen); 1117 1100 1118 } 1101 1119
Note: See TracChangeset
for help on using the changeset viewer.