View Full Version : C++ Sockets
Mwnciau
04-29-2007, 06:30 PM
Hey :)
I have just found http://www.adp-gmbh.ch/win/misc/sockets.html and have tried it. I can get it to work with web servers but does anyone know how to ping a computer on my local network and get information about it (Like computer name). Thanks
ghell
04-30-2007, 01:14 AM
well ping is done using ICMP (http://en.wikipedia.org/wiki/Internet_Control_Message_Protocol) rather than TCP or UDP
ICMP Echo Requests (pings): http://en.wikipedia.org/wiki/ICMP_Echo_Request
ICMP Echo Replies (pongs): http://en.wikipedia.org/wiki/ICMP_Echo_Reply
if you are interested. If you wrote your own server and client you could get the same effect though, its basically just something like you send the time, they send your time back and you calculate the difference or something like that (it's been a while since I did it)
Finding the "computer name" might be a bit more complicated, while ping is at a very low level, computer names are much higher level and probably use windows specific code for windows networks or unix specific code for other networks, etc. I'm not sure on this at all though. There may be something in MFC for doing it on windows networks I suppose.
KeZZeR
04-30-2007, 04:08 PM
I thought ICMP was just built upon the IP stack? Thus ICMP uses TCP/IP to make requests to the host computer?
Mwnciau
04-30-2007, 04:10 PM
Thanks for the reply, I'll have a look at that.
ghell
04-30-2007, 07:25 PM
TCP/IP is 2 protocols on a stack (Transmission Contontrol Protocol on top of Internet Protocol [then for example on top of ethernet, on top of 100BASE-T)
TCP and UDP are both in the transport layer.
IP and ICMP are both in the network layer.
The TCP/IP model is weird, it's an alternative to the OSI model (which isn't really used in practice) but I think the formal TCP/IP model is also a bit impractical. As far as I know it is 4 layers high and an extra layer is added to make it reflect reality.
Anyway the point is, you probably don't have access to ICMP. I think windows has now done away with giving people access to it for security reasons but you might be able to do something in an old version of windows or on a non-windows os. However, you can simulate the protocol under TCP for your own understanding, and may be able to call system code to fire off icmp pings etc, but I doubt you will be able to craft your own ICMP packets and send them at someone else expecting a response.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.