#define nil ((void*)0)
#include <sys/types.h>
#include <stdio.h>
+#include <syslog.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
static u32_t httl; /* TTL for /etc/hosts data. */
static int reinit, done; /* Reinit config / program is done. */
static int single; /* Run single on a nondefault interface. */
+static int localonly; /* Only accept local queries. */
+#define LOCALHOST 0x7F000001
static void report(const char *label)
{
time_t ht, dt;
/* See if anything really changed. */
- if (((ifip ^ HTONL(0x7F000000)) & HTONL(0xFF000000)) == 0) ifip= my_ip;
+ if (((ifip ^ HTONL(LOCALHOST)) & HTONL(0xFF000000)) == 0) ifip= my_ip;
ht= filetime(HOSTS);
dt= filetime(DHCPCACHE);
if (ifip == my_ip && ht == hosts_time && dt == dhcp_time) return;
unsigned ancount;
struct hostent localhost;
static char *noaliases[]= { nil };
- static ipaddr_t localaddr= HTONL(0x7F000001L);
+ static ipaddr_t localaddr= HTONL(LOCALHOST);
static char *localaddrlist[]= { (char *) &localaddr, nil };
if (single) return 0;
/* A query. */
if (udp.dns.hdr.dh_qdcount != HTONS(1)) return 1;
+ if(localonly) {
+ /* Check if it's a local query. */
+ if(ntohl(udp.hdr.uih_src_addr) != LOCALHOST) {
+ syslog(LOG_WARNING, "nonamed: dropped query from %s",
+ inet_ntoa(udp.hdr.uih_src_addr));
+ return 1;
+ }
+ }
+
/* Try to compose a reply from local data. */
if (compose_reply(&udp.dns, &dlen)) {
udp.hdr.uih_dst_addr= udp.hdr.uih_src_addr;
case 'q': /* Quit after printing cache contents. */
quit= 1;
break;
+ case 'L':
+ localonly= 1;
+ break;
default:
usage();
}
newjob(job_setup_listen, IMMEDIATE, nil);
newjob(job_find_named, IMMEDIATE, nil);
+ /* Open syslog. */
+ openlog("nonamed", LOG_PID, LOG_DAEMON);
+
while (!done) {
/* There is always something in the queue. */
assert(queue != nil);