2

Is it possible to obtain the content of received ICMP messages via unprivileged sockets on Linux systems ?

I'm interested in knowing if it is possible to do so with UDP DGRAM sockets, TCP STREAM sockets and/or ICMP DGRAM sockets.

  1. TCP sockets

I know that AF_INET, SOCK_STREAM,IPPROTO_TCP sockets can obtain feedback on the outcome of a connect() via return values such as ENETUNREACH, ETIMEDOUT or such. What I want is the actual entire ICMP message (the whole packet) by any means (create an other socket, ...) except sudo and setuid (no raw sockets).

  1. UDP sockets

I know that you can set the IP_RECVERR IP_PROTO-level option to AF_INET, SOCK_DGRAM,IPPROTO_UDP sockets, but not to STREAM sockets. This option allows to call recvmsg() with the MSG_ERRQUEUE flag set in order to receive a sock_extended_err structure containing the ICMP error. Does it works default or do i have to specify which ICMP message i want to get passed (i.e.:via ICMP_FILTER socket options) ?

  1. ICMP sockets

I also know that since ~2010, Linux systems allows AF_INET,SOCK_DGRAM,IPPROTO_ICMP sockets to send a few ICMP messages for ping purposes (I don't care about sending ICMP) and to receive some (which type/code i don't know). But it looks like it's not enabled by default and need root permission to be activated, which is forbidden. Is it possible to use those to receive ICMP messages, and which messages ?

  1. Additional Informations

I precise that I am asking this for Linux kernel >=2.6.x and IPv4. The ICMP messages I want to retreive are most importantly ttl-expired and if possible dest/port/host/network-unreach. I cannot run the program as root nor setuid root it, therefore RAW sockets are forbidden. I don't need to retreive the IP layer that encaspulate the ICMP messages.

jean-loup
  • 580
  • 4
  • 17
  • 1
    This is not 100% duplicate, but quite close to http://stackoverflow.com/questions/11914568/read-icmp-payload-from-a-recvmsg-with-msg-errqueue-flag. – user590028 Feb 03 '15 at 14:27
  • 1
    [ICMP](http://en.wikipedia.org/wiki/Internet_Control_Message_Protocol) is at a lower level than both UDP and TCP, so no you can't use UDP or TCP for ICMP. – Some programmer dude Feb 03 '15 at 14:30
  • @JoachimPileborg It is at a different level of abstraction, but it does not mean that the information cannot be transmitted between the 2 (udp stack to application). – jean-loup Feb 03 '15 at 14:34
  • @user590028 Thanks, this should do it for point 2. – jean-loup Feb 03 '15 at 14:36

0 Answers0