-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
104 lines (90 loc) · 2.85 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"flag"
"fmt"
"net"
"os"
"time"
"github.com/miekg/dns"
)
// Options - query options
type Options struct {
qopts QueryOptions
useV6 bool
useV4 bool
sortresponse bool
json bool
resolvconf string
resolvers []net.IP
masterIP net.IP
masterName string
additional string
noqueryns bool
masterSerial uint32
delta int
}
// Defaults
var (
defaultTimeout = 3
defaultRetries = 3
defaultSerialDelta = 0
)
func doFlags() (string, Options) {
var opts Options
help := flag.Bool("h", false, "print help string")
flag.BoolVar(&opts.useV6, "6", false, "use IPv6 only")
flag.BoolVar(&opts.useV4, "4", false, "use IPv4 only")
flag.BoolVar(&opts.sortresponse, "s", false, "sort responses")
flag.BoolVar(&opts.json, "j", false, "output json")
flag.BoolVar(&opts.qopts.tcp, "c", false, "use IPv4 only")
flag.StringVar(&opts.resolvconf, "cf", "", "use alternate resolv.conf file")
master := flag.String("m", "", "master server address")
flag.StringVar(&opts.additional, "a", "", "additional nameservers: n1,n2..")
flag.BoolVar(&opts.noqueryns, "n", false, "don't query advertised nameservers")
flag.IntVar(&opts.delta, "d", defaultSerialDelta, "allowed serial number drift")
timeoutp := flag.Int("t", defaultTimeout, "query timeout in seconds")
flag.IntVar(&opts.qopts.retries, "r", defaultRetries, "number of query retries")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, `%s, version %s
Usage: %s [Options] <zone>
Options:
-h Print this help string
-4 Use IPv4 transport only
-6 Use IPv6 transport only
-cf file Use alternate resolv.conf file
-s Print responses sorted by domain name and IP version
-j Produce json formatted output (implies -s)
-c Use TCP for queries (default: UDP with TCP on truncation)
-t N Query timeout value in seconds (default %d)
-r N Maximum # SOA query retries for each server (default %d)
-d N Allowed SOA serial number drift (default %d)
-m ns Master server name/address to compare serial numbers with
-a ns1,.. Specify additional nameserver names/addresses to query
-n Don't query advertised nameservers for the zone
`, progname, Version, progname, defaultTimeout, defaultRetries, defaultSerialDelta)
}
flag.Parse()
opts.qopts.timeout = time.Second * time.Duration(*timeoutp)
if *help {
flag.Usage()
os.Exit(4)
}
if *master != "" {
opts.masterIP = net.ParseIP(*master)
if opts.masterIP == nil { // assume hostname
opts.masterName = dns.Fqdn(*master)
}
}
if opts.useV4 && opts.useV6 {
fmt.Fprintf(os.Stderr, "Cannot specify both -4 and -6.\n")
flag.Usage()
os.Exit(4)
}
if flag.NArg() != 1 {
fmt.Fprintf(os.Stderr, "Incorrect number of arguments.\n")
flag.Usage()
os.Exit(4)
}
args := flag.Args()
return dns.Fqdn(args[0]), opts
}