#!/usr/bin/perl
# $Id: editrt,v 1.1 2001/02/10 23:57:32 stes Exp $

$IPMENU=$ENV{'IPMENU'};
require "$IPMENU/ipmenu.lib";

$rtkey=$ARGV[0];
$mydst=$ARGV[1];

$form="$TMP/Form.$$";

open(PIPE,"ip -o route show table $rtkey |");

while (<PIPE>) {
   if (/^([\w]+)[ ]+(default|[\d\.\/]+)/) { 
     $type=$1;$dst=$2;
   } else {
     if (/^(default|[\d\w\.\/]+)/) { 
       $type='unicast';$dst=$1;
     } else {
       next;
     }
   }

   last if ($dst eq $mydst); 
}
close (PIPE);

if ($dst eq $mydst) {
$vroutedst=$dst;
$vroutetype=$type;
if (/dev ([\w\d]+)/) { $vroutedev= $1; }
if (/via ([\w\d\.\/]+)/) { $vroutevia= $1; }
if (/src ([\w\d\.\/]+)/) { $vroutesrc= $1; }
if (/scope ([\w\d\.\/]+)/) { $vroutescope= $1; }
if (/proto ([\w\d\.\/]+)/) { $vrouteproto= $1; }
formroute($form,$rtkey);

print "open $form\n";
} else {
unlink($form);
print "nop\n";
}

