+\f/*
+** HOSTSIGNATURE -- return the "signature" for a host.
+**
+** The signature describes how we are going to send this -- it
+** can be just the hostname (for non-Internet hosts) or can be
+** an ordered list of MX hosts.
+**
+** Parameters:
+** m -- the mailer describing this host.
+** host -- the host name.
+** e -- the current envelope.
+**
+** Returns:
+** The signature for this host.
+**
+** Side Effects:
+** Can tweak the symbol table.
+*/
+
+char *
+hostsignature(m, host, e)
+ register MAILER *m;
+ char *host;
+ ENVELOPE *e;
+{
+ register char *p;
+ register STAB *s;
+ int i;
+ int len;
+#ifdef NAMED_BIND
+ int nmx;
+ auto int rcode;
+ char *mxhosts[MAXMXHOSTS + 1];
+ static char myhostbuf[MAXNAME];
+#endif
+
+ /*
+ ** Check to see if this uses IPC -- if not, it can't have MX records.
+ */
+
+ p = m->m_mailer;
+ if (strcmp(p, "[IPC]") != 0 && strcmp(p, "[TCP]") != 0)
+ {
+ /* just an ordinary mailer */
+ return host;
+ }
+
+ /*
+ ** If it is a numeric address, just return it.
+ */
+
+ if (host[0] == '[')
+ return host;
+
+ /*
+ ** Look it up in the symbol table.
+ */
+
+ s = stab(host, ST_HOSTSIG, ST_ENTER);
+ if (s->s_hostsig != NULL)
+ return s->s_hostsig;
+
+ /*
+ ** Not already there -- create a signature.
+ */
+
+#ifdef NAMED_BIND
+ if (myhostbuf[0] == '\0')
+ expand("\001j", myhostbuf, &myhostbuf[sizeof myhostbuf - 1], e);
+
+ nmx = getmxrr(host, mxhosts, myhostbuf, &rcode);
+ if (nmx <= 0)
+ {
+ register MCI *mci;
+ extern int errno;
+ extern MCI *mci_get();
+
+ /* update the connection info for this host */
+ mci = mci_get(host, m);
+ mci->mci_exitstat = rcode;
+ mci->mci_errno = errno;
+
+ /* and return the original host name as the signature */
+ s->s_hostsig = host;
+ return host;
+ }
+
+ len = 0;
+ for (i = 0; i < nmx; i++)
+ {
+ len += strlen(mxhosts[i]) + 1;
+ }
+ s->s_hostsig = p = xalloc(len);
+ for (i = 0; i < nmx; i++)
+ {
+ if (i != 0)
+ *p++ = ':';
+ strcpy(p, mxhosts[i]);
+ p += strlen(p);
+ }
+ makelower(s->s_hostsig);
+#else
+ /* not using BIND -- the signature is just the host name */
+ s->s_hostsig = host;
+#endif
+ if (tTd(17, 1))
+ printf("hostsignature(%s) = %s\n", host, s->s_hostsig);
+ return s->s_hostsig;
+}