1: #ifdef EXCELAN
   2: struct sockaddr_in current_peer = { AF_INET, IPPORT_NNTP };
   3: #endif
   4: #ifndef lint
   5: static char *sccsid = "@(#)main.c	1.10	(Berkeley) 2/6/88";
   6: #endif
   7: 
   8: /*
   9:  *	Network News Transfer Protocol server
  10:  *
  11:  *	Phil Lapsley
  12:  *	University of California, Berkeley
  13:  *	(Internet: phil@berkeley.edu; UUCP: ...!ucbvax!phil)
  14:  */
  15: 
  16: #include "common.h"
  17: #include <sys/socket.h>
  18: #include <netinet/in.h>
  19: #ifndef EXCELAN
  20: #include <netdb.h>
  21: #endif
  22: #include <signal.h>
  23: 
  24: main()
  25: {
  26: 
  27: #ifdef ALONE    /* If no inetd */
  28: 
  29:     int         sockt, client, length;
  30:     struct sockaddr_in  from;
  31:     extern int      reaper();
  32: 
  33:     disassoc();
  34: 
  35:     /* fd 0-2 should be open and point to / now. */
  36: 
  37: #ifdef SYSLOG
  38: #ifdef BSD_42
  39:     openlog("nntpd", LOG_PID);          /* fd 3 */
  40: #else
  41:     openlog("nntpd", LOG_PID, SYSLOG);      /* fd 3 */
  42: #endif
  43: #endif
  44: 
  45: #ifdef FASTFORK
  46:     num_groups = read_groups(); /* Read active file now (fd 4) */
  47:                     /* and then do it every */
  48:     set_timer();            /* so often later */
  49: #endif
  50: 
  51: #ifndef EXCELAN
  52:     sockt = get_socket();       /* should be fd 4 or 5 */
  53: #endif
  54: 
  55: #ifndef USG
  56:     (void) signal(SIGCHLD, reaper);
  57: #endif
  58: 
  59: #ifndef EXCELAN
  60:     if (listen(sockt, SOMAXCONN) < 0) {
  61: #ifdef SYSLOG
  62:         syslog(LOG_ERR, "main: listen: %m");
  63: #endif
  64:         exit(1);
  65:     }
  66: #endif
  67: 
  68:     for (;;) {
  69: #ifdef EXCELAN
  70:         int status;
  71:         sockt = get_socket();
  72:         if (sockt < 0)
  73:             continue;
  74:         client = accept(sockt, &from);
  75: #else
  76:         length = sizeof (from);
  77:         client = accept(sockt, &from, &length);
  78: #endif EXCELAN
  79:         if (client < 0) {
  80: #ifdef SYSLOG
  81:             if (errno != EINTR)
  82:                 syslog(LOG_ERR, "accept: %m\n");
  83: #endif
  84: #ifdef EXCELAN
  85:             close(sockt);
  86:             sleep(1);
  87: #endif
  88:             continue;
  89:         }
  90: 
  91:         switch (fork()) {
  92:         case    -1:
  93: #ifdef SYSLOG
  94:                 syslog(LOG_ERR, "fork: %m\n");
  95: #endif
  96: #ifdef EXCELAN
  97:                 (void) close(sockt);
  98: #endif
  99:                 (void) close(client);
 100:                 break;
 101: 
 102:         case    0:
 103: #ifdef EXCELAN
 104:                 if (fork())
 105:                     exit(0);
 106:                 bcopy(&from,&current_peer,sizeof(from));
 107:                 make_stdio(sockt);
 108: #else
 109:                 (void) close(sockt);
 110:                 make_stdio(client);
 111: #endif
 112:                 serve();
 113:                 break;
 114: 
 115:         default:
 116: #ifdef EXCELAN
 117:                 (void) close(sockt);
 118:                 (void) wait(&status);
 119: #else
 120:                 (void) close(client);
 121: #endif
 122:                 break;
 123:         }
 124:     }
 125: 
 126: #else       /* We have inetd */
 127: 
 128:     serve();
 129: 
 130: #endif
 131: }

Defined functions

main defined in line 24; never used

Defined variables

current_peer defined in line 2; used 3 times
sccsid defined in line 5; never used
Last modified: 1988-02-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 715
Valid CSS Valid XHTML 1.0 Strict