home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume30 / log_tcp / part02 / clean_exit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-20  |  1.2 KB  |  47 lines

  1.  /*
  2.   * clean_exit() cleans up and terminates the program. It should be called
  3.   * instead of exit when for some reason the real network daemon will not or
  4.   * cannot be run. Reason: in the case of a datagram-oriented service we must
  5.   * discard the not-yet received data from the client. Otherwise, inetd will
  6.   * see the same datagram again and again, and go into a loop.
  7.   * 
  8.   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  9.   */
  10.  
  11. #ifndef lint
  12. static char sccsid[] = "@(#) clean_exit.c 1.1 92/06/11 22:21:52";
  13. #endif
  14.  
  15. #include <sys/types.h>
  16. #include <sys/socket.h>
  17. #include <stdio.h>
  18.  
  19. extern void exit();
  20.  
  21. #include "log_tcp.h"
  22.  
  23. /* clean_exit - clean up and exit */
  24.  
  25. void    clean_exit(client)
  26. struct from_host *client;
  27. {
  28.     char    buf[BUFSIZ];
  29.     struct sockaddr sa;
  30.     int     size = sizeof(sa);
  31.  
  32.     /*
  33.      * Eat up the not-yet received packet. Some systems insist on a non-zero
  34.      * source address argument in the recvfrom() call below.
  35.      */
  36.  
  37.     if (client->sock_type == FROM_UNCONNECTED)
  38.     (void) recvfrom(0, buf, sizeof(buf), 0, &sa, &size);
  39.  
  40.     /*
  41.      * Be kind to the inetd. We already reported the problem via the syslogd,
  42.      * and there is no need for additional garbage in the logfile.
  43.      */
  44.  
  45.     exit(0);
  46. }
  47.