
#ifdef X400
set_which_mts(msg_fp)
FILE	*msg_fp;
{
    register int  state;
    register char tmpbuf[BUFSIZ];
    char          name[NAMESZ];
    extern char   need_x400_me;

    for (state = FLD;state == FLD || state == FLDPLUS;) {
	state = m_getfld (state, name, tmpbuf, BUFSIZ, msg_fp);
	switch (state) {
	    case FLD: 
	    case FLDPLUS: 
		if (uleq(name, "X-mts"))
		    if (uleq(tmpbuf, "x400"))
			need_x400_me = 1;
		while (state == FLDPLUS)
		    state = m_getfld (state, name, tmpbuf, BUFSIZ, msg_fp);
		break;

	    case LENERR: 
	    case FMTERR: 
	    case BODY: 
	    case FILEEOF:
		break;

	    default: 
		adios (NULLCP, "m_getfld() returned %d", state);
	}
    }
    rewind(msg_fp);
}

char *
get_x400_orname()
{
int	pid, len;
int	pipefds[2];
char	ptr[BUFSIZ];

/* Open a pie channel for retrieving the output of x400_whois. */
    if (pipe(pipefds) != 0) {
	fprintf(stderr,"Can't get pipes for x400_whois!\n");
	return ((char *)NULL);
    }

    pid = fork();
    if (pid == -1)
	return((char *)NULL);

    if (pid > 0) {	/* Parent process. */
	if (wait(NULL) != pid)
	    fprintf(stderr,"Wait returned without pid\n");
    }
    else {		/* Child process. */
	close(1);
	dup(pipefds[1]);
	close(2);
	dup(pipefds[1]);
	execl("/usr/bin/x400_whois", "x400_whois", (char *)NULL);
	execlp("x400_whois", "x400_whois", (char *)NULL);
	fprintf(stderr,"Can't find 'x400_whois'...\n");
	exit(1);
    }

    len = read(pipefds[0], ptr, BUFSIZ-1);
    if (len < 0)
	fprintf(stderr,"Failed to read anything from x400_whois...\n");
    else {
	ptr[len] = '\0';

/* If the output of x400_whois does not begin with a '/' then it is not an
 * ORaddress... Ignore any of the error output.
 */
	if (*ptr != '/')
	    *ptr = '\0';
	else
	    if (ptr[len-1] == '\n')
		ptr[len - 1] = '\0';
    }
    close(pipefds[0]);
    close(pipefds[1]);
    return(ptr);
}
#endif X400
