Advertisement
Guest User

how to catch ICMP unreachable within UDP sendto

a guest
Apr 6th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. 1 use strict;
  2. 2 use warnings;
  3. 3 use IO::Socket::INET;
  4. 4
  5. 5 my $cl = IO::Socket::INET->new(
  6. 6 PeerAddr => '192.168.178.1:12345', # definitly rejecting
  7. 7 Proto => 'udp',
  8. 8 );
  9. 9 $cl->send('foo') or die "send failed: $!"; # first send will succeed
  10. 10 # wait some time to receive ICMP unreachable
  11. 11 sleep(1);
  12. 12 $cl->send('bar') or die "send failed: $!"; # will fail
  13. -------
  14. $ perl a.pl
  15. send failed: Connection refused at a.pl line 12.
  16. -------
  17. $ strace -e sendto perl a.pl
  18. sendto(3, "foo", 3, 0, NULL, 0) = 3
  19. sendto(3, "bar", 3, 0, NULL, 0) = -1 ECONNREFUSED (Connection refused)
  20. ------
  21. # tcpdump -i $if -n udp or icmp
  22. 18:35:43.810818 IP 192.168.178.4.54762 > 192.168.178.1.12345: UDP, length 3
  23. 18:35:43.812406 IP 192.168.178.1 > 192.168.178.4: ICMP 192.168.178.1 udp port 12345 unreachable, length 39
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement