Hi Guys,
I am trying to write a perl function that add or delete and ARP cache entry. I wrote my own code as down, but unfortunately it doesn't work as I expected. I want to call arp function from within my function so I can add different entries every time I call my function. so is there any different solution for my problem?
If I use the "system(arp -i eth1 -s $NODE_IP $NODE_MAC)" instead of
Code:
#!/usr/bin/perl
sub add_mac_address{
my($OPERATION, $NODE_IP, $NODE_MAC) = @_;
open (MAC, "| arp") || die("Unable to write to the ARP cache");
$OPERATION =~ s/ADD/add/;
$OPERATION =~ s/DELETE/delete/;
if ($OPERATION eq "add"){
print MAC ("-i eth1 -s $NODE_IP $NODE_MAC");
}
elsif($OPERATION eq "delete"){
print MAC ("-i eth1 -d $NODE_IP");
}
else{
die ("Bad operation paramete\n");
}
close(MAC);
}
add_mac_address("ADD", "192.168.0.2", "00:30:84:9E:C8:9E");
Thanks for support
Bassam