- Timestamp:
- 10/11/04 13:53:12 (18 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:
- 37d2975
- Parents:
- 4e92740
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libtrace.h
r83e0a25 ref36351d 358 358 TRACE_EVENT_SLEEP, 359 359 TRACE_EVENT_PACKET 360 } libtrace_eventtype_t; 361 362 typedef struct { 363 libtrace_eventtype_t type; 364 int fd; 365 double seconds; 360 366 } libtrace_event_t; 361 367 362 368 /** process a libtrace event 363 * @returns 369 * @param trace the libtrace opaque pointer 370 * @param packet the libtrace_packet opaque pointer 371 * @param fd a pointer to a file descriptor to listen on 372 * @param seconds a pointer the time in seconds since to the next event 373 * @returns libtrace_event struct containing the type, and potential 374 * fd or seconds to sleep on 375 * 376 * Type can be: 364 377 * TRACE_EVENT_IOWAIT Waiting on I/O on <fd> 365 378 * TRACE_EVENT_SLEEP Next event in <seconds> 366 379 * TRACE_EVENT_PACKET Packet arrived in <buffer> with size <size> 367 380 */ 368 libtrace_event_t trace_event(struct libtrace_ packet_t *packet,369 int *fd,double *seconds);381 libtrace_event_t trace_event(struct libtrace_t *trace, 382 struct libtrace_packet_t *packet); 370 383 371 384 /** setup a BPF filter -
lib/trace.c
rb020bb9 ref36351d 1033 1033 1034 1034 /** process a libtrace event 1035 * @param libtrace the libtrace opaque pointer 1035 * @param trace the libtrace opaque pointer 1036 * @param packet the libtrace_packet opaque pointer 1036 1037 * @param fd a pointer to a file descriptor to listen on 1037 1038 * @param seconds a pointer the time in seconds since to the next event 1038 * @param buffer a pointer to a filled in buffer1039 * @param len the length of the buffer1040 * @param size the size of the event1041 1039 * @returns 1042 1040 * TRACE_EVENT_IOWAIT Waiting on I/O on <fd> … … 1048 1046 */ 1049 1047 libtrace_event_t libtrace_event(struct libtrace_t *trace, 1050 struct libtrace_packet_t *packet, 1051 int *fd,double *seconds) { 1052 *seconds = 0; 1053 *fd = 0; 1048 struct libtrace_packet_t *packet) { 1049 libtrace_event_t event; 1054 1050 /* Is there a packet ready? */ 1055 1051 switch (trace->sourcetype) { … … 1057 1053 { 1058 1054 int data; 1059 *fd = pcap_fileno(trace->input.pcap);1060 if(ioctl( *fd,FIONREAD,&data)==-1){1055 event.fd = pcap_fileno(trace->input.pcap); 1056 if(ioctl(event.fd,FIONREAD,&data)==-1){ 1061 1057 perror("ioctl(FIONREAD)"); 1062 1058 } 1063 1059 if (data>0) { 1064 returnTRACE_EVENT_PACKET;1065 } 1066 returnTRACE_EVENT_IOWAIT;1060 event.type = TRACE_EVENT_PACKET; 1061 } 1062 event.type = TRACE_EVENT_IOWAIT; 1067 1063 } 1068 1064 case SOCKET: … … 1075 1071 } 1076 1072 if (data>0) { 1077 returnTRACE_EVENT_PACKET;1078 } 1079 *fd = trace->input.fd;1080 returnTRACE_EVENT_IOWAIT;1073 event.type = TRACE_EVENT_PACKET; 1074 } 1075 event.fd = trace->input.fd; 1076 event.type = TRACE_EVENT_IOWAIT; 1081 1077 } 1082 1078 case STDIN: … … 1092 1088 ts=trace_get_seconds(packet); 1093 1089 if (trace->last_ts!=0) { 1094 *seconds = ts - trace->last_ts;1095 if ( *seconds>time(NULL)-trace->start_ts)1096 returnTRACE_EVENT_SLEEP;1090 event.seconds = ts - trace->last_ts; 1091 if (event.seconds>time(NULL)-trace->start_ts) 1092 event.type = TRACE_EVENT_SLEEP; 1097 1093 } 1098 1094 else { … … 1106 1102 free(trace->packet.buffer); 1107 1103 trace->packet.buffer = 0; 1108 returnTRACE_EVENT_PACKET;1104 event.type = TRACE_EVENT_PACKET; 1109 1105 } 1110 1106 default: 1111 1107 assert(0); 1112 1108 } 1113 /* Shouldn't get here */ 1114 assert(0); 1109 return event; 1115 1110 } 1116 1111
Note: See TracChangeset
for help on using the changeset viewer.