#!/atm/release/fore/bin/perl
#
# switch/pingd.pl - pindg functionality in a perl program
#
# Copyright (c) 1994 by Fore Systems, Inc.
# All rights reserved.

# This daemon pings its own ATM interfaces every 180 seconds,
# which allows the ATM switch control software to learn its IP address
# by snooping on the ARP packets.  It sets the ping to time-out after 2 sec.
# Acutally, this version pings it's own IP address+1

$ENV{'PATH'} = "/bin:/usr/bin:/etc:/usr/etc:/atm/etc:/usr/ucb:/atm/release/fore/etc:/atm/release/fore/bin";

while (1) {

    $foundASX = 0;

    open (FILE1, "ifconfig -a |") 
        || die "pingd.pl: could not do an \"ifconfig -a\\n";

# Find the device line in ifconfig.  The line following should have the 
# the address and  netmask on it. 

    while (<FILE1>) {
        if (/asx/) {
            ($junk, $inetaddr, $junk, $netmask, $junk, $junk) 
                = split(/ /,<FILE1>);

            $foundASX = 1;

# I know that no matter what the netmask is, the lower byte of the 
# address must be at least part of the hostid.  Not using $netmask here

            $inetaddr =~ /(\d+\.\d+\.\d+\.)(\d+)/;
            $upperPart = $1;
            $lowerPart = $2;

            $newLowerPart = 255-$lowerPart;
            system("/usr/etc/ping $upperPart$newLowerPart 2");
        }
    }

    if (!$foundASX) {
        printf("\npingd: \"ifconfig -a\" did not find an asx device\n");
    }

    sleep(180);
}


