home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume23 / log_tcp / part01 / refuse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  1.3 KB  |  58 lines

  1. #if defined(PARANOID) || defined(HOSTS_ACCESS)
  2.  
  3.  /*
  4.   * refuse - do the necessary cleanup if we refuse service to some host. This
  5.   * code is never invoked when access control and protection against bad host
  6.   * names are disabled.
  7.   * 
  8.   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  9.   */
  10.  
  11. #ifndef lint
  12. static char sccsid[] = "@(#) refuse.c 1.1 91/10/02 23:01:53";
  13. #endif
  14.  
  15. /* System libraries. */
  16.  
  17. #include <sys/types.h>
  18. #include <sys/param.h>
  19. #include <sys/socket.h>
  20. #include <netinet/in.h>
  21. #include <netdb.h>
  22. #include <stdio.h>
  23. #include <syslog.h>
  24.  
  25. extern void exit();
  26.  
  27. /* Local stuff. */
  28.  
  29. #include "log_tcp.h"
  30.  
  31. /* refuse - refuse request from bad host */
  32.  
  33. void    refuse(f)
  34. struct from_host *f;
  35. {
  36.     char    buf[BUFSIZ];
  37.     struct sockaddr sa;
  38.     int     size = sizeof(sa);
  39.  
  40.     syslog(LOG_WARNING, "refused connect from %s", f->source);
  41.  
  42.     /*
  43.      * In the case of non-connection-oriented services we must discard the
  44.      * packet sent by the client. Otherwise, a fresh daemon will be started
  45.      * each time the present one exits. Some systems insist on a non-zero
  46.      * source address argument in the recvfrom() call below.
  47.      */
  48.  
  49.     if (f->sock_type == FROM_UNCONNECTED)
  50.     (void) recvfrom(0, buf, sizeof(buf), 0, &sa, &size);
  51.  
  52.     /* Terminate with zero exit status to keep the inetd happy. */
  53.  
  54.     exit(0);
  55. }
  56.  
  57. #endif
  58.