File: send_packet.t

package info (click to toggle)
libnet-arp-perl 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 180 kB
  • ctags: 181
  • sloc: ansic: 297; perl: 41; makefile: 26
file content (85 lines) | stat: -rw-r--r-- 2,771 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#
# Test send_packet function
#
# Programmed by Bastian Ballmann
# Last update: 31.01.2007

use Net::ARP;
use Test::More qw( no_plan );

BEGIN
{
    eval{ require Net::Pcap; };
              
    if($@ =~ /^Can\'t\slocate/)
    {
        $dev = "eth0";
    }
    else
    {
   	import Net::Pcap;
        $dev = Net::Pcap::lookupdev(\$errbuf);
    }
}

print "Using device $dev to test send_packet()\n";

$ret = Net::ARP::send_packet("strange_dev",   # network interface
	      	      '127.0.0.1',            # source ip
	              '127.0.0.1',            # destination ip
		      'aa:bb:cc:aa:bb:cc',    # source mac
	              'ff:ff:ff:ff:ff:ff',    # destination mac
	              'reply');               # ARP operation 

ok( $ret == 0, "abort on strange dev value -> $ret" );


$ret = Net::ARP::send_packet($dev,            # network interface
	      	      'strange_src_ip',       # source ip
	              '127.0.0.1',            # destination ip
		      'aa:bb:cc:aa:bb:cc',    # source mac
	              'ff:ff:ff:ff:ff:ff',    # destination mac
	              'reply');               # ARP operation 

ok( $ret == 0, "abort on strange source ip value -> $ret" );


$ret = Net::ARP::send_packet($dev,            # network interface
	      	      '127.0.0.1',            # source ip
	              'strange_dst_ip',       # destination ip
		      'aa:bb:cc:aa:bb:cc',    # source mac
	              'ff:ff:ff:ff:ff:ff',    # destination mac
	              'reply');               # ARP operation 

ok( $ret == 0, "abort on strange destination ip value -> $ret" );


$ret = Net::ARP::send_packet($dev,            # network interface
	      	      '127.0.0.1',            # source ip
	              '127.0.0.1',            # destination ip
		      'strange_src_mac',      # source mac
	              'ff:ff:ff:ff:ff:ff',    # destination mac
	              'reply');               # ARP operation 

ok( $ret == 0, "abort on strange source mac value -> $ret" );


$ret = Net::ARP::send_packet($dev,            # network interface
	      	      '127.0.0.1',            # source ip
	              '127.0.0.1',            # destination ip
		      'aa:bb:cc:aa:bb:cc',    # source mac
	              'strange_dst_mac',      # destination mac
	              'reply');               # ARP operation 

ok( $ret == 0, "abort on strange destination mac value -> $ret" );

$ret = Net::ARP::send_packet($dev,            # network interface
		      '127.0.0.1',            # source ip
	              '127.0.0.1',            # destination ip
		      'aa:bb:cc:aa:bb:cc',    # source mac
	              'ff:ff:ff:ff:ff:ff',    # destination mac
	              'my_happy_arp_opcode'); # ARP operation 

ok( $ret == 1, "do not abort on strange arp op value -> $ret" );