if gethostbyname fails with a trailing dot, try it without the dot
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 14 Mar 1994 01:21:14 +0000 (17:21 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 14 Mar 1994 01:21:14 +0000 (17:21 -0800)
for NIS & /etc/hosts back compatibility

SCCS-vsn: usr.sbin/sendmail/src/daemon.c 8.39

usr/src/usr.sbin/sendmail/src/daemon.c

index 6d62b1b..1e1b63a 100644 (file)
@@ -12,9 +12,9 @@
 
 #ifndef lint
 #ifdef DAEMON
 
 #ifndef lint
 #ifdef DAEMON
-static char sccsid[] = "@(#)daemon.c   8.38 (Berkeley) %G% (with daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.39 (Berkeley) %G% (with daemon mode)";
 #else
 #else
-static char sccsid[] = "@(#)daemon.c   8.38 (Berkeley) %G% (without daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.39 (Berkeley) %G% (without daemon mode)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -272,6 +272,12 @@ makeconnection(host, port, mci, usesecureport)
                        {
                                /* try it as a host name (avoid MX lookup) */
                                hp = gethostbyname(&host[1]);
                        {
                                /* try it as a host name (avoid MX lookup) */
                                hp = gethostbyname(&host[1]);
+                               if (hp == NULL && p[-1] == '.')
+                               {
+                                       p[-1] = '\0';
+                                       hp = gethostbyname(&host[1]);
+                                       p[-1] = '.';
+                               }
                                *p = ']';
                                goto gothostent;
                        }
                                *p = ']';
                                goto gothostent;
                        }
@@ -289,7 +295,15 @@ makeconnection(host, port, mci, usesecureport)
        }
        else
        {
        }
        else
        {
+               register char *p = &host[strlen(host) - 1];
+
                hp = gethostbyname(host);
                hp = gethostbyname(host);
+               if (hp == NULL && *p == '.')
+               {
+                       *p = '\0';
+                       hp = gethostbyname(host);
+                       *p = '.';
+               }
 gothostent:
                if (hp == NULL)
                {
 gothostent:
                if (hp == NULL)
                {