Changeset e4e95499
- Timestamp:
- 04/23/06 17:55:09 (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:
- 12778c2
- Parents:
- 698a217
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
configure.in
r7b2a39b re4e95499 154 154 AC_REPLACE_FUNCS(pcap_dump_flush) 155 155 fi 156 157 AC_CHECK_LIB(pcap,pcap_inject, 158 AC_DEFINE(HAVE_PCAP_INJECT,1,[pcap has pcap_inject]), 159 have_pcap_inject=false) 160 161 AC_CHECK_LIB(pcap,pcap_sendpacket, 162 AC_DEFINE(HAVE_PCAP_SENDPACKET,1,[pcap has pcap_sendpacket]), 163 have_pcap_sendpacket=false) 156 164 fi 157 165 -
lib/format_linux.c
r411f3c7 re4e95499 65 65 }; 66 66 67 struct libtrace_linuxnative_format_data_t { 68 int fd; 69 }; 70 67 71 #define FORMAT(x) ((struct libtrace_format_data_t*)(x)) 72 #define DATAOUT(x) ((struct libtrace_linuxnative_format_data_t*)((x)->format_data)) 68 73 69 74 static int linuxnative_init_input(libtrace_t *libtrace) … … 74 79 FORMAT(libtrace->format_data)->promisc = 0; 75 80 FORMAT(libtrace->format_data)->snaplen = 65536; 81 82 return 0; 83 } 84 85 static int linuxnative_init_output(libtrace_out_t *libtrace) 86 { 87 libtrace->format_data = (struct libtrace_linuxnative_format_data_t*) 88 malloc(sizeof(struct libtrace_linuxnative_format_data_t)); 89 DATAOUT(libtrace)->fd = -1; 76 90 77 91 return 0; … … 122 136 } 123 137 138 static int linuxnative_start_output(libtrace_out_t *libtrace) 139 { 140 FORMAT(libtrace->format_data)->fd = 141 socket(PF_PACKET, SOCK_RAW, 0); 142 if (FORMAT(libtrace->format_data)->fd==-1) { 143 free(libtrace->format_data); 144 return -1; 145 } 146 147 return 0; 148 } 149 124 150 static int linuxnative_pause_input(libtrace_t *libtrace) 125 151 { … … 132 158 static int linuxnative_fin_input(libtrace_t *libtrace) 133 159 { 160 free(libtrace->format_data); 161 return 0; 162 } 163 164 static int linuxnative_fin_output(libtrace_out_t *libtrace) 165 { 166 close(DATAOUT(libtrace)->fd); 167 DATAOUT(libtrace)->fd=-1; 134 168 free(libtrace->format_data); 135 169 return 0; … … 165 199 #define LIBTRACE_MIN(a,b) ((a)<(b) ? (a) : (b)) 166 200 167 static int linuxnative_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 201 static int linuxnative_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 202 { 168 203 struct libtrace_linuxnative_header *hdr; 169 204 socklen_t socklen; … … 201 236 } 202 237 238 static int linuxnative_write_packet(libtrace_out_t *trace, 239 const libtrace_packet_t *packet) 240 { 241 struct sockaddr_ll hdr; 242 243 hdr.sll_family = AF_PACKET; 244 hdr.sll_protocol = 0; 245 hdr.sll_ifindex = if_nametoindex(packet->trace->uridata); 246 hdr.sll_hatype = 0; 247 hdr.sll_pkttype = 0; 248 hdr.sll_halen = 6; /* FIXME */ 249 memcpy(hdr.sll_addr,packet->payload,hdr.sll_halen); 250 251 return sendto(DATAOUT(trace)->fd, 252 packet->payload, 253 trace_get_capture_length(packet), 254 0, 255 (struct sockaddr*)&hdr, sizeof(hdr)); 256 257 } 258 203 259 static libtrace_linktype_t linuxnative_get_link_type(const struct libtrace_packet_t *packet) { 204 260 switch (htons((((struct libtrace_linuxnative_header*)(packet->buffer))->hdr.sll_protocol))) { … … 264 320 linuxnative_start_input, /* start_input */ 265 321 linuxnative_pause_input, /* pause_input */ 266 NULL,/* init_output */322 linuxnative_init_output, /* init_output */ 267 323 NULL, /* config_output */ 268 NULL,/* start_ouput */324 linuxnative_start_output, /* start_ouput */ 269 325 linuxnative_fin_input, /* fin_input */ 270 NULL,/* fin_output */326 linuxnative_fin_output, /* fin_output */ 271 327 linuxnative_read_packet, /* read_packet */ 272 328 NULL, /* fin_packet */ 273 NULL,/* write_packet */329 linuxnative_write_packet, /* write_packet */ 274 330 linuxnative_get_link_type, /* get_link_type */ 275 331 linuxnative_get_direction, /* get_direction */ -
lib/format_pcap.c
r114b8d6 re4e95499 155 155 } 156 156 157 static int pcap_init_output( structlibtrace_out_t *libtrace) {157 static int pcap_init_output(libtrace_out_t *libtrace) { 158 158 libtrace->format_data = malloc(sizeof(struct pcap_format_data_out_t)); 159 159 OUTPUT.trace.pcap = NULL; 160 160 OUTPUT.trace.dump = NULL; 161 161 return 0; 162 } 163 164 static int pcapint_init_output(libtrace_out_t *libtrace) { 165 #ifdef HAVE_PCAP_INJECT 166 libtrace->format_data = malloc(sizeof(struct pcap_format_data_out_t)); 167 OUTPUT.trace.pcap = NULL; 168 OUTPUT.trace.dump = NULL; 169 return 0; 170 #else 171 #ifdef HAVE_PCAP_SENDPACKET 172 libtrace->format_data = malloc(sizeof(struct pcap_format_data_out_t)); 173 OUTPUT.trace.pcap = NULL; 174 OUTPUT.trace.dump = NULL; 175 return 0; 176 #else 177 trace_set_err_out(libtrace,TRACE_ERR_NO_INIT_OUT, 178 "writing not supported by this version of pcap"); 179 return -1; 180 #endif 181 #endif 162 182 } 163 183 … … 237 257 } 238 258 259 static int pcapint_fin_output(libtrace_out_t *libtrace) 260 { 261 pcap_close(OUTPUT.trace.pcap); 262 free(libtrace->format_data); 263 return 0; 264 } 265 239 266 static void trace_pcap_handler(u_char *user, const struct pcap_pkthdr *pcaphdr, const u_char *pcappkt) { 240 267 struct libtrace_packet_t *packet = (struct libtrace_packet_t *)user; … … 260 287 } 261 288 289 /* TODO: use pcap_next_ex() if available */ 262 290 static int pcap_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 263 291 int pcapbytes = 0; … … 315 343 } 316 344 return 0; 345 } 346 347 static int pcapint_write_packet(libtrace_out_t *libtrace, const libtrace_packet_t *packet) { 348 int err; 349 350 if (!OUTPUT.trace.pcap) { 351 OUTPUT.trace.pcap = (pcap_t *)pcap_open_live( 352 libtrace->uridata,65536,0,0,NULL); 353 } 354 #if HAVE_PCAP_INJECT 355 err=pcap_inject(OUTPUT.trace.pcap, 356 packet->payload, 357 trace_get_capture_length(packet)); 358 if (err!=trace_get_capture_length(packet)) 359 err=-1; 360 #else 361 #if HAVE_PCAP_SENDPACKET 362 err=pcap_sendpacket(OUTPUT.trace.pcap, 363 packet->payload, 364 trace_get_capture_length(packet)); 365 #endif 366 #endif 367 return err; 317 368 } 318 369 … … 504 555 pcapint_start_input, /* start_input */ 505 556 pcapint_pause_input, /* pause_input */ 506 NULL,/* init_output */557 pcapint_init_output, /* init_output */ 507 558 NULL, /* config_output */ 508 559 NULL, /* start_output */ 509 560 pcap_fin_input, /* fin_input */ 510 NULL,/* fin_output */561 pcapint_fin_output, /* fin_output */ 511 562 pcap_read_packet, /* read_packet */ 512 563 NULL, /* fin_packet */ 513 NULL,/* write_packet */564 pcapint_write_packet, /* write_packet */ 514 565 pcap_get_link_type, /* get_link_type */ 515 566 pcap_get_direction, /* get_direction */ -
lib/trace.c
r411f3c7 re4e95499 131 131 * format module is sane. 132 132 */ 133 #if 0133 #if 1 134 134 if (f->init_input) { 135 135 #define REQUIRE(x) \
Note: See TracChangeset
for help on using the changeset viewer.