Skip Menu |

This queue is for tickets about the Net-DNS CPAN distribution.

Report information
The Basics
Id: 39284
Status: resolved
Priority: 0/
Queue: Net-DNS

People
Owner: Nobody in particular
Requestors: wessels [...] dns-oarc.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: patch to make Net::DNS::Nameserver reply handler return more socket details
Date: Mon, 15 Sep 2008 08:45:08 +0000 (UTC)
To: bug-Net-DNS [...] rt.cpan.org
From: Duane Wessels <wessels [...] dns-oarc.net>
For some of my work it is useful to get details such as the UDP/TCP source port from a transaction. This patch adds a new hash to the ReplyHandler callback where sockhost, sockport, peerhost, and peerport are returned. --- lib/Net/DNS/Nameserver.pm.orig 2008-07-09 09:44:08.000000000 -0700 +++ lib/Net/DNS/Nameserver.pm 2008-07-09 10:28:38.000000000 -0700 @@ -150,7 +150,7 @@ #------------------------------------------------------------------------------ sub make_reply { - my ($self, $query, $peerhost) = @_; + my ($self, $query, $peerhost, $conn) = @_; my $reply = Net::DNS::Packet->new(); # create empty reply packet $reply->header->qr(1); @@ -191,12 +191,12 @@ if ($query->header->opcode eq "QUERY"){ ($rcode, $ans, $auth, $add, $headermask) = - &{$self->{"ReplyHandler"}}($qname, $qclass, $qtype, $peerhost, $query); + &{$self->{"ReplyHandler"}}($qname, $qclass, $qtype, $peerhost, $query, $conn); }else{ $reply->header->rcode("SERVFAIL") unless ( ref $self->{"NotifyHandler"} eq "CODE"); ($rcode, $ans, $auth, $add, $headermask) = - &{$self->{"NotifyHandler"}}($qname, $qclass, $qtype, $peerhost, $query); + &{$self->{"NotifyHandler"}}($qname, $qclass, $qtype, $peerhost, $query, $conn); } print "$rcode\n" if $self->{"Verbose"}; @@ -310,7 +310,13 @@ my $qbuf = substr($self->{"_tcp"}{$sock}{"inbuffer"}, 0, $self->{"_tcp"}{$sock}{"querylength"}); substr($self->{"_tcp"}{$sock}{"inbuffer"}, 0, $self->{"_tcp"}{$sock}{"querylength"}) = ""; my $query = Net::DNS::Packet->new(\$qbuf); - my $reply = $self->make_reply($query, $sock->peerhost); + my $conn = { + sockhost => $self->{"_tcp"}{$sock}->sockhost, + sockport => $self->{"_tcp"}{$sock}->sockport, + peerhost => $self->{"_tcp"}{$sock}->peerhost, + peerport => $self->{"_tcp"}{$sock}->peerport + }; + my $reply = $self->make_reply($query, $sock->peerhost, $conn); if (not defined $reply) { print "I couldn't create a reply for $peer. Closing socket.\n" if $self->{"Verbose"}; @@ -348,7 +354,13 @@ my $query = Net::DNS::Packet->new(\$buf); - my $reply = $self->make_reply($query, $peerhost) || return; + my $conn = { + sockhost => $sock->sockhost, + sockport => $sock->sockport, + peerhost => $sock->peerhost, + peerport => $sock->peerport + }; + my $reply = $self->make_reply($query, $peerhost, $conn) || return; my $reply_data = $reply->data; local $| = 1 if $self->{"Verbose"};
Except that for TCP the patch should read: sockhost => $self->{"_tcp"}{$sock}{sockhost}, sockport => $self->{"_tcp"}{$sock}{sockport}, peerhost => $self->{"_tcp"}{$sock}{peerhost}, peerport => $self->{"_tcp"}{$sock}{peerport} (I think) I'll put this code in the next release...unless further testing introduces problems. (FWIW, I had allready added something like this, except less details, on the trunk. Your solution is cleaner though)
On Tue Dec 16 10:55:40 2008, OLAF wrote: Show quoted text
> Except that for TCP the patch should read: > sockhost => $self->{"_tcp"}{$sock}{sockhost}, > sockport => $self->{"_tcp"}{$sock}{sockport}, > peerhost => $self->{"_tcp"}{$sock}{peerhost}, > peerport => $self->{"_tcp"}{$sock}{peerport} > > (I think)
The above was not correct....
On Tue Dec 16 10:55:40 2008, OLAF wrote: Show quoted text
> Except that for TCP the patch should read: > sockhost => $self->{"_tcp"}{$sock}{sockhost}, > sockport => $self->{"_tcp"}{$sock}{sockport}, > peerhost => $self->{"_tcp"}{$sock}{peerhost}, > peerport => $self->{"_tcp"}{$sock}{peerport} > > (I think)
The above was not correct....
Solved on the trunk as of revision 734