1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

[fix] Fakedns doesn't need ip in args

This commit is contained in:
ljf 2023-03-13 03:02:36 +01:00
parent 5c01597490
commit 2bfee6653a
No known key found for this signature in database

View file

@ -3,8 +3,24 @@
use strict; use strict;
use warnings; use warnings;
use Net::DNS::Nameserver; use Net::DNS::Nameserver;
use IO::Socket::INET;
my $ip4_addr = shift @ARGV; # This idea was stolen from Net::Address::IP::Local::connected_to()
sub get_local_ip_address {
my $socket = IO::Socket::INET->new(
Proto => 'udp',
PeerAddr => '198.41.0.4', # a.root-servers.net
PeerPort => '53', # DNS
);
# A side-effect of making a socket connection is that our IP address
# is available from the 'sockhost' method
my $local_ip_address = $socket->sockhost;
return $local_ip_address;
}
my $ip4_addr = get_local_ip_address();
sub reply_handler { sub reply_handler {
my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_; my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
@ -25,7 +41,7 @@ sub reply_handler {
my $ns = new Net::DNS::Nameserver( my $ns = new Net::DNS::Nameserver(
LocalPort => 4253, LocalPort => 4253,
LocalAddr => $ip4_addr, LocalAddr => '0.0.0.0',
ReplyHandler => \&reply_handler, ReplyHandler => \&reply_handler,
Verbose => 0 Verbose => 0
) || die "Couldn't create fake nameserver object.\n"; ) || die "Couldn't create fake nameserver object.\n";