Changeset 58e2f74 for tools/tracereplay
- Timestamp:
- 11/25/09 21:52:20 (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:
- 6d9bd23
- Parents:
- effd683
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereplay/tracereplay.c
reffd683 r58e2f74 53 53 static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t length) { 54 54 55 uint32_t remaining = 0;56 57 55 uint32_t sum = 0; 58 59 56 uint16_t protocol = ip->ip_p; 60 61 57 uint16_t temp = 0; 62 63 58 uint16_t * check = NULL; 64 59 uint16_t tsum = 0; 65 60 66 61 67 sum += ~checksum(&ip->ip_src.s_addr,sizeof(uint32_t)); 68 sum += ~checksum(&ip->ip_dst.s_addr,sizeof(uint32_t)); 69 62 sum += (uint16_t) ~checksum(&ip->ip_src.s_addr,sizeof(uint32_t)); 63 sum += (uint16_t) ~checksum(&ip->ip_dst.s_addr,sizeof(uint32_t)); 64 65 66 /*this will be in host order whereas everything else is in network order*/ 70 67 temp = htons(protocol); 71 72 sum += ~checksum(&temp,sizeof(uint16_t)); 73 68 sum += (uint16_t) ~checksum(&temp,sizeof(uint16_t)); 69 70 /*this will be in host order whereas everything else is in network order*/ 74 71 temp = htons(length); 75 sum += ~checksum(&temp,sizeof(uint16_t)); 76 77 78 printf("IP payload length: %d\n",length); 79 72 sum += (uint16_t) ~checksum(&temp,sizeof(uint16_t)); 73 80 74 void * transportheader = trace_get_payload_from_ip(ip,NULL,NULL); 81 82 83 printf("proto: %d\n",ip->ip_p);84 75 85 76 if(protocol == 17 ) { 86 77 libtrace_udp_t * udp_header = transportheader; 87 printf("udp length: %d\n",ntohs(udp_header -> len));88 78 check = &udp_header -> check; 89 79 *check = 0; 90 printf("l3 payload length: %d\n",length);91 80 tsum = checksum(transportheader, length); 92 81 } … … 95 84 tcp_header -> check = 0; 96 85 check = &tcp_header -> check; 97 98 //use tcp header length and datagram length instead 86 *check = 0; 99 87 tsum = checksum(transportheader,length); 100 88 } 101 89 102 103 printf("tsum: %04X\n", tsum); 104 105 sum += ~tsum; 90 sum += (uint16_t) ~tsum; 106 91 107 92 while (sum>>16) 108 93 sum = (sum & 0xffff) + (sum >> 16); 109 94 110 95 if(check != NULL) { 111 96 *check = (uint16_t)~sum; 112 printf("checksum: %04X\n",*check);113 97 } 114 98 … … 129 113 size_t wire_length = trace_get_wire_length(packet); 130 114 131 printf("wire length: %d\n",wire_length);132 133 115 if(linktype == TRACE_TYPE_ETH || linktype == TRACE_TYPE_80211) { 134 116 wire_length -= FCS_SIZE; 135 117 } 136 137 printf("wire length after FCS: %d\n",wire_length);138 118 139 119 trace_construct_packet(new_packet,linktype,pkt_buffer,wire_length); … … 146 126 sum = checksum(header,header->ip_hl*sizeof(uint32_t)); 147 127 header -> ip_sum = sum; 148 udp_tcp_checksum(header,ntohs(header->ip_len) -sizeof(uint32_t)*header->ip_hl);128 udp_tcp_checksum(header,ntohs(header->ip_len)-sizeof(uint32_t)*header->ip_hl); 149 129 } 150 130 … … 211 191 } 212 192 213 /* int main(int argc, char *argv[]) { */214 215 /* /\* uint16_t buffer[] = {0x45,0x00,0x00,0x30, */216 /* 0x3b,0xa9,0x40,0x00, */217 /* 0x6e,0x06,0x44,0x5b, */218 /* 0x25,0xdb,0xef,0x28, */219 /* 0x7d,0xb6,0x6a,0xb1 */220 /* };*\/ */221 222 /* uint8_t buffer[] = {0x00,0x01, */223 /* 0xf2,0x03, */224 /* 0xf4,0xf5, */225 /* 0xf6,0xf7 */226 /* }; */227 228 /* uint16_t checksum = ip_checksum(buffer,8); */229 230 /* printf("checksum: %04X\n",checksum); */231 232 /* } */233 234 235 193 int main(int argc, char *argv[]) { 236 194 … … 325 283 libtrace_packet_t * new = per_packet(packet); 326 284 327 //libtrace_ip_t * header;328 // header = trace_get_ip(new);329 330 //printf("before write: %04X\n",header->ip_sum);331 332 285 if (trace_write_packet(output, new) < 0) { 333 286 trace_perror_output(output, "Writing packet");
Note: See TracChangeset
for help on using the changeset viewer.