#!/usr/bin/perl

#perl script to test tap packet
#manipulation (Peter Walsh)

use Linux::TunTap;
use NetPacket::Ethernet;
use String::HexConvert ':all';
use strict;

my $tap = new Linux::TunTap();
my $if = $tap->{interface};
   print ("Iface $if \n");

my ($eth_hex, $eth_pkt, $eth_obj);
my ($tap_hex, $tap_pkt);

while(1) {
   $tap_pkt = $tap->get_raw();
   $tap_hex = ascii_to_hex($tap_pkt);

   #print ("TAPHEX ", $tap_hex, "\n");
   $eth_hex = substr($tap_hex,8);
   #print ("ETHHEX ", $eth_hex, "\n");

   $eth_pkt = hex_to_ascii($eth_hex);

   $eth_obj = NetPacket::Ethernet->decode($eth_pkt);
   print("SRC_MAC $eth_obj->{src_mac} DEST_MAC $eth_obj->{dest_mac}");
   printf(" TYPE %x \n", $eth_obj->{type});
}


