Ignore:
Timestamp:
11/25/09 21:52:20 (12 years ago)
Author:
Andreas Löf <andreas.lof@…>
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
Message:

cleaned up code.

Works now.

Might be necessary to change the destination MAC addresses as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/tracereplay/tracereplay.c

    reffd683 r58e2f74  
    5353static void udp_tcp_checksum(libtrace_ip_t *ip, uint32_t length) {
    5454
    55   uint32_t remaining = 0;
    56 
    5755  uint32_t sum = 0;
    58  
    5956  uint16_t protocol = ip->ip_p;
    60 
    6157  uint16_t temp = 0;
    62 
    6358  uint16_t * check = NULL;
    6459  uint16_t tsum = 0;
    6560
    6661
    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*/
    7067  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*/
    7471  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
    8074  void * transportheader = trace_get_payload_from_ip(ip,NULL,NULL);
    81 
    82 
    83   printf("proto: %d\n",ip->ip_p);
    8475
    8576  if(protocol == 17 ) {
    8677    libtrace_udp_t * udp_header = transportheader;
    87     printf("udp  length: %d\n",ntohs(udp_header -> len));
    8878    check = &udp_header -> check;
    8979    *check = 0;
    90     printf("l3 payload length: %d\n",length); 
    9180    tsum = checksum(transportheader, length);
    9281  }
     
    9584    tcp_header -> check = 0;
    9685    check = &tcp_header -> check;
    97 
    98     //use tcp header length and datagram length instead
     86    *check = 0;
    9987    tsum = checksum(transportheader,length);
    10088  }
    10189
    102 
    103   printf("tsum: %04X\n", tsum);
    104 
    105   sum += ~tsum;
     90  sum += (uint16_t) ~tsum;
    10691
    10792  while (sum>>16)
    10893    sum = (sum & 0xffff) + (sum >> 16);
    109  
     94
    11095  if(check != NULL) {
    11196    *check = (uint16_t)~sum;
    112     printf("checksum: %04X\n",*check);
    11397  }
    11498 
     
    129113  size_t wire_length = trace_get_wire_length(packet);
    130114
    131   printf("wire length: %d\n",wire_length);
    132 
    133115  if(linktype == TRACE_TYPE_ETH || linktype == TRACE_TYPE_80211) {
    134116    wire_length -= FCS_SIZE;
    135117  }
    136 
    137   printf("wire length after FCS: %d\n",wire_length);
    138118
    139119  trace_construct_packet(new_packet,linktype,pkt_buffer,wire_length);
     
    146126    sum = checksum(header,header->ip_hl*sizeof(uint32_t));
    147127    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);
    149129  }
    150130
     
    211191}
    212192
    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 
    235193int main(int argc, char *argv[]) {
    236194       
     
    325283                libtrace_packet_t * new = per_packet(packet);
    326284
    327                 //libtrace_ip_t * header;
    328                 //              header = trace_get_ip(new);
    329 
    330                 //printf("before write: %04X\n",header->ip_sum);
    331                
    332285                if (trace_write_packet(output, new) < 0) {
    333286                        trace_perror_output(output, "Writing packet");
Note: See TracChangeset for help on using the changeset viewer.