4643l1

Listing 1. Perl5 VoIP Gateway for IP id Characteristics

#!/usr/bin/perl -w

use Net::RawIP ;

# We should have some defaults
# WEST
$to_west = '172.16.4.100';
# EAST
$to_east = '8.0.0.2';
# Max size of packet
$snaplen = 2500;
# No. packets to read by each dev
$N       = 50;

# This is how we specify our pcap device
# filter. We need one for packets that originate
# from WEST and one for EAST.
$from_east_filter =
 "ip proto \\udp and dst host $to_west";
$from_west_filter =
 "ip proto \\udp and dst host $to_east";

# Declare what kind of raw ip packet we want
$mithm_east = new Net::RawIP({udp=>{}});
$mithm_west = new Net::RawIP({udp=>{}});

# Initialize packet capture device on eth1 to
# listen to $cap_filter as defined above. The
# time-out is set to 5 milliseconds.

open(FD, "+>> id_dump.txt");

$p = $mithm_east->pcapinit("eth1",
 $from_east_filter,
 $snaplen, 5 );
loop $p, $N, \&outage, \@mithm_east;

close(FD);

#
# Sub Name : 'outage'
# Input  : pcap_t* handle
# Output : none
#
# Function  : Behaviour similar to tcpdump.
#    prints out the packets captured
#    by the input handle.
#
# Note  : $arp is an array for $p!
#
sub outage
{

 # let's concentrate on the UDP header
 $mithm_east->bset(substr ($_[2], 14));

 # Let's be a bit more precise
 my @arp = $mithm_east->get
 (
  {
   ip => [qw(id)]
  }
 );

 print  " $arp[0]\n";

}

#
# Sub Name : 'qoutage'
# Input  : pcap_t* handle
# Output : none
#
# Function  : Behaviour similar to tcpdump.
#    prints out the packets captured
#    by the input handle.
#
# Note  : $arq is an array for $q!
#
sub qoutage
{


 # let's concentrate on the UDP header
 $mithm_west->bset(substr ($_[2], 14));

 # Let's be a bit more precise
 my @arq = $mithm_west->get
 (


   ip => [qw(id)]
  }
 );

}

