memset((char *)&dv, 0, sizeof(dv));
memset((void *)&dv, 0, sizeof(dv));
main(argc, argv)	char *argv[];{	struct sockaddr_in from;	int on = 1, fromlen;	register int ch;	extern char *optarg;	extern int optind;#if	defined(IPPROTO_IP) && defined(IP_TOS)	int tos = -1;#endif#ifdef ENCRYPTION	extern int des_check_key;	des_check_key = 1; /* Kludge for Mac NCSA telnet 2.6 /bg */#endif	pfrontp = pbackp = ptyobuf;	netip = netibuf;	nfrontp = nbackp = netobuf;	progname = *argv;#ifdef ENCRYPTION	nclearto = 0;#endif#ifdef CRAY	/*	 * Get number of pty's before trying to process options,	 * which may include changing pty range.	 */	highpty = getnpty();#endif /* CRAY */	while ((ch = getopt(argc, argv, valid_opts)) != -1) {		switch(ch) {#ifdef	AUTHENTICATION		case 'a':			/*			 * Check for required authentication level			 */			if (strcmp(optarg, "debug") == 0) {				auth_debug_mode = 1;			} else if (strcasecmp(optarg, "none") == 0) {				auth_level = 0;			} else if (strcasecmp(optarg, "other") == 0) {				auth_level = AUTH_OTHER;			} else if (strcasecmp(optarg, "user") == 0) {				auth_level = AUTH_USER;			} else if (strcasecmp(optarg, "valid") == 0) {				auth_level = AUTH_VALID;			} else if (strcasecmp(optarg, "off") == 0) {				/*				 * This hack turns off authentication				 */				auth_level = -1;			} else {				fprintf(stderr,			    "telnetd: unknown authorization level for -a\n");			}			break;#endif	/* AUTHENTICATION */#ifdef BFTPDAEMON		case 'B':			bftpd++;			break;#endif /* BFTPDAEMON */		case 'd':			if (strcmp(optarg, "ebug") == 0) {				debug++;				break;			}			usage();			/* NOTREACHED */			break;#ifdef DIAGNOSTICS		case 'D':			/*			 * Check for desired diagnostics capabilities.			 */			if (!strcmp(optarg, "report")) {				diagnostic |= TD_REPORT|TD_OPTIONS;			} else if (!strcmp(optarg, "exercise")) {				diagnostic |= TD_EXERCISE;			} else if (!strcmp(optarg, "netdata")) {				diagnostic |= TD_NETDATA;			} else if (!strcmp(optarg, "ptydata")) {				diagnostic |= TD_PTYDATA;			} else if (!strcmp(optarg, "options")) {				diagnostic |= TD_OPTIONS;			} else {				usage();				/* NOT REACHED */			}			break;#endif /* DIAGNOSTICS */		case 'g':			gettyname = optarg;			break;		case 'h':			hostinfo = 0;			break;#if	defined(CRAY) && defined(NEWINIT)		case 'I':		    {			extern char *gen_id;			gen_id = optarg;			break;		    }#endif	/* defined(CRAY) && defined(NEWINIT) */#ifdef	LINEMODE		case 'l':			alwayslinemode = 1;			break;#endif	/* LINEMODE */		case 'k':#if	defined(LINEMODE) && defined(KLUDGELINEMODE)			lmodetype = NO_AUTOKLUDGE;#else			/* ignore -k option if built without kludge linemode */#endif	/* defined(LINEMODE) && defined(KLUDGELINEMODE) */			break;		case 'n':			keepalive = 0;			break;#ifdef CRAY		case 'r':		    {			char *strchr();			char *c;			/*			 * Allow the specification of alterations			 * to the pty search range.  It is legal to			 * specify only one, and not change the			 * other from its default.			 */			c = strchr(optarg, '-');			if (c) {				*c++ = '\0';				highpty = atoi(c);			}			if (*optarg != '\0')				lowpty = atoi(optarg);			if ((lowpty > highpty) || (lowpty < 0) ||							(highpty > 32767)) {				usage();				/* NOT REACHED */			}			break;		    }#endif	/* CRAY */#ifdef	SecurID		case 's':			/* SecurID required */			require_SecurID = 1;			break;#endif	/* SecurID */		case 'S':#ifdef	HAS_GETTOS			if ((tos = parsetos(optarg, "tcp")) < 0)				fprintf(stderr, "%s%s%s\n",					"telnetd: Bad TOS argument '", optarg,					"'; will try to use default TOS");#else			fprintf(stderr, "%s%s\n", "TOS option unavailable; ",						"-S flag not supported\n");#endif			break;		case 'u':			utmp_len = atoi(optarg);			break;		case 'U':			registerd_host_only = 1;			break;#ifdef	AUTHENTICATION		case 'X':			/*			 * Check for invalid authentication types			 */			auth_disable_name(optarg);			break;#endif	/* AUTHENTICATION */		default:			fprintf(stderr, "telnetd: %c: unknown option\n", ch);			/* FALLTHROUGH */		case '?':			usage();			/* NOTREACHED */		}	}	argc -= optind;	argv += optind;	if (debug) {	    int s, ns, foo;	    struct servent *sp;	    static struct sockaddr_in sin = { AF_INET };	    if (argc > 1) {		usage();		/* NOT REACHED */	    } else if (argc == 1) {		    if ((sp = getservbyname(*argv, "tcp"))) {			sin.sin_port = sp->s_port;		    } else {			sin.sin_port = atoi(*argv);			if ((int)sin.sin_port <= 0) {			    fprintf(stderr, "telnetd: %s: bad port #\n", *argv);			    usage();			    /* NOT REACHED */			}			sin.sin_port = htons((u_short)sin.sin_port);		   }	    } else {		sp = getservbyname("telnet", "tcp");		if (sp == 0) {		    fprintf(stderr, "telnetd: tcp/telnet: unknown service\n");		    exit(1);		}		sin.sin_port = sp->s_port;	    }	    s = socket(AF_INET, SOCK_STREAM, 0);	    if (s < 0) {		    perror("telnetd: socket");;		    exit(1);	    }	    (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR,				(char *)&on, sizeof(on));	    if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0) {		perror("bind");		exit(1);	    }	    if (listen(s, 1) < 0) {		perror("listen");		exit(1);	    }	    foo = sizeof sin;	    ns = accept(s, (struct sockaddr *)&sin, &foo);	    if (ns < 0) {		perror("accept");		exit(1);	    }	    (void) dup2(ns, 0);	    (void) close(ns);	    (void) close(s);#ifdef convex	} else if (argc == 1) {		; /* VOID*/		/* Just ignore the host/port name */#endif	} else if (argc > 0) {		usage();		/* NOT REACHED */	}#if	defined(_SC_CRAY_SECURE_SYS)	secflag = sysconf(_SC_CRAY_SECURE_SYS);	/*	 *	Get socket's security label	 */	if (secflag)  {		int szss = sizeof(ss);#ifdef SO_SEC_MULTI			/* 8.0 code */		int sock_multi;		int szi = sizeof(int);#endif /* SO_SEC_MULTI */		memset((char *)&dv, 0, sizeof(dv));		if (getsysv(&sysv, sizeof(struct sysv)) != 0) {			perror("getsysv");			exit(1);		}		/*		 *	Get socket security label and set device values		 *	   {security label to be set on ttyp device}		 */#ifdef SO_SEC_MULTI			/* 8.0 code */		if ((getsockopt(0, SOL_SOCKET, SO_SECURITY,			       (char *)&ss, &szss) < 0) ||		    (getsockopt(0, SOL_SOCKET, SO_SEC_MULTI,				(char *)&sock_multi, &szi) < 0)) {			perror("getsockopt");			exit(1);		} else {			dv.dv_actlvl = ss.ss_actlabel.lt_level;			dv.dv_actcmp = ss.ss_actlabel.lt_compart;			if (!sock_multi) {				dv.dv_minlvl = dv.dv_maxlvl = dv.dv_actlvl;				dv.dv_valcmp = dv.dv_actcmp;			} else {				dv.dv_minlvl = ss.ss_minlabel.lt_level;				dv.dv_maxlvl = ss.ss_maxlabel.lt_level;				dv.dv_valcmp = ss.ss_maxlabel.lt_compart;			}			dv.dv_devflg = 0;		}#else /* SO_SEC_MULTI */		/* 7.0 code */		if (getsockopt(0, SOL_SOCKET, SO_SECURITY,				(char *)&ss, &szss) >= 0) {			dv.dv_actlvl = ss.ss_slevel;			dv.dv_actcmp = ss.ss_compart;			dv.dv_minlvl = ss.ss_minlvl;			dv.dv_maxlvl = ss.ss_maxlvl;			dv.dv_valcmp = ss.ss_maxcmp;		}#endif /* SO_SEC_MULTI */	}#endif	/* _SC_CRAY_SECURE_SYS */	openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);	fromlen = sizeof (from);	if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {		fprintf(stderr, "%s: ", progname);		perror("getpeername");		_exit(1);	}	if (keepalive &&	    setsockopt(0, SOL_SOCKET, SO_KEEPALIVE,			(char *)&on, sizeof (on)) < 0) {		syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");	}#if	defined(IPPROTO_IP) && defined(IP_TOS)	{# if	defined(HAS_GETTOS)		struct tosent *tp;		if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))			tos = tp->t_tos;# endif		if (tos < 0)			tos = 020;	/* Low Delay bit */		if (tos		   && (setsockopt(0, IPPROTO_IP, IP_TOS,				  (char *)&tos, sizeof(tos)) < 0)		   && (errno != ENOPROTOOPT) )			syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");	}#endif	/* defined(IPPROTO_IP) && defined(IP_TOS) */	net = 0;	doit(&from);	/* NOTREACHED */	return (0);}  /* end of main */