Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!legato!nowicki From: nowicki@legato (Bill Nowicki) Newsgroups: comp.mail.sendmail Subject: Re: How to recognize domain literals (was Re: How to use IP addresses ...) Summary: Fixed in SunOS 4.1 Message-ID: <1100@legato.LEGATO.COM> Date: 6 Dec 89 01:41:50 GMT References: <8911292029.AA13662@jvncf.csc.org> <1436@utkcs2.cs.utk.edu> <3472@jhunix.HCF.JHU.EDU> <1439@utkcs2.cs.utk.edu> Reply-To: nowicki@legato (Bill Nowicki) Organization: Legato Systems, Inc., Palo Alto, CA Lines: 84 In article <1439@utkcs2.cs.utk.edu> moore@cs.utk.edu (Keith Moore) writes: >In article <3472@jhunix.HCF.JHU.EDU> ecf_hap@jhunix.UUCP (Andrew Poling) writes: >>In article <1436@utkcs2.cs.utk.edu> moore@cs.utk.edu (Keith Moore) writes: >>>In article , >>> cfe+@andrew.cmu.edu (Craig F. Everhart) writes: >>>(lamenting the fact that most sendmail sites don't recognize domain literals) ... >The only reason to use domain literals at all is as a trapdoor for when >the name server / host tables are incorrect or insufficient. So it's >important that they work properly even if the name server database at some >particular site is bogus. > Yes! The only time I have ever had to send mail to an explicit IP address was when the name server for that site was broken. As you note, that is exactly the same case in which $[ fails. That is the general problem with $[ -- there is no well-defined error behavior. Sometimes you want it to quietly act as a no-op on any error, other times you want to force a re-queue of the message, etc. >(Sendmail really should pre-define a class that will match all local >IP addresses as obtained from the SIOCGIFCONF ioctl; then the matches >would be foolproof.) This is actually simple to do. I did this while working for "a certain major Unix vendor" many months ago. Since SunOS 4.x sendmail had the ability to match multiple tokens in a class (see my last message) from the IDA enhancements, all you need to do is add these to the $=w class. You might also want to shuffle a few lines in the sendmail.cf file to match $=w before the IP dotted-quad. This is the way SunOS 4.1 was set up to work, so that you can use the exact same sendmail.cf file on tens of thousands of systems instead of needing to diddle each one manually. You can get a sendmail with this feature from uunet.uu.net:~ftp/sun-fixes. For those of you who like source: char ** myhostname(hostbuf, size) char hostbuf[]; int size; { extern struct hostent *gethostbyname(); struct hostent *hp; static char *nicknames[MAXATOM]; register char **avp, *thisname; int s, n; struct ifconf ifc; struct ifreq *ifr; char interfacebuf[1024]; if (gethostname(hostbuf, size) < 0) { (void) strcpy(hostbuf, "localhost"); } hp = gethostbyname(hostbuf); if (hp == NULL) return (NULL); (void) strncpy(hostbuf, hp->h_name, size-1); for (avp=nicknames;*hp->h_aliases;) *avp++ = *hp->h_aliases++; *avp = NULL; s = socket(AF_INET, SOCK_DGRAM, 0); if (s == -1) return (nicknames); ifc.ifc_len = sizeof(interfacebuf); ifc.ifc_buf = interfacebuf; if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) return (nicknames); ifr = ifc.ifc_req; for (n = ifc.ifc_len/sizeof (struct ifreq); n > 0; n--, ifr++) { char thisbuf[256]; if (ifr->ifr_addr.sa_family != AF_INET) continue; (void) sprintf(thisbuf, "[%s]", inet_ntoa( ((struct sockaddr_in *)(&ifr->ifr_addr))->sin_addr)); thisname = newstr(thisbuf); *avp++ = thisname; } *avp = NULL; return (nicknames); }