h_errno = 0;
SM_SET_H_ERRNO(0);
giveresponse(status, dsn, m, mci, ctladdr, xstart, e)	int status;	char *dsn;	register MAILER *m;	register MCI *mci;	ADDRESS *ctladdr;	time_t xstart;	ENVELOPE *e;{	register const char *statmsg;	extern char *SysExMsg[];	register int i;	int errnum = errno;	int off = 4;	extern int N_SysEx;	char dsnbuf[ENHSCLEN];	char buf[MAXLINE];	if (e == NULL)		syserr("giveresponse: null envelope");	/*	**  Compute status message from code.	*/	i = status - EX__BASE;	if (status == 0)	{		statmsg = "250 2.0.0 Sent";		if (e->e_statmsg != NULL)		{			(void) snprintf(buf, sizeof buf, "%s (%s)",					statmsg,					shortenstring(e->e_statmsg, 403));			statmsg = buf;		}	}	else if (i < 0 || i >= N_SysEx)	{		(void) snprintf(buf, sizeof buf,				"554 5.3.0 unknown mailer error %d",				status);		status = EX_UNAVAILABLE;		statmsg = buf;	}	else if (status == EX_TEMPFAIL)	{		char *bp = buf;		snprintf(bp, SPACELEFT(buf, bp), "%s", SysExMsg[i] + 1);		bp += strlen(bp);#if NAMED_BIND		if (h_errno == TRY_AGAIN)			statmsg = errstring(h_errno+E_DNSBASE);		else#endif /* NAMED_BIND */		{			if (errnum != 0)				statmsg = errstring(errnum);			else			{#if SMTP				statmsg = SmtpError;#else /* SMTP */				statmsg = NULL;#endif /* SMTP */			}		}		if (statmsg != NULL && statmsg[0] != '\0')		{			switch (errnum)			{#ifdef ENETDOWN			  case ENETDOWN:	/* Network is down */#endif /* ENETDOWN */#ifdef ENETUNREACH			  case ENETUNREACH:	/* Network is unreachable */#endif /* ENETUNREACH */#ifdef ENETRESET			  case ENETRESET:	/* Network dropped connection on reset */#endif /* ENETRESET */#ifdef ECONNABORTED			  case ECONNABORTED:	/* Software caused connection abort */#endif /* ECONNABORTED */#ifdef EHOSTDOWN			  case EHOSTDOWN:	/* Host is down */#endif /* EHOSTDOWN */#ifdef EHOSTUNREACH			  case EHOSTUNREACH:	/* No route to host */#endif /* EHOSTUNREACH */				if (mci->mci_host != NULL)				{					snprintf(bp, SPACELEFT(buf, bp),						 ": %s", mci->mci_host);					bp += strlen(bp);				}				break;			}			snprintf(bp, SPACELEFT(buf, bp), ": %s", statmsg);		}		statmsg = buf;	}#if NAMED_BIND	else if (status == EX_NOHOST && h_errno != 0)	{		statmsg = errstring(h_errno + E_DNSBASE);		(void) snprintf(buf, sizeof buf, "%s (%s)",			SysExMsg[i] + 1, statmsg);		statmsg = buf;	}#endif /* NAMED_BIND */	else	{		statmsg = SysExMsg[i];		if (*statmsg++ == ':' && errnum != 0)		{			(void) snprintf(buf, sizeof buf, "%s: %s",				statmsg, errstring(errnum));			statmsg = buf;		}	}	/*	**  Print the message as appropriate	*/	if (status == EX_OK || status == EX_TEMPFAIL)	{		extern char MsgBuf[];		if ((off = isenhsc(statmsg + 4, ' ')) > 0)		{			if (dsn == NULL)			{				snprintf(dsnbuf, sizeof dsnbuf,					 "%.*s", off, statmsg + 4);				dsn = dsnbuf;			}			off += 5;		}		else		{			off = 4;		}		message("%s", statmsg + off);		if (status == EX_TEMPFAIL && e->e_xfp != NULL)			fprintf(e->e_xfp, "%s\n", &MsgBuf[4]);	}	else	{		char mbuf[ENHSCLEN + 4];		Errors++;		if ((off = isenhsc(statmsg + 4, ' ')) > 0 &&		    off < sizeof mbuf - 4)		{			if (dsn == NULL)			{				snprintf(dsnbuf, sizeof dsnbuf,					 "%.*s", off, statmsg + 4);				dsn = dsnbuf;			}			off += 5;			(void) strlcpy(mbuf, statmsg, off);			(void) strlcat(mbuf, " %s", sizeof mbuf);		}		else		{			dsnbuf[0] = '\0';			(void) snprintf(mbuf, sizeof mbuf, "%.3s %%s", statmsg);			off = 4;		}		usrerr(mbuf, &statmsg[off]);	}	/*	**  Final cleanup.	**	Log a record of the transaction.  Compute the new	**	ExitStat -- if we already had an error, stick with	**	that.	*/	if (OpMode != MD_VERIFY && !bitset(EF_VRFYONLY, e->e_flags) &&	    LogLevel > ((status == EX_TEMPFAIL) ? 8 : (status == EX_OK) ? 7 : 6))		logdelivery(m, mci, dsn, statmsg + off, ctladdr, xstart, e);	if (tTd(11, 2))		dprintf("giveresponse: status=%d, dsn=%s, e->e_message=%s\n",			status,			dsn == NULL ? "<NULL>" : dsn,			e->e_message == NULL ? "<NULL>" : e->e_message);	if (status != EX_TEMPFAIL)		setstat(status);	if (status != EX_OK && (status != EX_TEMPFAIL || e->e_message == NULL))	{		if (e->e_message != NULL)			free(e->e_message);		e->e_message = newstr(statmsg + off);	}	errno = 0;#if NAMED_BIND	h_errno = 0;#endif /* NAMED_BIND */}