#!/usr/bin/perl

use strict;

use gateway_lib;

use Getopt::Long;

use IO::File;

my $tapno;
my $addr;
my $iface;
my $fedkit_dir= "/usr/local/federation";
my $perl = "/usr/bin/perl";
my $peer;
my $use_file;
my %opts = (
    'tapno=s' => \$tapno,
    'addr=s' => \$addr,
    'peer=s' => \$peer,
    'use_file', \$use_file,
);

exit(20) unless GetOptions(%opts);
gateway_lib::read_config(gateway_lib::config_filename(), \%opts)
    if $use_file;

die "Need an address\n" unless $addr;

# Get the interface to reset
my $f = new IO::File("/tmp/interface$tapno") ||
    die "Cannot open interface file\n";

while (<$f>) {
    chomp;
    $iface = $_;
}
$f->close( );

print "iface is $iface\n";
gateway_lib::configure_outgoing_iface($iface, $addr);

exit(0);

=pod

=head1 NAME

B<unsetup_bridge.pl> - Restore the given IP address to the interface bridged to
the given tapno. 

=head1 OPTIONS

=over 8

=item B<addr=>I<address>

Address of the local interface to restore.

=item B<tapno=>I<integer>

The tap interface that generated the interface save file.

=item B<use_file>

If given read additional parameters from the file in
/proj/I<project>/exp/I<experiment>/tmp/I<hostname>.gw/conf where those are the
current testbed project and experiment and the hostname is before the first
dot.  The file is option: value.


=back

=head1 SYNOPSIS

B<unsetup_bridge.pl> restores a previously assigned IP address to an interface.
That interface name was saved by B<setup_bridge.pl>, before it was removed for
bridging.

=head1 AUTHORS

Ted Faber <faber@isi.edu>

=cut
