linux - Catching ICMP reject on UNIX -


firewalls such iptables have option notify sender (after blocking packet) via icmp messages (e.g. port closed). message contains header of rejected packet (required rfc), it's technically possible associate application sent it.

is there easy way programatically capture icmp messages related application in unix environment? convenient if application tell user destination behind firewall. doesn't have posix specified, shouldn't limited 1 platform (although know anyway :).

one way achieve raw sockets , 1 using pcap, both of these quite invasive , have go through icmp messages , filter ones belong other applications.

it's technically possible associate application sent it

i doubt there's easy way want. kernel receives icmp message , processes before telling program unsuccessful. example, here's result of pinging unreachable host (running on linux using strace examine system calls; boldface line result of receiving icmp error):

     sendmsg(3, {msg_name(16)={sa_family=af_inet, sin_port=htons(0), sin_addr=inet_addr("192.168.113.198")}, msg_iov(1)=[{"\10\0mq\f\24\0\1~u\227u\0\0\0\0\250\373\1\0\0\0\0\0\20\21\22\23\24\25\26\27"..., 64}], msg_controllen=0, msg_flags=0}, 0) = 64     setitimer(itimer_real, {it_interval={0, 0}, it_value={10, 0}}, null) = 0     recvmsg(3, 0x7ffffd6ecbe0, 0)           = -1 eagain (resource temporarily unavailable)     recvmsg(3, {msg_name(16)={sa_family=af_inet, sin_port=htons(0), sin_addr=inet_addr("192.168.113.206")}, msg_iov(1)=[{"e\0\0008\5\316\0\0\200\1\366q\300\250q\316\n\0\2\17\3\0017\335\0\0\0\0e\0t\0"..., 192}], msg_controllen=32, {cmsg_len=32, cmsg_level=sol_socket, cmsg_type=0x1d /* scm_??? */, ...}, msg_flags=0}, 0) = 56     recvmsg(3, 0x7ffffd6ecbe0, 0)           = -1 ehostunreach (no route host)     recvmsg(3, {msg_name(16)={sa_family=af_inet, sin_port=htons(0), sin_addr=inet_addr("192.168.113.198")}, msg_iov(1)=[{"\10\0mq\f\24\0\1", 8}], msg_controllen=80, {cmsg_len=32, cmsg_level=sol_socket, cmsg_type=0x1d /* scm_??? */, ...}, msg_flags=msg_errqueue}, msg_dontwait|msg_errqueue) = 8     write(1, "from 192.168.113.206 icmp_seq=1 "..., 61) = 61     write(1, "\n", 1)                       = 1     write(1, "--- 192.168.113.198 ping statist"..., 40) = 40     write(1, "1 packets transmitted, 0 receive"..., 73) = 73     write(1, "\n", 1)                       = 1 

you run application , monitor strace (or on system), you'd have watch , decode various icmp failure modes. going pretty invasive.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -