Changeset 411f3c7
- Timestamp:
- 04/23/06 13:48:20 (15 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:
- e337363
- Parents:
- 7b2a39b
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_linux.c
rdd2eaee r411f3c7 54 54 struct libtrace_format_data_t { 55 55 int fd; 56 int snaplen; 57 int promisc; 56 58 }; 57 59 … … 59 61 struct timeval ts; 60 62 int wirelen; 63 int caplen; 61 64 struct sockaddr_ll hdr; 62 65 }; … … 64 67 #define FORMAT(x) ((struct libtrace_format_data_t*)(x)) 65 68 66 static int linuxnative_init_input( struct libtrace_t *libtrace) {67 struct sockaddr_ll addr; 69 static int linuxnative_init_input(libtrace_t *libtrace) 70 { 68 71 libtrace->format_data = (struct libtrace_format_data_t *) 69 72 malloc(sizeof(struct libtrace_format_data_t)); 73 FORMAT(libtrace->format_data)->fd = -1; 74 FORMAT(libtrace->format_data)->promisc = 0; 75 FORMAT(libtrace->format_data)->snaplen = 65536; 76 77 return 0; 78 } 79 80 static int linuxnative_start_input(libtrace_t *libtrace) 81 { 82 struct sockaddr_ll addr; 70 83 FORMAT(libtrace->format_data)->fd = 71 84 socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); … … 109 122 } 110 123 111 static int linuxnative_fin_input(struct libtrace_t *libtrace) { 124 static int linuxnative_pause_input(libtrace_t *libtrace) 125 { 112 126 close(FORMAT(libtrace->format_data)->fd); 127 FORMAT(libtrace->format_data)->fd=-1; 128 129 return 0; 130 } 131 132 static int linuxnative_fin_input(libtrace_t *libtrace) 133 { 113 134 free(libtrace->format_data); 114 135 return 0; 115 136 } 116 137 117 static int linuxnative_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 138 static int linuxnative_config_input(libtrace_t *libtrace, 139 trace_option_t option, 140 void *data) 141 { 142 switch(option) { 143 case TRACE_OPTION_SNAPLEN: 144 FORMAT(libtrace->format_data)->snaplen=*(int*)data; 145 return 0; 146 case TRACE_OPTION_PROMISC: 147 FORMAT(libtrace->format_data)->promisc=*(int*)data; 148 return 0; 149 case TRACE_OPTION_FILTER: 150 /* We don't support bpf filters in any special way 151 * so return an error and let libtrace deal with 152 * emulating it 153 */ 154 break; 155 /* Avoid default: so that future options will cause a warning 156 * here to remind us to implement it, or flag it as 157 * unimplementable 158 */ 159 } 160 trace_set_err(libtrace,TRACE_ERR_UNKNOWN_OPTION, 161 "Unknown option %i", option); 162 return -1; 163 } 164 165 #define LIBTRACE_MIN(a,b) ((a)<(b) ? (a) : (b)) 166 167 static int linuxnative_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 118 168 struct libtrace_linuxnative_header *hdr; 119 169 socklen_t socklen; 170 int snaplen; 120 171 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 121 172 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); … … 129 180 hdr=(void*)packet->buffer; 130 181 socklen=sizeof(hdr->hdr); 182 snaplen=LIBTRACE_MIN( 183 (int)LIBTRACE_PACKET_BUFSIZE-(int)sizeof(*hdr), 184 (int)FORMAT(libtrace->format_data)->snaplen); 131 185 hdr->wirelen = recvfrom(FORMAT(libtrace->format_data)->fd, 132 186 (void*)packet->payload, 133 LIBTRACE_PACKET_BUFSIZE-sizeof(*hdr),187 snaplen, 134 188 MSG_TRUNC, 135 189 (void *)&hdr->hdr, … … 138 192 if (hdr->wirelen==-1) 139 193 return -1; 194 195 hdr->caplen=LIBTRACE_MIN(snaplen,hdr->wirelen); 140 196 141 197 if (ioctl(FORMAT(libtrace->format_data)->fd,SIOCGSTAMP,&hdr->ts)==-1) … … 166 222 } 167 223 168 static struct timeval linuxnative_get_timeval(const struct libtrace_packet_t *packet) { 224 static struct timeval linuxnative_get_timeval(const libtrace_packet_t *packet) 225 { 169 226 return ((struct libtrace_linuxnative_header*)(packet->buffer))->ts; 170 227 } 171 228 172 static int linuxnative_get_wire_length(const struct libtrace_packet_t *packet) { 229 static int linuxnative_get_capture_length(const libtrace_packet_t *packet) 230 { 231 return ((struct libtrace_linuxnative_header*)(packet->buffer))->caplen; 232 } 233 234 static int linuxnative_get_wire_length(const libtrace_packet_t *packet) 235 { 173 236 return ((struct libtrace_linuxnative_header*)(packet->buffer))->wirelen; 174 237 } 175 238 176 static int linuxnative_get_framing_length(const struct libtrace_packet_t *packet) { 239 static int linuxnative_get_framing_length(const libtrace_packet_t *packet) 240 { 177 241 return sizeof(struct libtrace_linuxnative_header); 178 242 } … … 197 261 TRACE_FORMAT_LINUX_NATIVE, 198 262 linuxnative_init_input, /* init_input */ 199 NULL,/* config_input */200 NULL,/* start_input */201 NULL,/* pause_input */263 linuxnative_config_input, /* config_input */ 264 linuxnative_start_input, /* start_input */ 265 linuxnative_pause_input, /* pause_input */ 202 266 NULL, /* init_output */ 203 267 NULL, /* config_output */ … … 217 281 NULL, /* seek_timeval */ 218 282 NULL, /* seek_seconds */ 219 NULL,/* get_capture_length */283 linuxnative_get_capture_length, /* get_capture_length */ 220 284 linuxnative_get_wire_length, /* get_wire_length */ 221 285 linuxnative_get_framing_length, /* get_framing_length */ 222 286 NULL, /* set_capture_length */ 223 287 linuxnative_get_fd, /* get_fd */ 224 trace_event_ trace, /* trace_event */288 trace_event_device, /* trace_event */ 225 289 linuxnative_help, /* help */ 226 290 NULL -
lib/trace.c
r7b2a39b r411f3c7 124 124 f->next=formats_list; 125 125 formats_list=f; 126 /* Now, verify things */ 126 /* Now, verify things 127 * This #if can be changed to a 1 to output warnings about inconsistant 128 * functions being provided by format modules. This generally is very 129 * noisy, as almost all modules don't implement one or more functions 130 * for various reasons. This is very useful when checking a new 131 * format module is sane. 132 */ 127 133 #if 0 128 if (f ormat_list[nformats]->init_input) {134 if (f->init_input) { 129 135 #define REQUIRE(x) \ 130 if (!f ormat_list[nformats]->x) \131 fprintf(stderr,"%s: Input format should provide " #x "\n",f ormat_list[nformats]->name)136 if (!f->x) \ 137 fprintf(stderr,"%s: Input format should provide " #x "\n",f->name) 132 138 REQUIRE(read_packet); 133 139 REQUIRE(start_input); 134 REQUIRE(config_input);135 REQUIRE(pause_input);136 140 REQUIRE(fin_input); 137 141 REQUIRE(get_link_type); … … 140 144 REQUIRE(get_framing_length); 141 145 REQUIRE(trace_event); 142 if (!f ormat_list[nformats]->get_erf_timestamp143 && !f ormat_list[nformats]->get_seconds144 && !f ormat_list[nformats]->get_timeval) {146 if (!f->get_erf_timestamp 147 && !f->get_seconds 148 && !f->get_timeval) { 145 149 fprintf(stderr,"%s: A trace format capable of input, should provide at least one of\n" 146 "get_erf_timestamp, get_seconds or trace_timeval\n",format_list[nformats]->name); 147 } 148 if (format_list[nformats]->trace_event==trace_event_device) { 150 "get_erf_timestamp, get_seconds or trace_timeval\n",f->name); 151 } 152 if (f->trace_event!=trace_event_trace) { 153 /* Theres nothing that a trace file could optimise with 154 * config_input 155 */ 156 REQUIRE(pause_input); 157 REQUIRE(config_input); 149 158 REQUIRE(get_fd); 150 159 } 151 160 else { 152 if (f ormat_list[nformats]->get_fd) {161 if (f->get_fd) { 153 162 fprintf(stderr,"%s: Unnecessary get_fd\n", 154 f ormat_list[nformats]->name);163 f->name); 155 164 } 156 165 } … … 159 168 else { 160 169 #define REQUIRE(x) \ 161 if (f ormat_list[nformats]->x) \162 fprintf(stderr,"%s: Non Input format shouldn't need " #x "\n",f ormat_list[nformats]->name)170 if (f->x) \ 171 fprintf(stderr,"%s: Non Input format shouldn't need " #x "\n",f->name) 163 172 REQUIRE(read_packet); 164 173 REQUIRE(start_input); … … 175 184 #undef REQUIRE 176 185 } 177 if (f ormat_list[nformats]->init_output) {186 if (f->init_output) { 178 187 #define REQUIRE(x) \ 179 if (!f ormat_list[nformats]->x) \180 fprintf(stderr,"%s: Output format should provide " #x "\n",f ormat_list[nformats]->name)188 if (!f->x) \ 189 fprintf(stderr,"%s: Output format should provide " #x "\n",f->name) 181 190 REQUIRE(write_packet); 182 191 REQUIRE(start_output); … … 187 196 else { 188 197 #define REQUIRE(x) \ 189 if (f ormat_list[nformats]->x) \190 fprintf(stderr,"%s: Non Output format shouldn't need " #x "\n",f ormat_list[nformats]->name)198 if (f->x) \ 199 fprintf(stderr,"%s: Non Output format shouldn't need " #x "\n",f->name) 191 200 REQUIRE(write_packet); 192 201 REQUIRE(start_output); … … 1350 1359 { 1351 1360 char *buf2 = buf; 1352 staticchar staticbuf[18]={0,};1361 char staticbuf[18]={0,}; 1353 1362 if (!buf2) 1354 1363 buf2=staticbuf;
Note: See TracChangeset
for help on using the changeset viewer.