Re: FW: [Q] cksum of UDP packet

From: crawford charles (biv0uac17_at_hotmail.com)
Date: 07/30/03

  • Next message: Calderon, Juan C (EM, DDEMESIS): "RE: Password Hiding"
    To: anqin@anqin.com
    Date: Wed, 30 Jul 2003 15:22:32 +0000
    
    

    One infers from the sample below that you did not include the "UDP
    Pseudo-header" (IP src/dst address etc.) in the calculation.
    See Comer/Stevens, RFC 768, or a host of other references for the UDP
    checksum computation.

    I hope that this helps.

    From: Qin An [mailto:anqin@anqin.com]
    Sent: Tuesday, July 29, 2003 11:41 PM
    To: secprog@securityfocus.com
    Subject: [Q] cksum of UDP packet

    Hi, Glad to meet you all!

    I got a problem in cksum computation for UDP packet. At the end of this
    mail, there is
    a function copied from a textbook. I believe it is a universal cksum
    calculation function.
    I captured a UDP packet on the net:

    0x07, 0x2c, 0x00, 0x35, 0x00, 0x0c, 0x98, 0x8e, 0x64, 0x69, 0x72, 0x0a

    The 6th and 7th element is the cksum computed by the sender's kernel. My
    question is that
    when I use in_cksum to compute the cksum, it returns 0x1f22, different from
    0x98, 0x8e.
    What's wrong here? Is there any other algorithm to compute cksum?

    Thank you in advance!

    Qin An

    ==========================================

    unsigned short in_cksum (unsigned short *ptr, int nbytes)
    {
       unsigned long sum; /* assumes long == 32 bits */
       unsigned short oddbyte, answer; /* assumes short == 16 bits */

       sum = 0;
       while (nbytes > 1){
      sum += *ptr++;
      nbytes -= 2;
      }

       /* mop up an odd byte, if necessary */
       if (nbytes == 1){
       /* make sure top half is zero */
      oddbyte = 0;
       /* one byte only */
      * ((unsigned char *) &oddbyte) = *(unsigned char *) ptr;
      sum += oddbyte;
      }

      /* add back carry outs from top 16 bits to low 16 bits */
       /* add high-16 to low-16 */
       sum = (sum >> 16) + (sum & 0xffff);
       /* add carry */
       sum += (sum >> 16);
       /* ones-compliment, then truncate to 16 bits */
       answer = (unsigned short)(~sum);
       return answer;
    }

    unsigned char s[] = {
    0x07, 0x2c, 0x00, 0x35, 0x00, 0x0c, 0x98,
    0x8e, 0x64, 0x69, 0x72, 0x0a};

    int main (int argc, char *argv[])
    {
       int i;

       s[6] = s[7] = 0;

       i = in_cksum ((unsigned short *) &s[0], 12);
    }

    _________________________________________________________________
    Add photos to your messages with MSN 8. Get 2 months FREE*.
    http://join.msn.com/?page=features/featuredemail


  • Next message: Calderon, Juan C (EM, DDEMESIS): "RE: Password Hiding"

    Relevant Pages

    • Re: OTish: using short-term TCP connections to send to multiple slaves
      ... fragmented and re-assembled at the other end, but it's not like TCP ... way too big for UDP, ... inside a single UDP packet, this is trivially easy: ... power to monitor and drop connections on any basis it likes. ...
      (comp.lang.python)
    • Re: OTish: using short-term TCP connections to send to multiple slaves
      ... fragmented and re-assembled at the other end, but it's not like TCP ... being way too big for UDP, ... fit inside a single UDP packet, this is trivially easy: ... power to monitor and drop connections on any basis it likes. ...
      (comp.lang.python)
    • Re: xPC Target UDP Communication
      ... That will get the attention of the member of our group who wrote the real time UDP code. ... I have been trying to communicate with my xPC Target using the UDP ... The communication from my Target to the Host works perfectly. ... I have verified that the correct UDP packet is ...
      (comp.soft-sys.matlab)
    • Re: Cant send a udp packet to the local PC?
      ... to test a simple UDP server / client applications on my PC. ... couldn't send a UDP packet to the local (the same pc where the sending ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Reading UDP with FPGA
      ... as the title says I have to read some information stored in UDP packet ... Use an external processor and send data to FPGA through dedicated ... UDP is very simple. ... I have some designs that use a PicoBlaze to deal ...
      (comp.arch.fpga)