#!/usr/local/bin/perl -w

use strict;
use BER '0.58';
use SNMP_Session '0.58';

my $trap_receiver = shift @ARGV || die;
my $trap_community = shift @ARGV || die;
my $trap_session = SNMP_Session->open ($trap_receiver, $trap_community, 162);
my $start_time = time;

link_down_trap (1);
1;

sub link_down_trap ($) {
  my ($if_index) = @_;
  my $genericTrap = 2;		# linkDown
  my $specificTrap = 0;
  my @ifIndexOID = ( 1,3,6,1,2,1,2,2,1,1 );
  my @ifDescrOID = ( 1,3,6,1,2,1,2,2,1,2 );
  my $upTime = int ((time - $start_time) * 100);
  my $myIpAddress = pack "CCCC", 130, 59, 4, 2;
  my @myOID = ( 1,3,6,1,4,1,2946,0,8,15 );

  warn "Sending trap failed"
    unless $trap_session->trap_request_send (encode_oid (@myOID),
					     encode_ip_address ($myIpAddress),
					     encode_int ($genericTrap),
					     encode_int ($specificTrap),
					     encode_timeticks ($upTime),
					     [encode_oid (@ifIndexOID,$if_index),
					      encode_int ($if_index)],
					     [encode_oid (@ifDescrOID,$if_index),
					      encode_string ("foo")]);
}
