Ignore:
Timestamp:
11/23/09 14:08:03 (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:
43351e9
Parents:
c988da9
Message:

checksums working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/tracereplay/tracereplay.c

    rc988da9 rff7d949  
    2929/* This function assumes that the relevant fields have been zeroed out. RFC 1071*/
    3030static uint16_t checksum(void * buffer, uint16_t length) {
    31   //printf("length: %d\n",length);
    3231  uint32_t sum = 0;
    3332  uint16_t * buff = (uint16_t *) buffer;
    34   uint16_t i;
    35   uint16_t result;
    36 
    37   for (i=0;i<length;i=i+2) {
    38     sum += ~ntohs(buff[i]);
    39   }
    40  
    41   result = sum;
    42   result += sum >> 16;
     33  uint16_t count = length;
     34
     35  while(count > 1 ) {
     36    sum += *buff++;
     37    count = count -2;
     38  }
     39
     40  if(count > 0) {
     41    sum += buff;
     42  }
     43 
     44  while (sum>>16)
     45    sum = (sum & 0xffff) + (sum >> 16);
    4346
    4447  return ~sum;
     48}
     49
     50static uint16_t udp_tcp_checksum(libtrace_packet_t *packet) {
     51
     52  uint32_t sum;
     53
     54
     55
    4556}
    4657
     
    6778  if(header != NULL) {
    6879    header -> ip_sum = 0;
    69     header -> ip_sum = htons(checksum(header,header->ip_hl*4));
     80    header -> ip_sum = checksum(header,header->ip_hl*sizeof(uint32_t));
    7081  }
    7182
     
    132143}
    133144
     145/* int main(int argc, char *argv[]) {  */
     146 
     147/*   /\* uint16_t buffer[] = {0x45,0x00,0x00,0x30, */
     148/*                     0x3b,0xa9,0x40,0x00, */
     149/*                     0x6e,0x06,0x44,0x5b, */
     150/*                     0x25,0xdb,0xef,0x28, */
     151/*                     0x7d,0xb6,0x6a,0xb1 */
     152/*                     };*\/  */
     153
     154/*   uint8_t buffer[] = {0x00,0x01, */
     155/*                    0xf2,0x03, */
     156/*                    0xf4,0xf5, */
     157/*                    0xf6,0xf7 */
     158/*   }; */
     159
     160/*   uint16_t checksum = ip_checksum(buffer,8); */
     161
     162/*   printf("checksum: %04X\n",checksum); */
     163 
     164/* } */
     165
     166
    134167int main(int argc, char *argv[]) {
    135168       
     
    243276
    244277}
     278
Note: See TracChangeset for help on using the changeset viewer.