use strict;

open(TAIL, "tail -f tmp.log |") or die;
while(<TAIL>) {
    if (/^(\w+ \d+ \d+:\d+:\d+ ).+(udp )(\d+\.\d+\.\d+\.\d+)(\(\d+\)) -> (\d+\.\d+\.\d+\.\d+)(\(\d+\))/) {
        print "$1$2$3@{[host($3)]}$4 -> $5@{[host($5)]}$6\n";
    }
    else {
        print $_;
    }
}

sub host {
    my $host = gethostbyaddr(pack("C4", split(/\./, $_[0])), 2);
    return $host ? "[$host]" : '';
}