106
109
{ 'z', OPT_NOWILD },
107
110
{ 'Z', OPT_ETHERS },
108
111
{ 'y', OPT_LOCALISE },
113
{ '3', OPT_BOOTP_DYNAMIC },
115
"Usage: dnsmasq [options]\n\n"
116
#ifndef HAVE_GETOPT_LONG
117
"Use short options only on the command line.\n"
119
"Valid options are :\n"
120
"-a, --listen-address=ipaddr Specify local address(es) to listen on.\n"
121
"-A, --address=/domain/ipaddr Return ipaddr for all hosts in specified domains.\n"
122
"-b, --bogus-priv Fake reverse lookups for RFC1918 private address ranges.\n"
123
"-B, --bogus-nxdomain=ipaddr Treat ipaddr as NXDOMAIN (defeats Verisign wildcard).\n"
124
"-c, --cache-size=cachesize Specify the size of the cache in entries (defaults to %d).\n"
125
"-C, --conf-file=path Specify configuration file (defaults to " CONFFILE ").\n"
126
"-d, --no-daemon Do NOT fork into the background: run in debug mode.\n"
127
"-D, --domain-needed Do NOT forward queries with no domain part.\n"
128
"-e, --selfmx Return self-pointing MX records for local hosts.\n"
129
"-E, --expand-hosts Expand simple names in /etc/hosts with domain-suffix.\n"
130
"-f, --filterwin2k Don't forward spurious DNS requests from Windows hosts.\n"
131
"-F, --dhcp-range=ipaddr,ipaddr,time Enable DHCP in the range given with lease duration.\n"
132
"-g, --group=groupname Change to this group after startup (defaults to " CHGRP ").\n"
133
"-G, --dhcp-host=<hostspec> Set address or hostname for a specified machine.\n"
134
"-h, --no-hosts Do NOT load " HOSTSFILE " file.\n"
135
"-H, --addn-hosts=path Specify a hosts file to be read in addition to " HOSTSFILE ".\n"
136
"-i, --interface=interface Specify interface(s) to listen on.\n"
137
"-I, --except-interface=int Specify interface(s) NOT to listen on.\n"
138
"-j, --dhcp-userclass=<id>,<class> Map DHCP user class to option set.\n"
139
"-J, --dhcp-ignore=<id> Don't do DHCP for hosts in option set.\n"
140
"-k, --keep-in-foreground Do NOT fork into the background, do NOT run in debug mode.\n"
141
"-K, --dhcp-authoritative Assume we are the only DHCP server on the local network.\n"
142
"-l, --dhcp-leasefile=path Specify where to store DHCP leases (defaults to " LEASEFILE ").\n"
143
"-L, --localmx Return MX records for local hosts.\n"
144
"-m, --mx-host=host_name,target,pref Specify an MX record.\n"
145
"-M, --dhcp-boot=<bootp opts> Specify BOOTP options to DHCP server.\n"
146
"-n, --no-poll Do NOT poll " RESOLVFILE " file, reload only on SIGHUP.\n"
147
"-N, --no-negcache Do NOT cache failed search results.\n"
148
"-o, --strict-order Use nameservers strictly in the order given in " RESOLVFILE ".\n"
149
"-O, --dhcp-option=<optspec> Set extra options to be set to DHCP clients.\n"
150
"-p, --port=number Specify port to listen for DNS requests on (defaults to 53).\n"
151
"-P, --edns-packet-max=<size> Maximum supported UDP packet size for EDNS.0 (defaults to %d).\n"
152
"-q, --log-queries Log queries.\n"
153
"-Q, --query-port=number Force the originating port for upstream queries.\n"
154
"-R, --no-resolv Do NOT read resolv.conf.\n"
155
"-r, --resolv-file=path Specify path to resolv.conf (defaults to " RESOLVFILE ").\n"
156
"-S, --server=/domain/ipaddr Specify address(es) of upstream servers with optional domains.\n"
157
" --local=/domain/ Never forward queries to specified domains.\n"
158
"-s, --domain=domain Specify the domain to be assigned in DHCP leases.\n"
159
"-t, --mx-target=host_name Specify default target in an MX record.\n"
160
"-T, --local-ttl=time Specify time-to-live in seconds for replies from /etc/hosts.\n"
161
"-u, --user=username Change to this user after startup. (defaults to " CHUSER ").\n"
162
"-U, --dhcp-vendorclass=<id>,<class> Map DHCP vendor class to option set.\n"
163
"-v, --version Display dnsmasq version and copyright information.\n"
164
"-V, --alias=addr,addr,mask Translate IPv4 addresses from upstream servers.\n"
165
"-W, --srv-host=name,target,... Specify a SRV record.\n"
166
"-w, --help Display this message.\n"
167
"-x, --pid-file=path Specify path of PID file. (defaults to " RUNFILE ").\n"
168
"-X, --dhcp-lease-max=number Specify maximum number of DHCP leases (defaults to %d).\n"
169
"-y, --localise-queries Answer DNS queries based on the interface a query was sent to.\n"
170
"-Y --txt-record=name,txt.... Specify TXT DNS record.\n"
171
"-z, --bind-interfaces Bind only to interfaces in use.\n"
172
"-Z, --read-ethers Read DHCP static host information from " ETHERSFILE ".\n"
119
static const struct {
124
{ "-a, --listen-address=ipaddr", gettext_noop("Specify local address(es) to listen on."), NULL },
125
{ "-A, --address=/domain/ipaddr", gettext_noop("Return ipaddr for all hosts in specified domains."), NULL },
126
{ "-b, --bogus-priv", gettext_noop("Fake reverse lookups for RFC1918 private address ranges."), NULL },
127
{ "-B, --bogus-nxdomain=ipaddr", gettext_noop("Treat ipaddr as NXDOMAIN (defeats Verisign wildcard)."), NULL },
128
{ "-c, --cache-size=cachesize", gettext_noop("Specify the size of the cache in entries (defaults to %s)."), "$" },
129
{ "-C, --conf-file=path", gettext_noop("Specify configuration file (defaults to %s)."), CONFFILE },
130
{ "-d, --no-daemon", gettext_noop("Do NOT fork into the background: run in debug mode."), NULL },
131
{ "-D, --domain-needed", gettext_noop("Do NOT forward queries with no domain part."), NULL },
132
{ "-e, --selfmx", gettext_noop("Return self-pointing MX records for local hosts."), NULL },
133
{ "-E, --expand-hosts", gettext_noop("Expand simple names in /etc/hosts with domain-suffix."), NULL },
134
{ "-f, --filterwin2k", gettext_noop("Don't forward spurious DNS requests from Windows hosts."), NULL },
135
{ "-F, --dhcp-range=ipaddr,ipaddr,time", gettext_noop("Enable DHCP in the range given with lease duration."), NULL },
136
{ "-g, --group=groupname", gettext_noop("Change to this group after startup (defaults to %s)."), CHGRP },
137
{ "-G, --dhcp-host=<hostspec>", gettext_noop("Set address or hostname for a specified machine."), NULL },
138
{ "-h, --no-hosts", gettext_noop("Do NOT load %s file."), HOSTSFILE },
139
{ "-H, --addn-hosts=path", gettext_noop("Specify a hosts file to be read in addition to %s."), HOSTSFILE },
140
{ "-i, --interface=interface", gettext_noop("Specify interface(s) to listen on."), NULL },
141
{ "-I, --except-interface=int", gettext_noop("Specify interface(s) NOT to listen on.") , NULL },
142
{ "-j, --dhcp-userclass=<id>,<class>", gettext_noop("Map DHCP user class to option set."), NULL },
143
{ "-J, --dhcp-ignore=<id>", gettext_noop("Don't do DHCP for hosts in option set."), NULL },
144
{ "-k, --keep-in-foreground", gettext_noop("Do NOT fork into the background, do NOT run in debug mode."), NULL },
145
{ "-K, --dhcp-authoritative", gettext_noop("Assume we are the only DHCP server on the local network."), NULL },
146
{ "-l, --dhcp-leasefile=path", gettext_noop("Specify where to store DHCP leases (defaults to %s)."), LEASEFILE },
147
{ "-L, --localmx", gettext_noop("Return MX records for local hosts."), NULL },
148
{ "-m, --mx-host=host_name,target,pref", gettext_noop("Specify an MX record."), NULL },
149
{ "-M, --dhcp-boot=<bootp opts>", gettext_noop("Specify BOOTP options to DHCP server."), NULL },
150
{ "-n, --no-poll", gettext_noop("Do NOT poll %s file, reload only on SIGHUP."), RESOLVFILE },
151
{ "-N, --no-negcache", gettext_noop("Do NOT cache failed search results."), NULL },
152
{ "-o, --strict-order", gettext_noop("Use nameservers strictly in the order given in %s."), RESOLVFILE },
153
{ "-O, --dhcp-option=<optspec>", gettext_noop("Set extra options to be set to DHCP clients."), NULL },
154
{ "-p, --port=number", gettext_noop("Specify port to listen for DNS requests on (defaults to 53)."), NULL },
155
{ "-P, --edns-packet-max=<size>", gettext_noop("Maximum supported UDP packet size for EDNS.0 (defaults to %s)."), "*" },
156
{ "-q, --log-queries", gettext_noop("Log queries."), NULL },
157
{ "-Q, --query-port=number", gettext_noop("Force the originating port for upstream queries."), NULL },
158
{ "-R, --no-resolv", gettext_noop("Do NOT read resolv.conf."), NULL },
159
{ "-r, --resolv-file=path", gettext_noop("Specify path to resolv.conf (defaults to %s)."), RESOLVFILE },
160
{ "-S, --server=/domain/ipaddr", gettext_noop("Specify address(es) of upstream servers with optional domains."), NULL },
161
{ " --local=/domain/", gettext_noop("Never forward queries to specified domains."), NULL },
162
{ "-s, --domain=domain", gettext_noop("Specify the domain to be assigned in DHCP leases."), NULL },
163
{ "-t, --mx-target=host_name", gettext_noop("Specify default target in an MX record."), NULL },
164
{ "-T, --local-ttl=time", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL },
165
{ "-u, --user=username", gettext_noop("Change to this user after startup. (defaults to %s)."), CHUSER },
166
{ "-U, --dhcp-vendorclass=<id>,<class>", gettext_noop("Map DHCP vendor class to option set."), NULL },
167
{ "-v, --version", gettext_noop("Display dnsmasq version and copyright information."), NULL },
168
{ "-V, --alias=addr,addr,mask", gettext_noop("Translate IPv4 addresses from upstream servers."), NULL },
169
{ "-W, --srv-host=name,target,...", gettext_noop("Specify a SRV record."), NULL },
170
{ "-w, --help", gettext_noop("Display this message."), NULL },
171
{ "-x, --pid-file=path", gettext_noop("Specify path of PID file. (defaults to %s)."), RUNFILE },
172
{ "-X, --dhcp-lease-max=number", gettext_noop("Specify maximum number of DHCP leases (defaults to %s)."), "&" },
173
{ "-y, --localise-queries", gettext_noop("Answer DNS queries based on the interface a query was sent to."), NULL },
174
{ "-Y --txt-record=name,txt....", gettext_noop("Specify TXT DNS record."), NULL },
175
{ "-z, --bind-interfaces", gettext_noop("Bind only to interfaces in use."), NULL },
176
{ "-Z, --read-ethers", gettext_noop("Read DHCP static host information from %s."), ETHERSFILE },
177
{ "-1, --enable-dbus", gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL },
178
{ "-2, --no-dhcp-interface=interface", gettext_noop("Do not provide DHCP on this interface, only provide DNS."), NULL },
179
{ "-3, --bootp-dynamic", gettext_noop("Enable dynamic address allocation for bootp."), NULL },
183
/* We hide metacharaters in quoted strings by mapping them into the ASCII control
184
character space. Note that the \0, \t \a \b \r and \n characters are carefully placed in the
185
following sequence so that they map to themselves: it is therefore possible to call
186
unhide_metas repeatedly on string without breaking things.
187
The transformation gets undone by opt_canonicalise, atoi_check and safe_string_alloc, and a
188
couple of other places. */
190
static const char meta[] = "\000123456\a\b\t\n78\r90abcdefABCDEF:,.";
192
static char hide_meta(char c)
196
for (i = 0; i < (sizeof(meta) - 1); i++)
203
static char unhide_meta(char cr)
207
if (c < (sizeof(meta) - 1))
213
static void unhide_metas(char *cp)
217
*cp = unhide_meta(*cp);
220
static char *safe_string_alloc(char *cp)
224
if (cp && strlen(cp) != 0)
226
ret = safe_malloc(strlen(cp)+1);
229
/* restore hidden metachars */
236
static char *safe_strchr(char *s, int c)
244
static int canonicalise_opt(char *s)
250
return canonicalise(s);
253
static int atoi_check(char *a, int *res)
263
if (*p < '0' || *p > '9')
175
270
static void add_txt(struct daemon *daemon, char *name, char *txt)