1#!/usr/bin/perl
2#
3# $Id: icmp-mask.pl 1640 2009-11-09 17:58:27Z gomor $
4#
5use strict;
6use warnings;
7
8use Getopt::Std;
9my %opts;
10getopts('i:I:d:v', \%opts);
11
12die "Usage: $0 -i dstIp [-I srcIp] [-d device] [-v]\n"
13   unless $opts{i};
14
15use Net::Packet;
16
17$Env->dev($opts{d}) if $opts{d};
18$Env->ip ($opts{I}) if $opts{I};
19$Env->debug(3)      if $opts{v};
20
21my $ip = Net::Packet::IPv4->new(
22   protocol => NP_IPv4_PROTOCOL_ICMPv4,
23   dst      => $opts{i},
24);
25
26my $mask = Net::Packet::ICMPv4->new(
27   type => NP_ICMPv4_TYPE_ADDRESS_MASK_REQUEST,
28);
29
30my $frame = Net::Packet::Frame->new(l3 => $ip, l4 => $mask);
31
32$frame->send;
33
34until ($Env->dump->timeout) {
35   if ($frame->recv) {
36      print "Reply:\n";
37      print $frame->reply->l3->print, "\n";
38      print $frame->reply->l4->print, "\n";
39      last;
40   }
41}
42
43$Env->dump->stop;
44$Env->dump->clean;
45