- Timestamp:
- 04/02/07 21:44:53 (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:
- 11f2df7
- Parents:
- 02bd77e
- Location:
- lib
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_bpf.c
r5361eae r73dd29f 61 61 unsigned int buffersize; 62 62 int remaining; 63 unsigned int dlt;63 unsigned int linktype; 64 64 }; 65 65 … … 151 151 152 152 if (ioctl(FORMATIN(libtrace)->fd, BIOCGDLT, 153 &FORMATIN(libtrace)-> dlt) == -1) {153 &FORMATIN(libtrace)->linktype) == -1) { 154 154 trace_set_err(libtrace,errno,"Failed to retrieve link type"); 155 155 close(FORMATIN(libtrace)->fd); … … 278 278 279 279 /* Find the payload */ 280 /* TODO: Pcap deals with a padded FDDI dlthere */280 /* TODO: Pcap deals with a padded FDDI linktype here */ 281 281 packet->payload=FORMATIN(libtrace)->bufptr+BPFHDR(packet)->bh_hdrlen; 282 282 … … 293 293 294 294 static libtrace_linktype_t bpf_get_link_type(const libtrace_packet_t *packet) { 295 return pcap_ dlt_to_libtrace(FORMATIN(packet->trace)->dlt);295 return pcap_linktype_to_libtrace(FORMATIN(packet->trace)->linktype); 296 296 } 297 297 -
lib/format_pcap.c
rf0c639b r73dd29f 264 264 assert(libtrace->format_data); 265 265 linktype = pcap_datalink(DATA(libtrace)->input.pcap); 266 packet->type = pcap_ dlt_to_rt(linktype);266 packet->type = pcap_linktype_to_rt(linktype); 267 267 268 268 packet->buf_control = TRACE_CTRL_PACKET; … … 314 314 * pop off the top header until it can be converted 315 315 */ 316 while (libtrace_to_pcap_ dlt(trace_get_link_type(packet))==~0U) {316 while (libtrace_to_pcap_linktype(trace_get_link_type(packet))==~0U) { 317 317 if (!demote_packet(packet)) { 318 318 trace_set_err_out(libtrace, … … 323 323 } 324 324 325 325 326 if (!OUTPUT.trace.pcap) { 326 OUTPUT.trace.pcap = pcap_open_dead( 327 libtrace_to_pcap_dlt(trace_get_link_type(packet)), 328 65536); 327 int linktype=libtrace_to_pcap_dlt(trace_get_link_type(packet)); 328 OUTPUT.trace.pcap = pcap_open_dead(linktype,65536); 329 329 if (!OUTPUT.trace.pcap) { 330 trace_set_err_out(libtrace,TRACE_ERR_INIT_FAILED,"Failed to open dead trace: %s\n", 330 trace_set_err_out(libtrace,TRACE_ERR_INIT_FAILED, 331 "Failed to open dead trace: %s\n", 331 332 pcap_geterr(OUTPUT.trace.pcap)); 332 333 } … … 409 410 410 411 static libtrace_linktype_t pcap_get_link_type(const libtrace_packet_t *packet) { 411 /* pcap doesn't store dltin the framing header so we need412 /* pcap doesn't store linktype in the framing header so we need 412 413 * rt to do it for us 413 414 */ 414 int linktype = rt_to_pcap_ dlt(packet->type);415 return pcap_ dlt_to_libtrace(linktype);415 int linktype = rt_to_pcap_linktype(packet->type); 416 return pcap_linktype_to_libtrace(linktype); 416 417 } 417 418 … … 511 512 struct pcap_pkthdr *pcapptr = 0; 512 513 pcapptr = (struct pcap_pkthdr *)packet->header; 513 if (packet->type==pcap_ dlt_to_rt(TRACE_DLT_EN10MB))514 if (packet->type==pcap_linktype_to_rt(TRACE_DLT_EN10MB)) 514 515 return pcapptr->len+4; /* Include the missing FCS */ 515 else if (packet->type==pcap_ dlt_to_rt(TRACE_DLT_IEEE802_11_RADIO)) {516 else if (packet->type==pcap_linktype_to_rt(TRACE_DLT_IEEE802_11_RADIO)) { 516 517 /* If the packet is Radiotap and the flags field indicates 517 518 * that the FCS is not included in the 802.11 frame, then 518 519 * we need to add 4 to the wire-length to account for it. 519 520 */ 520 uint16_t flags; 521 trace_get_wireless_flags(trace_get_link(packet), trace_get_link_type(packet), &flags); 521 uint8_t flags; 522 trace_get_wireless_flags(trace_get_link(packet), 523 trace_get_link_type(packet), &flags); 522 524 if ((flags & TRACE_RADIOTAP_F_FCS) == 0) 523 525 return pcapptr->len + 4; -
lib/format_pcapfile.c
rf0c639b r73dd29f 212 212 assert(libtrace->format_data); 213 213 214 packet->type = pcap_ dlt_to_rt(swapl(libtrace,214 packet->type = pcap_linktype_to_rt(swapl(libtrace, 215 215 DATA(libtrace)->header.network)); 216 216 … … 268 268 * pop off the top header until it can be converted 269 269 */ 270 while (libtrace_to_pcap_ dlt(trace_get_link_type(packet))==~0U) {270 while (libtrace_to_pcap_linktype(trace_get_link_type(packet))==~0U) { 271 271 if (!demote_packet(packet)) { 272 272 trace_set_err_out(out, … … 297 297 pcaphdr.snaplen = 65536; 298 298 pcaphdr.network = 299 libtrace_to_pcap_ dlt(trace_get_link_type(packet));299 libtrace_to_pcap_linktype(trace_get_link_type(packet)); 300 300 301 301 libtrace_io_write(DATAOUT(out)->file, &pcaphdr, sizeof(pcaphdr)); … … 338 338 { 339 339 #if 0 340 return pcap_ dlt_to_libtrace(340 return pcap_linktype_to_libtrace( 341 341 swapl(packet->trace, 342 342 DATA(packet->trace)->header.network … … 344 344 ); 345 345 #endif 346 return pcap_ dlt_to_libtrace(rt_to_pcap_dlt(packet->type));346 return pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type)); 347 347 } 348 348 … … 429 429 libtrace_pcapfile_pkt_hdr_t *pcapptr 430 430 = (libtrace_pcapfile_pkt_hdr_t *)packet->header; 431 if (packet->type==pcap_ dlt_to_rt(TRACE_DLT_EN10MB))431 if (packet->type==pcap_linktype_to_rt(TRACE_DLT_EN10MB)) 432 432 /* Include the missing FCS */ 433 433 return swapl(packet->trace,pcapptr->wirelen)+4; 434 else if (packet->type==pcap_ dlt_to_rt(TRACE_DLT_IEEE802_11_RADIO)) {434 else if (packet->type==pcap_linktype_to_rt(TRACE_DLT_IEEE802_11_RADIO)) { 435 435 /* If the packet is Radiotap and the flags field indicates 436 436 * that the FCS is not included in the 802.11 frame, then -
lib/libtrace.h.in
r3ec29a9 r73dd29f 203 203 }; 204 204 205 /** Enumeration of DLT types supported by libtrace 206 * These aren't actually DLTs, but LINKTYPE_'s, so becareful when modifying 207 * this. 208 */ 205 /** Enumeration of DLT supported by libtrace 206 */ 209 207 typedef enum { 210 208 TRACE_DLT_NULL = 0, … … 212 210 TRACE_DLT_PPP = 9, 213 211 TRACE_DLT_ATM_RFC1483 = 11, 214 TRACE_DLT_RAW = 101, 212 /* Sigh. This is handled in files with LINKTYPE's */ 213 #ifdef __OpenBSD__ 214 TRACE_DLT_RAW = 14, 215 #else 216 TRACE_DLT_RAW = 12, 217 #endif 218 TRACE_DLT_LINKTYPE_RAW = 101, 215 219 TRACE_DLT_IEEE802_11 = 105, 216 220 TRACE_DLT_LINUX_SLL = 113, -
lib/libtrace_int.h
re01a738 r73dd29f 361 361 void register_format(struct libtrace_format_t *format); 362 362 363 libtrace_linktype_t pcap_dlt_to_libtrace(libtrace_dlt_t dlt); 364 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type); 365 libtrace_rt_types_t pcap_dlt_to_rt(libtrace_dlt_t dlt); 366 libtrace_dlt_t rt_to_pcap_dlt(libtrace_rt_types_t rt_type); 363 libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_linktype_t linktype); 364 libtrace_linktype_t libtrace_to_pcap_linktype(libtrace_linktype_t type); 365 libtrace_linktype_t libtrace_to_pcap_dlt(libtrace_linktype_t type); 366 libtrace_rt_types_t pcap_linktype_to_rt(libtrace_linktype_t linktype); 367 libtrace_linktype_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type); 367 368 libtrace_linktype_t erf_type_to_libtrace(uint8_t erf); 368 369 uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype); -
lib/linktypes.c
rbe22b51 r73dd29f 32 32 */ 33 33 34 libtrace_linktype_t pcap_dlt_to_libtrace(libtrace_dlt_t dlt) 35 { 36 switch(dlt) { 37 case TRACE_DLT_RAW: return TRACE_TYPE_NONE; 34 libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype) 35 { 36 switch(linktype) { 37 case TRACE_DLT_RAW: 38 case TRACE_DLT_LINKTYPE_RAW: return TRACE_TYPE_NONE; 38 39 case TRACE_DLT_EN10MB: return TRACE_TYPE_ETH; 39 40 case TRACE_DLT_IEEE802_11: return TRACE_TYPE_80211; … … 53 54 } 54 55 55 56 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type) 56 libtrace_linktype_t libtrace_to_pcap_dlt(libtrace_linktype_t type) 57 57 { 58 58 /* If pcap doesn't have a DLT, you can either ask pcap to register … … 61 61 */ 62 62 switch(type) { 63 case TRACE_TYPE_NONE: return TRACE_DLT_RAW; 63 case TRACE_TYPE_NONE: return TRACE_DLT_RAW; 64 64 case TRACE_TYPE_ETH: return TRACE_DLT_EN10MB; 65 65 case TRACE_TYPE_80211: return TRACE_DLT_IEEE802_11; … … 93 93 } 94 94 95 libtrace_rt_types_t pcap_dlt_to_rt(libtrace_dlt_t dlt) 96 { 97 /* For pcap the rt type is just the dlt + a fixed value */ 98 return dlt + TRACE_RT_DATA_DLT; 99 } 100 101 libtrace_dlt_t rt_to_pcap_dlt(libtrace_rt_types_t rt_type) 95 libtrace_linktype_t libtrace_to_pcap_linktype(libtrace_linktype_t type) 96 { 97 return pcap_dlt_to_pcap_linktype(libtrace_to_pcap_dlt(type)); 98 } 99 100 static libtrace_dlt_t pcap_dlt_to_pcap_linktype(libtrace_dlt_t linktype) 101 { 102 switch (linktype) { 103 case TRACE_DLT_RAW: return TRACE_DLT_LINKTYPE_RAW; 104 default: 105 return linktype; 106 } 107 } 108 109 libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype) 110 { 111 /* For pcap the rt type is just the linktype + a fixed value */ 112 return pcap_dlt_to_pcap_linktype(linktype) + TRACE_RT_DATA_DLT; 113 } 114 115 libtrace_linktype_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type) 102 116 { 103 117 assert(rt_type >= TRACE_RT_DATA_DLT); … … 173 187 libtrace_sll_header_t *hdr; 174 188 175 if (pcap_ dlt_to_libtrace(rt_to_pcap_dlt(packet->type))189 if (pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type)) 176 190 == TRACE_TYPE_LINUX_SLL) { 177 191 /* This is already been promoted, so ignore it */ … … 192 206 hdr->pkttype=TRACE_SLL_OUTGOING; 193 207 194 switch(pcap_ dlt_to_libtrace(rt_to_pcap_dlt(packet->type))) {208 switch(pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type))) { 195 209 case TRACE_TYPE_NONE: 196 210 trace_get_payload_from_link( … … 226 240 packet->header=tmpbuffer; 227 241 packet->payload=tmpbuffer+trace_get_framing_length(packet); 228 packet->type=pcap_ dlt_to_rt(TRACE_DLT_LINUX_SLL);242 packet->type=pcap_linktype_to_rt(TRACE_DLT_LINUX_SLL); 229 243 ((struct libtrace_pcapfile_pkt_hdr_t*) packet->header)->caplen+= 230 244 sizeof(libtrace_sll_header_t); … … 277 291 packet->header=tmp; 278 292 packet->payload=tmp+sizeof(libtrace_pcapfile_pkt_hdr_t); 279 packet->type=pcap_ dlt_to_rt(TRACE_DLT_ATM_RFC1483);293 packet->type=pcap_linktype_to_rt(TRACE_DLT_ATM_RFC1483); 280 294 281 295 if (trace == NULL) { … … 291 305 ->hatype)) { 292 306 case ARPHRD_PPP: 293 packet->type=pcap_ dlt_to_rt(TRACE_DLT_RAW);307 packet->type=pcap_linktype_to_rt(TRACE_DLT_RAW); 294 308 break; 295 309 case ARPHRD_ETHER: 296 packet->type=pcap_ dlt_to_rt(TRACE_DLT_EN10MB);310 packet->type=pcap_linktype_to_rt(TRACE_DLT_EN10MB); 297 311 break; 298 312 default: -
lib/trace.c
re01a738 r73dd29f 1490 1490 memcpy(packet->header,&hdr,sizeof(hdr)); 1491 1491 memcpy(packet->payload,data,(size_t)len); 1492 packet->type=pcap_ dlt_to_rt(libtrace_to_pcap_dlt(linktype));1493 } 1492 packet->type=pcap_linktype_to_rt(libtrace_to_pcap_linktype(linktype)); 1493 }
Note: See TracChangeset
for help on using the changeset viewer.