- Timestamp:
- 05/03/06 00:38:02 (16 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:
- e5f1431
- Parents:
- ef69a05
- Location:
- lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_pcap.c
r62987bb r81f9b6e 366 366 linktype = rt_to_pcap_dlt(packet->type); 367 367 return pcap_dlt_to_libtrace(linktype); 368 } 369 370 static int8_t pcap_set_direction(libtrace_packet_t *packet,int8_t dir) { 371 libtrace_sll_header_t *sll; 372 promote_packet(packet); 373 sll=packet->payload; 374 if(dir==0) 375 sll->pkttype=0; 376 else 377 sll->pkttype=1; 378 return sll->pkttype; 368 379 } 369 380 … … 518 529 pcap_get_link_type, /* get_link_type */ 519 530 pcap_get_direction, /* get_direction */ 520 NULL,/* set_direction */531 pcap_set_direction, /* set_direction */ 521 532 NULL, /* get_erf_timestamp */ 522 533 pcap_get_timeval, /* get_timeval */ … … 553 564 pcap_get_link_type, /* get_link_type */ 554 565 pcap_get_direction, /* get_direction */ 555 NULL,/* set_direction */566 pcap_set_direction, /* set_direction */ 556 567 NULL, /* get_erf_timestamp */ 557 568 pcap_get_timeval, /* get_timeval */ -
lib/libtrace_int.h
r39e141f r81f9b6e 346 346 void register_format(struct libtrace_format_t *format); 347 347 348 libtrace_linktype_t pcap_dlt_to_libtrace( int dlt);349 charlibtrace_to_pcap_dlt(libtrace_linktype_t type);350 enum rt_field_t pcap_dlt_to_rt( int dlt);351 int rt_to_pcap_dlt(enum rt_field_t rt_type);348 libtrace_linktype_t pcap_dlt_to_libtrace(libtrace_dlt_t dlt); 349 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type); 350 enum rt_field_t pcap_dlt_to_rt(libtrace_dlt_t dlt); 351 libtrace_dlt_t rt_to_pcap_dlt(enum rt_field_t rt_type); 352 352 libtrace_linktype_t erf_type_to_libtrace(char erf); 353 353 char libtrace_to_erf_type(libtrace_linktype_t linktype); 354 355 void promote_packet(libtrace_packet_t *packet); 354 356 355 357 #if HAVE_BPF -
lib/linktypes.c
rda22687 r81f9b6e 7 7 #include "rt_protocol.h" 8 8 #include <assert.h> 9 #include "libtrace_int.h" 10 #include <stdlib.h> 11 #include <net/if_arp.h> 12 #include <string.h> 9 13 10 14 /* This file maps libtrace types to/from pcap DLT and erf types … … 25 29 case TRACE_DLT_PFLOG: return TRACE_TYPE_PFLOG; 26 30 } 27 return -1;31 return ~0; 28 32 } 29 33 30 int libtrace_to_pcap_dlt(libtrace_linktype_t type)34 libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type) 31 35 { 32 36 switch(type) { … … 38 42 case TRACE_TYPE_PFLOG: return TRACE_DLT_PFLOG; 39 43 } 40 return -1;44 return ~0; 41 45 } 42 46 43 enum rt_field_t pcap_dlt_to_rt( int dlt)47 enum rt_field_t pcap_dlt_to_rt(libtrace_dlt_t dlt) 44 48 { 45 49 /* For pcap the rt type is just the dlt + a fixed value */ … … 47 51 } 48 52 49 int rt_to_pcap_dlt(enum rt_field_t rt_type)53 libtrace_dlt_t rt_to_pcap_dlt(enum rt_field_t rt_type) 50 54 { 51 55 assert(rt_type >= RT_DATA_PCAP); … … 61 65 case TYPE_AAL5: return TRACE_TYPE_AAL5; 62 66 } 63 return -1;67 return ~0; 64 68 } 65 69 … … 74 78 return -1; 75 79 } 80 81 /** Tinker with a packet 82 * packets that don't support direction tagging are annoying, especially 83 * when we have direction tagging information! So this converts the packet 84 * to TRACE_TYPE_LINUX_SLL which does support direction tagging. This is a 85 * pcap style packet for the reason that it means it works with bpf filters. 86 * 87 * @note this will copy the packet, so use sparingly if possible. 88 */ 89 void promote_packet(libtrace_packet_t *packet) 90 { 91 if (packet->trace->format->type == TRACE_FORMAT_PCAP) { 92 char *tmpbuffer; 93 libtrace_sll_header_t *hdr; 94 95 switch(pcap_dlt_to_libtrace(rt_to_pcap_dlt(packet->type))) { 96 case TRACE_TYPE_LINUX_SLL: 97 return; /* Unnecessary */ 98 99 case TRACE_TYPE_ETH: 100 /* This should be easy, just prepend the header */ 101 tmpbuffer= malloc(sizeof(libtrace_sll_header_t) 102 +trace_get_capture_length(packet) 103 +trace_get_framing_length(packet) 104 ); 105 106 hdr=(void*)((char*)tmpbuffer 107 +trace_get_framing_length(packet)); 108 109 hdr->pkttype=0; /* "outgoing" */ 110 hdr->hatype = ARPHRD_ETHER; 111 break; 112 default: 113 /* failed */ 114 return; 115 } 116 memcpy(tmpbuffer,packet->header, 117 trace_get_framing_length(packet)); 118 memcpy(tmpbuffer 119 +sizeof(libtrace_sll_header_t) 120 +trace_get_framing_length(packet), 121 packet->payload, 122 trace_get_capture_length(packet)); 123 if (packet->buf_control == TRACE_CTRL_EXTERNAL) { 124 packet->buf_control=TRACE_CTRL_PACKET; 125 } 126 else { 127 free(packet->buffer); 128 } 129 packet->buffer=tmpbuffer; 130 packet->header=tmpbuffer; 131 packet->payload=tmpbuffer+trace_get_framing_length(packet); 132 packet->type=TRACE_TYPE_LINUX_SLL; 133 return; 134 } 135 }
Note: See TracChangeset
for help on using the changeset viewer.