#!/usr/bin/perl -w

# Just a little script written by Sake Blok (sake@euronet.nl)
# to extract udp-payload data from an udp-stream.

use strict;
use English;

use Net::PcapUtils;
use NetPacket::Ethernet qw(:strip);
use NetPacket::IP;
use NetPacket::UDP;

my $packet_nr=0;

sub process_pkt {
   my($arg, $hdr, $pkt) = @_;

   my $ip_obj = NetPacket::IP->decode(eth_strip($pkt));
   my $udp_obj = NetPacket::UDP->decode($ip_obj->{data});

   $packet_nr++;

   printf OUT "%s",$udp_obj->{data};
}

my $infile = shift || die "Usage: $0 <infile> <outfile>\n";
my $outfile = shift || die "Usage: $0 <infile> <outfile>\n";

open(OUT,">$outfile");
Net::PcapUtils::loop(\&process_pkt, (SAVEFILE => $infile, FILTER => 'udp'));
close(OUT);

