I have created a icmp ping function but it doesn't always work due to the firewall of the computer I am trying to ping. I heard you can get around this using a tcp ping. How can i construct a tcp ping packet. I did a little research and it uses the ack, syn flags in the packet, but don't get how to tell if the computer responded correctly since it is random sequences.

Recommended Answers

All 4 Replies

as you probably know, Ping is on the Network Layer, and by definition doesn't use a port. there is no such thing as "Tcp Ping".

problem is, many servers no longer adhere to the RFC requirement to answer a network ping, citing security risks.

so, some people have written their own programs to emulate "ping" functionality at the TCP Transport Layer.

you could either get busy and start writing your own from scratch, or search around and use somebody else's.

like this
or this
or this.

thanks man for the links. Was searching all of google and couldn't find anything.

I have another question a little off topic from my original question but still socket related. Is there a callback in bsd sockets that lets me know when a chunk of data has been received so that I can determine how much data is left to be received.

sounds like you could use a little help from Beej.

so i could do something like this on the transmitter's end

int sendall(int s, char *buf, int *len) {
    int total = 0;        // how many bytes we've sent
    int bytesleft = *len; // how many we have left to send
    int n;

    while(total < *len) {
        n = send(s, buf+total, bytesleft, 0);
        if (n == -1) break;
        total += n;
        bytesleft -= n;
    }
    *len = total; // return number actually sent here
    return n==-1?-1:0; // return -1 on failure, 0 on success
}

and on the the receiver's end I would be able to get the total length of the data I am sending from a property in the TCP header or in where ever i define it if UDP. From that I could just modify the code above to receive data that has a larger size than the transfer frame can handle

Talguy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.