Ping issue in 1.20+

Ralf Friedl Ralf.Friedl at online.de
Sun Jun 30 23:42:49 UTC 2013


Giovanni Vallesi - TeeBX schrieb:
> Il 28/06/2013 1.04, Denys Vlasenko ha scritto:
>>> Please add debugging prints to inet_cksum() function - for one,
>>> >  let's find out the value of nleft, addr[0], and the return value.
>>> >  (IOW, let's find out whether we checksum over the correct buffer,
>>> >  and whether we produce the same xsum we see in tcpdump.)
>> For example, this way:
>>
>>
>> uint16_t FAST_FUNC inet_cksum(uint16_t *addr, int nleft)
>> {
>>          /*
>>           * Our algorithm is simple, using a 32 bit accumulator,
>>           * we add sequential 16 bit words to it, and at the end, fold
>>           * back all the carry bits from the top 16 bits into the lower
>>           * 16 bits.
>>           */
>>          unsigned sum = 0;
>> char string[nleft*2 + 2];
>> int z = nleft;
>> bin2hex(string, (void*)addr, nleft)[0] = 0;
>>          while (nleft>  1) {
>>                  sum += *addr++;
>>                  nleft -= 2;
>>          }
>>
>>          /* Mop up an odd byte, if necessary */
>>          if (nleft == 1) {
>>                  if (BB_LITTLE_ENDIAN)
>>                          sum += *(uint8_t*)addr;
>>                  else
>>                          sum += *(uint8_t*)addr<<  8;
>>          }
>>
>>          /* Add back carry outs from top 16 bits to low 16 bits */
>>          sum = (sum>>  16) + (sum&  0xffff);     /* add hi 16 to low 
>> 16 */
>>          sum += (sum>>  16);                     /* add carry */
>>
>> bb_error_msg("inet_cksum(%s,%d)=0x%x", string, z, 
>> (unsigned)(uint16_t)~sum);
>>          return (uint16_t)~sum;
>> }
>>
>> When I run it, I see:
>>
>> # ./busybox ping -c2 10.0.0.138
>> PING 10.0.0.138 (10.0.0.138): 56 data bytes
>> ping: 
>> inet_cksum(080000001f29000038717f2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,64)=0x4021
>> 64 bytes from 10.0.0.138: seq=0 ttl=254 time=3.116 ms
>> ping: 
>> inet_cksum(080000001f29000117b48e2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,64)=0xfc32
>> 64 bytes from 10.0.0.138: seq=1 ttl=254 time=2.747 ms
>
> Thanks Denys,
> I patched ping.c source according to your suggestion... but I think 
> the output is of little use because the (I guess) contains non 
> printable chars so the terminals strips them:
>
> ~ # ping -c3 172.31.255.1
> PING 172.31.255.1 (172.31.255.1): 56 data bytes
> ping: inet_cksum(,64)=0xa786
> 64 bytes from 172.31.255.1: seq=0 ttl=62 time=1.097 ms
> ping: inet_cksum(,64)=0xb851
> ping: inet_cksum,64)=0x603c
You can send the output to a file to check for non printable characters. 
But the output in the case should result from bin2hex and therefor be 
printable, as you can see in the example.
So I guess you also have a problem with bin2hex. So you should check 
your compiler and build environment.


More information about the busybox mailing list