Thread: Simple ping routine, not receiving anything.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    Quote Originally Posted by Yonut View Post
    Why would the program only work once a proper ping is issued? Why would the second ping correct the checksum of the original ping? I'm thinking this might have something to do with bind.
    Perhaps your program was waiting for a response and stole the response from the other ping program (if that's possible).
    Here's an implementation based on the RFC example C code that might work:
    Code:
    #include <stdio.h>
    #include <inttypes.h>
    
    // Compute Internet Checksum for "count" bytes
    // beginning at location "addr".
    uint16_t checksum(void* addr, int count)
    {
        uint16_t* buf = addr;
        uint32_t sum = 0;
    
        for ( ; count > 1; count -= 2)
            sum += *(uint16_t*)buf++;
    
        //  Add left-over byte, if any
        if (count > 0)
            sum += *(unsigned char*)addr;
    
        //  Fold 32-bit sum to 16 bits
        while (sum >> 16)
            sum = (sum & 0xffff) + (sum >> 16);
    
        return (uint16_t)~sum;
    }
    
    int main() {
        // ICMP_ECHO == 8
        char dat[] = "/x08/x00/x00/x00/x12/x34/x00/x00";
        uint16_t cs = checksum(dat, 8);
        printf("%04" PRIX16 "\n", cs); // yields A740
        return 0;
    }
    Last edited by john.c; 3 Weeks Ago at 03:11 PM.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is this an example of a co-routine?
    By c_weed in forum Tech Board
    Replies: 1
    Last Post: 06-20-2012, 11:36 AM
  2. Replies: 1
    Last Post: 03-21-2008, 08:15 PM
  3. Help with my XOR routine..
    By Neo1 in forum C++ Programming
    Replies: 9
    Last Post: 10-04-2007, 03:30 PM
  4. working, but slow simple graphing routine in gnuplot
    By noguru in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 11:31 AM
  5. Simple client - receiving data from server and keyboard w/o blocking
    By Spitball in forum Networking/Device Communication
    Replies: 5
    Last Post: 01-08-2005, 12:32 PM

Tags for this Thread