trying to write a ping program

trying to write a ping program

Post by cassiej1 on Sat Apr 09, 2011 11:28 am
([msg=56182]see trying to write a ping program[/msg])

Can someone PLEASE point me toward some tutorials that will help me to be able to code a pinger I already wrote the code to generate a list of ips and now i want to write the code to ping these ips. thanks for the help
cassiej1
New User
New User
 
Posts: 1
Joined: Sat Apr 09, 2011 10:42 am
Blog: View Blog (0)


Re: trying to write a ping program

Post by Goatboy on Sat Apr 09, 2011 3:33 pm
([msg=56190]see Re: trying to write a ping program[/msg])

You will either need to use a library that will handle the gory details for you, or you'll need to read up on crafting packets by hand. I haven't done a ton of socket coding in C, but there's an excellent guide by a guy named Beej. Look it up.
Assume that everything I say is or could be a lie.
1UHQ15HqBRZFykqx7mKHpYroxanLjJcUk
User avatar
Goatboy
Expert
Expert
 
Posts: 2823
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Re: trying to write a ping program

Post by thetan on Sat Apr 09, 2011 5:26 pm
([msg=56191]see Re: trying to write a ping program[/msg])

Beej's guide has been a timeless classic in network programming.

http://beej.us/guide/bgnet/

Beej's guide is what The C Programming Language (K&R) is for C, what Donald Knuth's TOACP is for algorithms, what MIT's SICP (the wizard book) is for language and what Compilers: Principals, Techniques and Tools (The dragon book) is fro compiler theory.

Anyways, if you want to implement a traditional pinger similar to the ping command line tool, you'll have to send ICMP packets. Standard sockets typically only allow for the sending of data of TCP or UDP packets (that the kernel creates for you) that sit on top of the IP protocol. ICMP like IP is an OSI layer 3 protocol that sits directly on a layer 2 protocol (typically ethernet frames).

in *nix you'll need to open a raw socket with the ICMP proto flag. The following should be a push in the right direction.

http://www.kernel.org/doc/man-pages/onl ... cmp.7.html
http://www.kernel.org/doc/man-pages/onl ... raw.7.html
"If art interprets our dreams, the computer executes them in the guise of programs!" - SICP

Image

“If at first, the idea is not absurd, then there is no hope for it” - Albert Einstein
User avatar
thetan
Contributor
Contributor
 
Posts: 657
Joined: Thu Dec 17, 2009 6:58 pm
Location: Various Bay Area Cities, California
Blog: View Blog (0)


Re: trying to write a ping program

Post by kujinR on Sun Apr 10, 2011 12:26 pm
([msg=56217]see Re: trying to write a ping program[/msg])

thetan wrote:Beej's guide is what The C Programming Language (K&R) is for C, what Donald Knuth's TOACP is for algorithms, what MIT's SICP (the wizard book) is for language and what Compilers: Principals, Techniques and Tools (The dragon book) is fro compiler theory.

Totally off topic but, I would like to see more of this list, please.
"Better to keep your mouth shut and be thought a fool than to open it and remove all doubt."
"red = changed"
User avatar
kujinR
Poster
Poster
 
Posts: 270
Joined: Thu Jul 29, 2010 4:39 am
Blog: View Blog (0)


Post by -Th3V01d- on Wed Jan 25, 2012 3:14 pm
([msg=63873]see [/msg])

no one can help you here...
ImageДа будет Революция
User avatar
-Th3V01d-
New User
New User
 
Posts: 11
Joined: Sun Jan 15, 2012 8:24 am
Blog: View Blog (0)


Re:

Post by centip3de on Wed Jan 25, 2012 4:39 pm
([msg=63878]see Re:[/msg])

-Th3V01d- wrote:no one can help you here...


1: Epic necro is epic.
2: There's lots of people to help you here.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1431
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re:

Post by LoGiCaL__ on Wed Jan 25, 2012 5:56 pm
([msg=63884]see Re:[/msg])

-Th3V01d- wrote:no one can help you here...


If you're going to necro a post, at least be somewhat helpful or have something productive to add. thnx
User avatar
LoGiCaL__
Addict
Addict
 
Posts: 1061
Joined: Sun May 30, 2010 12:33 pm
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests