Announcement

Collapse
No announcement yet.

internetchecksum port problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • cyclone atom
    Guest replied
    Well thank you both for the info.
    I'm currently working some things out with the examples.

    Raymond, I'm a little new at pbdll but why do you use the indicator for intr variable(???) and not a declaration as Dword ?

    Another thing that I ran into is that in wsock32.inc the cksum from the icmp header is of type integer, while the cksum of an ip header type is a word (wich is the right one with the return value of the function)

    I already send an email to support but I haven't got a reply yet.

    Greetz
    Erwin

    ------------------

    Leave a comment:


  • Raymond Penn
    replied
    This is code that I have working in my ping port which uses the low-level Winsock API.

    I have it bolted into a program and it would take some time to pull it out into a usable example.

    FUNCTION cksum(BYVAL buf AS DWORD, BYVAL blen AS LONG) AS WORD

    DIM lsum AS DWORD
    DIM bufp AS WORD PTR
    DIM Intr???

    bufp=buf

    WHILE blen>0
    [email protected]
    INCR bufp
    blen=blen-2
    LOOP

    intr???=lsum
    SHIFT RIGHT intr???,16

    lsum=(lsum + intr???)
    SHIFT RIGHT intr???,16

    lsum=(lsum + intr???) AND &h0FFFF

    lsum=NOT lsum

    FUNCTION=BITS??(lsum)
    END FUNCTION


    ------------------

    Leave a comment:


  • Erwin van de Wiel
    Guest replied
    Hello,

    I'm the same one who posted the first message and this is what I got. If somebody with C knowledge could verify it I would be very thankfull.

    'USHORT InternetChecksum(PUSHORT pBuf, int nLen)
    function InternetChecksum(header as word ptr, headerlen as long)as word
    '{
    'int nSum = 0;
    dim nSum as long
    nsum = 0

    dim I as integer

    while headerlen > 0
    nsum = nsum + @header[i]
    i = i + 1
    headerlen = headerlen - 2
    wend

    'While(nlen > 0)
    '{
    'nSum += (*pBuf++);
    'nLen -= 2;
    '}

    dim tempvar1 as long
    dim tempvar2 as long
    tempvar1 = nsum
    shift right tempvar1,16
    nsum = tempvar AND &hffff
    tempvar2 = nsum
    shift right tempvar2,16
    nsum = nsum + tempvar2
    InternetChecksum = NOT nsum
    'nSum = (nSum > 16) + (nSum & 0xffff);
    'nSum += (nsum > 16);
    'return(~nSum);
    '}

    If someone could verify the conversion please.

    Thanks

    ------------------

    Leave a comment:


  • Scott Turchin
    replied
    Can't help you there, and I'm not sure how that works exactly, I had believed that was at a TCP/IP layer not an application layer, but I could be wrong..


    However, I've already ported icmp_echo over, you can take my work and continue on if you like, it works but has some bugs in it....


    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • cyclone atom
    Guest started a topic internetchecksum port problem

    internetchecksum port problem

    Hello,

    I'm porting the ping example from the winsock2 book to powerbasic. The problem I'm running in to is the InternetChecksum function. I know C++ a little, but I find this function difficult to convert to the powerbasic language. Maybe I could do it but I want to make sure that the function is correct, clean and fast .

    The definition of the function is "the one's complement of the one's complement sum of all 16 bit words"

    So if somebody could help me with this I will be very thankfull.

    Ok this is the C function. I'm only intrested in the code that's inside the function. The parameters are : 1. A type 2. len of type (sizeof).

    USHORT InternetChecksum(PUSHORT pBuf, int nLen)
    {
    int nSum = 0;

    While(nlen > 0)
    {
    nSum += (*pBuf++);
    nLen -= 2;
    }

    nSum = (nSum > 16) + (nSum & 0xffff);
    nSum += (nsum > 16);
    return(~nSum);
    }

    The checksum is a standard from RFC 791 IP.

    Any help is appreciated even if it is a little.

    Thanks



    [This message has been edited by cyclone atom (edited March 05, 2000).]
Working...
X