Changeset c5fe79a for tools/tracereplay
- Timestamp:
- 11/24/09 17:50:51 (13 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:
- 93928b7
- Parents:
- 43351e9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereplay/tracereplay.c
r43351e9 rc5fe79a 44 44 while (sum>>16) 45 45 sum = (sum & 0xffff) + (sum >> 16); 46 printf("%04X\n",~sum);47 46 return ~sum; 48 47 } … … 50 49 static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t* remaining) { 51 50 52 uint32_t sum; 53 uint32_t pseudoheader[3]; 54 uint8_t * other8; 55 uint16_t * other16; 56 57 uint8_t proto; 58 51 52 53 uint32_t sum = 0; 54 uint32_t pseudoheader[3] = {0,0,0}; 55 uint8_t * other8 = NULL; 56 uint16_t * other16 = NULL; 57 58 uint8_t proto = 0; 59 60 printf("IP payload length: %d\n",*remaining); 61 62 /* 63 Remaining gets the wrong value here. 64 65 */ 59 66 void * transportheader = trace_get_payload_from_ip(ip,&proto,remaining); 60 67 61 uint16_t * check = 0; 68 printf("l3 payload length: %d\n",*remaining); 69 70 uint16_t * check = NULL; 62 71 uint16_t tsum = 0; 63 72 … … 75 84 76 85 if(proto == 17 ) { 86 printf("udp length: %d\n",sizeof(libtrace_udp_t)); 77 87 libtrace_udp_t * udp_header = transportheader; 78 88 udp_header -> check = 0; 79 89 check = &udp_header -> check; 80 90 *other16 = *remaining + sizeof(libtrace_udp_t); 81 tsum = checksum(transportheader,* other16);91 tsum = checksum(transportheader,*remaining + sizeof(libtrace_udp_t)); 82 92 } 83 93 else if(proto == 6) { 94 84 95 libtrace_tcp_t * tcp_header = transportheader; 85 96 tcp_header -> check = 0; 86 97 check = &tcp_header -> check; 87 98 *other16 = *remaining + sizeof(libtrace_tcp_t); 88 tsum = checksum(transportheader,*other16); 89 } 90 91 sum = ~(~checksum(pseudoheader,3*sizeof(uint32_t)) + ~tsum); 99 //use tcp header length and datagram length instead 100 tsum = checksum(transportheader,*remaining+sizeof(libtrace_tcp_t)); 101 } 102 103 *other16 = *remaining; 104 105 sum = (~checksum(pseudoheader,3*sizeof(uint32_t)) + ~tsum); 92 106 93 107 while (sum>>16) … … 95 109 96 110 if(check != NULL) { 97 *check = (uint16_t) sum;111 *check = (uint16_t)~sum; 98 112 } 99 113 … … 103 117 104 118 static libtrace_packet_t * per_packet(libtrace_packet_t *packet) { 105 uint32_t remaining ;106 libtrace_linktype_t linktype ;119 uint32_t remaining = 0; 120 libtrace_linktype_t linktype = 0; 107 121 void * pkt_buffer = trace_get_packet_buffer(packet,&linktype,&remaining); 108 122 remaining = 0; 123 libtrace_ip_t * header = NULL; 124 uint16_t sum = 0; 109 125 libtrace_packet_t *new_packet = trace_create_packet(); 110 126 111 127 size_t wire_length = trace_get_wire_length(packet); 112 128 113 libtrace_ip_t * header; 114 void * l3_header; 115 uint16_t sum; 116 uint16_t ethertype; 117 118 l3_header = trace_get_layer3(packet, ðertype, &remaining); 129 printf("wire length: %d\n",wire_length); 119 130 120 131 if(linktype == TRACE_TYPE_ETH || linktype == TRACE_TYPE_80211) { 121 132 wire_length -= FCS_SIZE; 122 remaining -= FCS_SIZE; 123 } 133 } 134 135 printf("wire length after FCS: %d\n",wire_length); 124 136 125 137 trace_construct_packet(new_packet,linktype,pkt_buffer,wire_length); 126 138 127 139 128 //header = trace_get_ip(new_packet); 129 //if(header != NULL) { 130 131 l3_header = trace_get_layer3(packet, ðertype, &remaining); 132 if(ethertype == 0x0800) { 133 header = (libtrace_ip_t *) l3_header; 140 header = trace_get_ip(new_packet); 141 if(header != NULL) { 142 wire_length -= sizeof(libtrace_ip_t); 134 143 header -> ip_sum = 0; 135 printf("after zero %04X\n", header -> ip_sum); 136 sum = checksum(l3_header,header->ip_hl*sizeof(uint32_t)); 137 printf("first %04X\n", sum); 144 sum = checksum(header,header->ip_hl*sizeof(uint32_t)); 138 145 header -> ip_sum = sum; 139 printf("final %04X\n", header -> ip_sum); 140 udp_tcp_checksum(header,&remaining); 146 udp_tcp_checksum(header,&wire_length); 141 147 } 142 148 … … 319 325 libtrace_packet_t * new = per_packet(packet); 320 326 327 //libtrace_ip_t * header; 328 // header = trace_get_ip(new); 329 330 //printf("before write: %04X\n",header->ip_sum); 331 321 332 if (trace_write_packet(output, new) < 0) { 322 333 trace_perror_output(output, "Writing packet");
Note: See TracChangeset
for help on using the changeset viewer.