~vcs-imports/mysql-mmm/2.0

« back to all changes in this revision

Viewing changes to lib/Agent/Helpers/Network.pm

  • Committer: mail at pascalhofmann
  • Date: 2009-02-10 09:18:57 UTC
  • Revision ID: vcs-imports@canonical.com-20090210091857-66p9ks2dxtdt99fk
ph:
- Use Net::ARP instead of arping
- Documentation update

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
our $VERSION = '0.01';
8
8
 
 
9
if ($OSNAME eq 'linux') {
 
10
        use Net::ARP;
 
11
        use Time::HiRes qw( usleep );
 
12
}
 
13
 
9
14
=head1 NAME
10
15
 
11
16
MMM::Agent::Helpers::Network - network related functions for the B<mmmd_agent> helper programs
108
113
 
109
114
        
110
115
        if ($OSNAME eq 'linux') {
111
 
                # Get path to arping
112
 
                my $arp_util = `which arping`;
113
 
                chomp($arp_util);
114
 
 
115
 
                if ($arp_util eq '') {
116
 
                        print "ERROR: Could not find arping!\n";
117
 
                        exit(1);
118
 
                }
119
 
 
120
 
                # Get broadcast for arping
121
 
                my $output = `/sbin/ifconfig $if`;
122
 
                $output =~ /Bcast:\s*([\d\.]+)/i;       # TODO error check?
123
 
                my $if_bcast = $1;
124
 
 
125
 
                # Execute the arping command
126
 
                my $arp_param = '';
127
 
                # Check parameters for arping
128
 
                if (`$arp_util 2>&1` =~ /\[ -S <host\/ip> \]/) {
129
 
                        $arp_param = "-i $if -S $ip";
130
 
                }
131
 
                elsif (`$arp_util 2>&1` =~ /\[-s source\]/) {
132
 
                        $arp_param = "-I $if -s $ip";
133
 
                } else {
134
 
                        print "ERROR: Unknown arping version!\n";
135
 
                        exit(1);
136
 
                }
137
 
                `$arp_util -c 2 $arp_param $if_bcast`
 
116
                my $mac = '';
 
117
                Net::ARP::get_mac('eth0', $mac);
 
118
                return "ERROR: Couln't get mac adress of interface $if" unless ($mac);
 
119
 
 
120
                for (my $i = 0; $i < 5; $i++) {
 
121
                        Net::ARP::send_packet($if, $ip, $ip, $mac, 'ff:ff:ff:ff:ff:ff', 'reply');
 
122
                        Net::ARP::send_packet($if, $ip, $ip, $mac, 'ff:ff:ff:ff:ff:ff', 'request');
 
123
                        usleep(100);
 
124
                }
138
125
        }
139
126
        elsif ($OSNAME eq 'solaris') {
140
127
                # Get params for send_arp
163
150
        }
164
151
        return undef;
165
152
}
 
153
 
 
154
1;