Networking Q: Accepting ICMP packets

This is a discussion on Networking Q: Accepting ICMP packets within the C Programming forums, part of the General Programming Boards category; I'm trying to write a program that creates a listening socket that will accept ICMP packets and then read them ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    119

    Networking Q: Accepting ICMP packets

    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?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    119
    Thanks. I'll look into that. I guess I should have said I'm using FreeBSD.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by homer_3 View Post
    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 09: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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  2. Question on ICMP echo request
    By kzfid in forum Networking/Device Communication
    Replies: 7
    Last Post: 11-02-2005, 05:16 PM
  3. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 11:23 AM
  4. C++: Reference Book, GUI, Networking & Beyond
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2001, 07:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21