@@ -12,30 +12,24 @@ use Getopt::Long;
12
12
use Socket;
13
13
14
14
my %opts = (verbose => 0);
15
- GetOptions (\%opts ,
16
- ' interface=s@' ,
17
- ' user=s' ,
18
- ' verbose!' ,
19
- ' config=s' ,
20
- ' configtest!' ,
21
- ' development!' ,
22
- ' port=i' ,
23
- ) or die " invalid options" ;
15
+ GetOptions(\%opts , ' interface=s@' , ' user=s' , ' verbose!' , ' config=s' , ' configtest!' , ' development!' ,
16
+ ' port=i' ,)
17
+ or die " invalid options" ;
24
18
25
19
26
20
my $config_file = $opts {config } || ' pgeodns.conf' ;
27
- my $port = $opts {port } || 53;
21
+ my $port = $opts {port } || 53;
28
22
29
- exit !GeoDNS::load_config({},$config_file )
23
+ exit !GeoDNS::load_config({}, $config_file )
30
24
if $opts {configtest };
31
25
32
26
die " --interface [ip|hostname] required\n " unless $opts {interface };
33
- die " --user [user|uid] required\n " if $> ==0 and !$opts {user };
27
+ die " --user [user|uid] required\n " if $> == 0 and !$opts {user };
34
28
35
- $opts {interface } = [ $opts {interface } ] unless ref $opts {interface };
36
- $opts {interface } = [ map { split /\s *,\s */ } @{$opts {interface }} ];
29
+ $opts {interface } = [$opts {interface }] unless ref $opts {interface };
30
+ $opts {interface } = [map { split /\s *,\s */ } @{$opts {interface }}];
37
31
38
- for my $i ( 0 .. scalar @{$opts {interface }} - 1) {
32
+ for my $i (0 .. scalar @{$opts {interface }} - 1) {
39
33
my $localaddr = $opts {interface }-> [$i ];
40
34
if ($localaddr =~ / [^\d\. ]/ ) {
41
35
my $addr = inet_ntoa((gethostbyname ($localaddr ))[4]);
@@ -44,47 +38,47 @@ for my $i ( 0 .. scalar @{$opts{interface}} - 1) {
44
38
}
45
39
}
46
40
47
- my $g = GeoDNS-> new(server_id => $opts {interface }-> [0],
48
- debug => 1,
49
- config_file => $opts {config },
50
- development => ($opts {development } ? 1 : 0),
51
- );
41
+ my $g = GeoDNS-> new(
42
+ server_id => $opts {interface }-> [0],
43
+ debug => 1,
44
+ config_file => $opts {config },
45
+ development => ($opts {development } ? 1 : 0),
46
+ );
52
47
53
48
54
49
printf " \n Starting GeoDNS %s \n " , $g -> version_full;
55
50
56
- my $ns = Net::DNS::Nameserver-> new
57
- (
58
- LocalPort => $port ,
59
- LocalAddr => $opts { interface },
60
- ReplyHandler => sub {
61
- my @reply = $g -> reply_handler( @_ );
62
- # warn Data::Dumper->Dump([\@reply], [qw(reply)]);
63
- @reply
64
- },
65
- Verbose => $opts {verbose },
66
- );
51
+ my $ns = Net::DNS::Nameserver-> new(
52
+ LocalPort => $port ,
53
+ LocalAddr => $opts { interface } ,
54
+ ReplyHandler => sub {
55
+ my @reply = $g -> reply_handler( @_ );
56
+
57
+ # warn Data::Dumper->Dump([\@reply], [qw(reply)]);
58
+ @reply ;
59
+ },
60
+ Verbose => $opts {verbose },
61
+ );
67
62
68
63
# print error?
69
64
die " couldn't create nameserver object\n " unless $ns ;
70
65
71
66
if (my $uid = $opts {user }) {
72
67
$uid = getpwnam ($uid ) or die " could not lookup uid"
73
- if $uid =~ m /\D / ;
68
+ if $uid =~ m /\D / ;
74
69
setuid($uid ) or die " could not setuid: $! " ;
75
70
}
76
71
77
72
$g -> load_config($config_file );
78
73
79
74
if ($ns ) {
80
- $ns -> main_loop;
75
+ $ns -> main_loop;
81
76
}
82
77
else {
83
- die " couldn't create nameserver object\n " ;
78
+ die " couldn't create nameserver object\n " ;
84
79
}
85
80
86
81
87
-
88
82
__END__
89
83
90
84
=pod
0 commit comments