 /*
  * On socket-only systems, fromhost() is nothing but an alias for the
  * socket-specific sock_host() function.
  * 
  * On systems with sockets and TLI, fromhost() determines the type of API
  * (sockets, TLI), then invokes the appropriate API-specific routines.
  * 
  * The API-specific routines determine the nature of the service (datagram,
  * stream), and the name and address of the host at the other end. In case
  * of an IP service, these routines also determine the local address and
  * port, and the remote username if username lookups are done irrespective
  * of client. All results are in static memory.
  * 
  * The return value is (-1) if the remote host pretends to have someone elses
  * name, or if the remote host name is available but could not be verified;
  * in either case the hostname will be ignored. The return status is zero in
  * all other cases (the hostname is unavailable, or the host name double
  * check succeeds).
  * 
  * Diagnostics are reported through syslog(3).
  * 
  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  */

#ifndef lint
static char sccsid[] = "@(#) fromhost.c 1.13 93/09/24 19:16:08";
#endif

/* System libraries. */

#include <sys/types.h>
#include <stdio.h>
#include <syslog.h>

#ifdef TLI
#include <sys/tiuser.h>
#include <stropts.h>
#endif

/* Local stuff. */

#include "log_tcp.h"

#ifdef TLI

/* fromhost - find out what network API we should use */

int     fromhost(client)
struct client_info *client;
{

    /*
     * On systems with streams support the IP network protocol family may
     * have more than one programming interface (sockets and TLI).
     * 
     * Thus, we must first find out what programming interface to use: sockets
     * or TLI. On some systems, sockets are not part of the streams system,
     * so if stdin is not a stream we assume sockets.
     */

    if (!isastream(client->fd))
	return (sock_host(client));
    if (ioctl(0, I_FIND, "timod") > 0)
	return (tli_host(client));
    if (ioctl(0, I_FIND, "sockmod") > 0)
	return (sock_host(client));
    syslog(LOG_ERR, "wrapper: cannot establish type of transport interface");
    return (0);
}

#endif /* TLI */
