- Timestamp:
- 11/25/09 19:28:50 (11 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:
- effd683
- Parents:
- c5fe79a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereplay/tracereplay.c
rc5fe79a r93928b7 27 27 #define FCS_SIZE 4 28 28 29 30 31 29 32 /* This function assumes that the relevant fields have been zeroed out. RFC 1071*/ 30 33 static uint16_t checksum(void * buffer, uint16_t length) { … … 39 42 40 43 if(count > 0) { 41 sum += *buff;44 sum += (*buff << 8); 42 45 } 43 46 44 47 while (sum>>16) 45 48 sum = (sum & 0xffff) + (sum >> 16); 49 printf("%04X\n",sum); 46 50 return ~sum; 47 51 } 48 52 49 static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t * remaining) {50 51 53 static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t length) { 54 55 uint32_t remaining = 0; 52 56 53 57 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 */ 66 void * transportheader = trace_get_payload_from_ip(ip,&proto,remaining); 67 68 printf("l3 payload length: %d\n",*remaining); 58 59 uint16_t protocol = ip->ip_p; 60 61 uint16_t temp; 62 63 sum += ~checksum(&ip->ip_src,sizeof(uint32_t)); 64 sum += ~checksum(&ip->ip_dst,sizeof(uint32_t)); 65 temp = htons(protocol); 66 sum += ~checksum(&temp,sizeof(uint16_t)); 67 temp = htons(length); 68 sum += ~checksum(&temp,sizeof(uint16_t)); 69 70 71 printf("IP payload length: %d\n",length); 72 73 void * transportheader = trace_get_payload_from_ip(ip,NULL,NULL); 69 74 70 75 uint16_t * check = NULL; 71 76 uint16_t tsum = 0; 72 77 73 pseudoheader[0] = (uint32_t) (ip -> ip_src).s_addr; 74 pseudoheader[1] = (uint32_t)(ip -> ip_dst).s_addr; 75 76 other8 = (uint8_t *) &pseudoheader[2]; 77 78 *other8 = 0x00; 79 other8++; 80 *other8 = ip -> ip_p; 81 other8++; 82 83 other16 = (uint16_t *) other8; 84 85 if(proto == 17 ) { 86 printf("udp length: %d\n",sizeof(libtrace_udp_t)); 78 printf("proto: %d\n",ip->ip_p); 79 80 if(protocol == 17 ) { 87 81 libtrace_udp_t * udp_header = transportheader; 88 udp_header -> check = 0;82 printf("udp length: %d\n",ntohs(udp_header -> len)); 89 83 check = &udp_header -> check; 90 *other16 = *remaining + sizeof(libtrace_udp_t); 91 tsum = checksum(transportheader,*remaining + sizeof(libtrace_udp_t)); 92 } 93 else if(proto == 6) { 94 84 *check = 0; 85 printf("l3 payload length: %d\n",length); 86 tsum = checksum(transportheader, length); 87 int odd = 0;//length % 2; 88 } 89 else if(protocol == 6) { 95 90 libtrace_tcp_t * tcp_header = transportheader; 96 91 tcp_header -> check = 0; 97 92 check = &tcp_header -> check; 98 *other16 = *remaining + sizeof(libtrace_tcp_t); 93 99 94 //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); 95 tsum = checksum(transportheader,length); 96 } 97 98 99 printf("tsum: %04X\n", tsum); 100 101 sum = ~tsum; 106 102 107 103 while (sum>>16) … … 140 136 header = trace_get_ip(new_packet); 141 137 if(header != NULL) { 142 wire_length -= sizeof( libtrace_ip_t);138 wire_length -= sizeof(uint32_t)*header->ip_hl; 143 139 header -> ip_sum = 0; 144 140 sum = checksum(header,header->ip_hl*sizeof(uint32_t)); 145 141 header -> ip_sum = sum; 146 udp_tcp_checksum(header,&wire_length); 147 } 148 149 142 udp_tcp_checksum(header,ntohs(header->ip_len) - sizeof(uint32_t)*header->ip_hl); 143 } 150 144 151 145 return new_packet;
Note: See TracChangeset
for help on using the changeset viewer.