Skip to content

Instantly share code, notes, and snippets.

@gpolitis
Created December 15, 2015 20:17
Show Gist options
  • Save gpolitis/56608eb683ef23a702e2 to your computer and use it in GitHub Desktop.
Save gpolitis/56608eb683ef23a702e2 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use Net::Pcap;
die "Usage: $0 infile outfile" unless scalar(@ARGV) > 1;
my $err;
open(my $out, '>:raw', $ARGV[1]) or die "cannot open in file: $!";
write_header();
my $pcap = Net::Pcap::open_offline($ARGV[0], \$err);
Net::Pcap::dispatch($pcap, 0, \&process_pkt, $out);
Net::Pcap::close($pcap);
close($out);
sub write_header {
print $out "#!rtpplay1.0 0.0.0.0/1337\n";
print $out "DEADBEEFDEADBEEF";
}
sub process_pkt {
# skip first 54 octets and write rest to $out
my($out, $hdr, $pkt) = @_;
my $payload = substr($pkt, 42);
print $out "00";
print $out pack('n', length($payload));
print $out "0000";
print $out $payload;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment