I'm trying to write a program that creates a listening socket that will accept ICMP packets and then read them in. I created a socket using socket() and then the next step is to bind it. But what port would I bind to since ICMP doesn't have a port?
I'm trying to write a program that creates a listening socket that will accept ICMP packets and then read them in. I created a socket using socket() and then the next step is to bind it. But what port would I bind to since ICMP doesn't have a port?
Although I have not done it before I am pretty sure you need to use a "raw socket" for this. I am sure you cannot use a normal tcp or udp socket.
Take a look at these, they both cover ICMP explicitly:
Winsock Programmer's FAQ: Ping: Raw Sockets Method
http://courses.cs.vt.edu/~cs4254/fal...ides/raw_6.pdf
You can use raw sockets on *nix too, I don't know your OS.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Thanks. I'll look into that. I guess I should have said I'm using FreeBSD.
Well yer in luck. Word on the street is MS doesn't like raw sockets and doesn't support them well But Berkeley sockets were made for this, I think.
You may also want to investigate the pcap library, which is used with packet sniffers; you will definately be able to catch ICMP packets in there (I'm not sure how it works but I would guess raw sockets).
Last edited by MK27; 01-21-2010 at 10:11 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge