Changeset 43351e9
- Timestamp:
- 11/23/09 17:41:28 (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:
- c5fe79a
- Parents:
- ff7d949
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereplay/tracereplay.c
rff7d949 r43351e9 5 5 specified interface. 6 6 It pads packets with zeroes to reach the original length of the packet 7 and recalculates c rc checksums in ip/tcp/udp headers.7 and recalculates checksums in ip/tcp/udp headers. 8 8 9 9 Authors: Andreas Loef and Yuwei Wang … … 39 39 40 40 if(count > 0) { 41 sum += buff;41 sum += *buff; 42 42 } 43 43 44 44 while (sum>>16) 45 45 sum = (sum & 0xffff) + (sum >> 16); 46 46 printf("%04X\n",~sum); 47 47 return ~sum; 48 48 } 49 49 50 static uint16_t udp_tcp_checksum(libtrace_packet_t *packet) {50 static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t* remaining) { 51 51 52 52 uint32_t sum; 53 54 53 uint32_t pseudoheader[3]; 54 uint8_t * other8; 55 uint16_t * other16; 56 57 uint8_t proto; 58 59 void * transportheader = trace_get_payload_from_ip(ip,&proto,remaining); 60 61 uint16_t * check = 0; 62 uint16_t tsum = 0; 63 64 pseudoheader[0] = (uint32_t) (ip -> ip_src).s_addr; 65 pseudoheader[1] = (uint32_t)(ip -> ip_dst).s_addr; 66 67 other8 = (uint8_t *) &pseudoheader[2]; 68 69 *other8 = 0x00; 70 other8++; 71 *other8 = ip -> ip_p; 72 other8++; 73 74 other16 = (uint16_t *) other8; 75 76 if(proto == 17 ) { 77 libtrace_udp_t * udp_header = transportheader; 78 udp_header -> check = 0; 79 check = &udp_header -> check; 80 *other16 = *remaining + sizeof(libtrace_udp_t); 81 tsum = checksum(transportheader,*other16); 82 } 83 else if(proto == 6) { 84 libtrace_tcp_t * tcp_header = transportheader; 85 tcp_header -> check = 0; 86 check = &tcp_header -> check; 87 *other16 = *remaining + sizeof(libtrace_tcp_t); 88 tsum = checksum(transportheader,*other16); 89 } 90 91 sum = ~(~checksum(pseudoheader,3*sizeof(uint32_t)) + ~tsum); 92 93 while (sum>>16) 94 sum = (sum & 0xffff) + (sum >> 16); 95 96 if(check != NULL) { 97 *check = (uint16_t)sum; 98 } 99 55 100 56 101 } … … 58 103 59 104 static libtrace_packet_t * per_packet(libtrace_packet_t *packet) { 60 61 uint32_t remaining; 105 uint32_t remaining; 62 106 libtrace_linktype_t linktype; 63 107 void * pkt_buffer = trace_get_packet_buffer(packet,&linktype,&remaining); 108 remaining = 0; 64 109 libtrace_packet_t *new_packet = trace_create_packet(); 65 110 66 111 size_t wire_length = trace_get_wire_length(packet); 67 112 68 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); 69 119 70 120 if(linktype == TRACE_TYPE_ETH || linktype == TRACE_TYPE_80211) { 71 121 wire_length -= FCS_SIZE; 122 remaining -= FCS_SIZE; 72 123 } 73 124 … … 75 126 76 127 77 header = trace_get_ip(new_packet); 78 if(header != NULL) { 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; 79 134 header -> ip_sum = 0; 80 header -> ip_sum = checksum(header,header->ip_hl*sizeof(uint32_t)); 81 } 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); 138 header -> ip_sum = sum; 139 printf("final %04X\n", header -> ip_sum); 140 udp_tcp_checksum(header,&remaining); 141 } 142 143 82 144 83 145 return new_packet;
Note: See TracChangeset
for help on using the changeset viewer.