Ignore:
Timestamp:
11/23/09 09:59:46 (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:
ff7d949
Parents:
c8e8122
Message:

rewrote the checksum function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/tracereplay/tracereplay.c

    rc8e8122 rc988da9  
    2323#include <libtrace.h>
    2424#include <getopt.h>
     25#include <arpa/inet.h>
    2526
    2627#define FCS_SIZE 4
     28
     29/* This function assumes that the relevant fields have been zeroed out. RFC 1071*/
     30static uint16_t checksum(void * buffer, uint16_t length) {
     31  //printf("length: %d\n",length);
     32  uint32_t sum = 0;
     33  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;
     43
     44  return ~sum;
     45}
     46
    2747
    2848static libtrace_packet_t * per_packet(libtrace_packet_t *packet) {
     
    3555  size_t wire_length = trace_get_wire_length(packet);
    3656
     57  libtrace_ip_t * header;
     58
    3759  if(linktype == TRACE_TYPE_ETH || linktype == TRACE_TYPE_80211) {
    3860    wire_length -= FCS_SIZE;
     
    4062
    4163  trace_construct_packet(new_packet,linktype,pkt_buffer,wire_length);
     64 
     65
     66  header = trace_get_ip(new_packet);
     67  if(header != NULL) {
     68    header -> ip_sum = 0;
     69    header -> ip_sum = htons(checksum(header,header->ip_hl*4));
     70  }
    4271
    4372  return new_packet;
     
    4675
    4776
    48 /* This function assumes that the relevant fields have been zeroed out */
    49 static uint16_t checksum(void * buffer, size_t length) {
    50   uint8_t * data;
    51   int i;
    52   uint16_t result = 0;
    53 
    54 
    55   data = (uint8_t) buffer;
    56 
    57 
    58 
    59   for(i = 0; i < length; i++) {
    60     result = ~data[i];
    61   }
    62  
    63   return ~result;
    64 
    65 }
    6677
    6778static uint32_t event_read_packet(libtrace_t *trace, libtrace_packet_t *packet)
Note: See TracChangeset for help on using the changeset viewer.