ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Please add some option in following file as ping.
If add -c and -I option, It is OK.
I am hopping your help
Please
/*
* tcping.c
*
* Copyright (c) 2002-2008 Marc Kirchner <mail(at)marc(dash)kirchner(dot)de>
*
* tcping is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* tcping is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ms++. If not, see <http://www.gnu.org/licenses/>.
*
* tcping does a nonblocking connect to test if a port is reachable.
* Its exit codes are:
* -1 an error occured
* 0 port is open
* 1 port is closed
* 2 user timeout
*/
int sockfd;
struct sockaddr_in addr;
struct hostent *host;
int error = 0;
int ret;
socklen_t errlen;
struct timeval timeout;
fd_set fdrset, fdwset;
int verbose=1;
int c;
char *cptr;
long timeout_sec=0, timeout_usec=0;
int port=0;
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088
Rep:
Please,
That program, while it is a "ping" program is different to the standard ping program.
Normal ping sends a number of ICMP echo request packets and awaits the reply. It then reports on the statistics, such as average round trip time.
The tcping.c program you have posted above is simply checking connectivity to a given TCP port. It creates a socket, and attempts to connect to the specified port. It then interprets the result as either open or closed.
Sample output from tcping.c:
Code:
$ ./a.out 192.168.1.1 80
192.168.1.1 port 80 open.
Have you tried compiling and running it? All you need to do is paste it into a file (tcping.c) and then run "gcc tcping.c". You can then run a.out which is the executable.
My understanding of the options you want implemented is that -c specifies the number of packets to send and -I specifies the interface to use. As per my explanation above, there is no point in implementing -c in tcping.c, as you would simply be checking connectivity to the same port multiple times.
You say that your ISP has blocked Ping? Why have they done this? Have you tried contacting them and finding out why? I find it difficult to believe that they have blocked Ping. ICMP traffic is essential for the operation of the internet, and so they can't block it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.