/*
 * An example of how you can implement
 * TCP wrappers in your own code.
 *
 * See the TCP wrapper library and tcpd.c file for
 * more examples.
 *
 * Copyright 2001, James Lee
 * Released under the GPL.
 *
 */

/*
 * Include the following in an included .h file,
 * or at the top of the .c file that uses
 * TCP wrappers
 */

#ifdef USE_LIBWRAP
#include <tcpd.h>

/* These default severities are probably acceptable. */
int allow_severity=LOG_NOTICE;
int deny_severity=LOG_WARNING;

#endif





/* The following goes in your actual .c file */

/* 
* Insert code like the following after a connection
* is established, before the connection is used.
*/

#ifdef USE_LIBWRAP
      struct request_info request;

      request_init(&request, RQ_DAEMON, options.servname, RQ_FILE, local, 0);
      fromhost(&request);

      if (!hosts_access(&request)) {
          log(LOG_WARNING, "Connection from %s:%d REFUSED by libwrap",
              inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
          log(LOG_DEBUG, "See hosts_access(5) for details");
          goto cleanup_local;
      }
#endif

