1#!/usr/bin/perl -w 2 3# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4# 5# SPDX-License-Identifier: MPL-2.0 6# 7# This Source Code Form is subject to the terms of the Mozilla Public 8# License, v. 2.0. If a copy of the MPL was not distributed with this 9# file, you can obtain one at https://mozilla.org/MPL/2.0/. 10# 11# See the COPYRIGHT file distributed with this work for additional 12# information regarding copyright ownership. 13 14use IO::File; 15use IO::Socket; 16use Net::DNS; 17use Net::DNS::Packet; 18 19my $localport = int($ENV{'PORT'}); 20if (!$localport) { $localport = 5300; } 21 22my $sock = IO::Socket::INET->new(LocalAddr => "10.53.0.7", 23 LocalPort => $localport, Proto => "udp") or die "$!"; 24 25my $pidf = new IO::File "ans.pid", "w" or die "cannot open pid file: $!"; 26print $pidf "$$\n" or die "cannot write pid file: $!"; 27$pidf->close or die "cannot close pid file: $!"; 28sub rmpid { unlink "ans.pid"; exit 1; }; 29 30$SIG{INT} = \&rmpid; 31$SIG{TERM} = \&rmpid; 32 33STDOUT->autoflush(1); 34 35print "Net::DNS::VERSION => $Net::DNS::VERSION\n"; 36 37for (;;) { 38 $sock->recv($buf, 512); 39 40 print "**** request from " , $sock->peerhost, " port ", $sock->peerport, "\n"; 41 42 my $packet; 43 44 if ($Net::DNS::VERSION > 0.68) { 45 $packet = new Net::DNS::Packet(\$buf, 0); 46 $@ and die $@; 47 } else { 48 my $err; 49 ($packet, $err) = new Net::DNS::Packet(\$buf, 0); 50 $err and die $err; 51 } 52 53 print "REQUEST:\n"; 54 $packet->print; 55 56 $packet->header->qr(1); 57 $packet->header->opcode(5); 58 59 my @questions = $packet->question; 60 my $qname = $questions[0]->qname; 61 my $qtype = $questions[0]->qtype; 62 $packet->push("update", rr_del("$qname SOA")); 63 64 print "RESPONSE:\n"; 65 $packet->print; 66 67 $sock->send($packet->data); 68} 69