Subject: An option for syslogd
To: None <tech-misc@netbsd.org>
From: Nikolay Silkin <nikolay.n.silkin@vanderbilt.edu>
List: tech-misc
Date: 01/12/2001 20:20:59
Hello All,

I would like to suggest a command line option to syslogd.
It allows to omit domain name resolution when syslogd accepts
and logs messages from remote hosts through a datagram socket.
The option is -n (analogous to netstat -n). Below are the diff's
that one can apply to the 1.5 release source of syslogd
(just one file, /usr/src/usr.sbin/syslogd/syslogd.c) to achieve this
effect. It is just about 6 new lines of code. I plan to build a NetBSD
based log server for a local net and it seems that having an option
of not waiting for DNS servers to reply may be quite convenient.

Comments and sugestions are appreciated. Please cc your reply to my e-mail
address as well.


Regards,

Nikolay Silkin


P.S: The diffs below are not formatted according to NetBSD's standard, sorry.

========== below are the diffs, save it as syslogd.diffs 
========== apply by 'patch syslogd.c syslogd.diffs' from the syslogd src dir
--- syslogd.c   Thu Jan 11 19:57:31 2001
+++ syslogd.c   Thu Jan 11 19:59:31 2001
@@ -192,6 +192,7 @@
 int    MarkInterval = 20 * 60; /* interval between marks in seconds */
 int    MarkSeq = 0;            /* mark sequence number */
 int    SecureMode = 0;         /* listen only on unix domain socks */
+int    UseNameService = 1;     /* make domain name queries */
 int    NumForwards = 0;        /* number of forwarding actions in conf file 
*/
 char   **LogPaths;             /* array of pathnames to read messages from */
 
@@ -228,7 +229,7 @@
        char *p, *line, **pp;
        struct pollfd *readfds;
 
-       while ((ch = getopt(argc, argv, "dsf:m:p:P:")) != -1)
+       while ((ch = getopt(argc, argv, "dnsf:m:p:P:")) != -1)
                switch(ch) {
                case 'd':               /* debug */
                        Debug++;
@@ -239,6 +240,9 @@
                case 'm':               /* mark interval */
                        MarkInterval = atoi(optarg) * 60;
                        break;
+               case 'n':               /* turn off DNS queries */
+                       UseNameService = 0;
+                       break;
                case 'p':               /* path */
                        logpath_add(&LogPaths, &funixsize,
                            &funixmaxsize, optarg);
@@ -946,15 +950,19 @@
                return ("???");
        }
 
-       error = getnameinfo((struct sockaddr*)f, ((struct 
sockaddr*)f)->sa_len,
-                       host, sizeof host, NULL, 0, niflag);
-       if (error) {
-               dprintf("Host name for your address (%s) unknown\n", ip);
-               return (ip);
+       if (UseNameService) {
+               error = getnameinfo((struct sockaddr*)f, ((struct 
sockaddr*)f)->
sa_len,
+                               host, sizeof host, NULL, 0, niflag);
+               if (error) {
+                       dprintf("Host name for your address (%s) unknown\n", 
ip)
;
+                       return (ip);
+               }
+               if ((p = strchr(host, '.')) && strcmp(p + 1, LocalDomain) == 
0)
+                       *p = '\0';
+               return (host);
+       } else {
+               return(ip);
        }
-       if ((p = strchr(host, '.')) && strcmp(p + 1, LocalDomain) == 0)
-               *p = '\0';
-       return (host);
 }

 void