📄 conn.c
字号:
#ifndef lintstatic char *sccsid = "@(#)conn.c 4.1 ULTRIX 7/2/90";#endif/******* * conn(system) * char *system; * * conn - place a telephone call to system and * login, etc. * * return codes: * CF_SYSTEM: don't know system * CF_TIME: wrong time to call * CF_DIAL: call failed * CF_NODEV: no devices available to place call * CF_LOGIN: login/password dialog failed * * >0 - file no. - connect ok * * decvax!larry - modifications to BSD4.2: * - only ASSERT when adimistrative problem, e.g * L-devices set up wrong. Otherwise * return(FAIL). * - fixline - changes for ULTRIX/11 * decvax!marc - add linebaudrate so packet driver can be smart * about how long to pause between reads. *//************************************************************************ * * * Copyright (c) 1984 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************/#include "uucp.h"#include <signal.h>#include <setjmp.h>#include <ctype.h>#include <sys/types.h>#include <sys/time.h>#include <errno.h>#ifdef SYSIII#include <termio.h>#include <fcntl.h>#endif#ifndef SYSIII#include <sgtty.h>#endif#define MAXC 1000extern jmp_buf Sjbuf;extern int errno;/* Parity control during login procedure */#define P_ZERO 0#define P_ONE 1#define P_EVEN 2#define P_ODD 3char par_tab[128]; /* must be power of two */int next_fd = -1; /* predicted fd to close interrupted opens */int linebaudrate; /* set here - used in pk driver (and fio.c) */ /* rti!trt, courtesy unc!smb *//*** * alarmtr() - catch alarm routine for "expect". */alarmtr(){ signal(SIGALRM, alarmtr); if (next_fd >= 0) { if (close(next_fd)) logent("FAIL", "ACU LINE CLOSE"); next_fd = -1; } longjmp(Sjbuf, 1);}int Dcf = -1;conn(system)char *system;{ int ret, nf; register int fn, fnd; char info[MAXC], *flds[MAXC/10]; register FILE *fsys; int fcode = 0; nf = 0; fnd = 0; fsys = fopen(SYSFILE, "r"); ASSERT(fsys != NULL, "CAN'T OPEN", SYSFILE, 0); DEBUG(4, "finds %s\n", "called"); while((nf = finds(fsys, system, info, flds)) > 0) { DEBUG(4, "getto %s\n", "called"); if ((fn = getto(flds)) > 0) { fnd = 1; Dcf = fn; break; } fcode = (fn == FAIL ? CF_DIAL : fn); } fclose(fsys); if (nf <= 0) return(fcode ? fcode : nf); DEBUG(4, "login %s\n", "called"); ret = login(nf, flds, fn); if (ret < 0) { clsacu(); return(CF_LOGIN); } /* rti!trt: avoid passing file to children */ fioclex(fn); return(fn);}/*** * getto(flds) connect to remote machine * char *flds[]; * * return codes: * >0 - file number - ok * FAIL - failed */#ifdef GENERICint gendialer = 0;#endifgetto(flds)register char *flds[];{ register struct condev *cd, *tcd; int nulldev(), diropn(); DEBUG(4, "call: no. %s ", flds[F_PHONE]); DEBUG(4, "for sys %s\n", flds[F_NAME]); DEBUG(4, "Looking for %s\n", flds[F_LINE]); CU_end = nulldev; for (cd = condevs; cd->CU_meth != NULL; cd++) { if (prefix(cd->CU_meth, flds[F_LINE])) {#ifdef GENERIC gendialer++; /* Try to use a generic dialer */#endif DEBUG(4, "Using %s to call\n", cd->CU_meth); return((*(cd->CU_gen))(flds)); } } /* try using a direct connect */ return(diropn(flds)); }/*** * clsacu() close call unit * * return codes: none */int (*CU_end)() = nulldev;clsacu(){ if (Dcf > 0) ioctl(Dcf, TIOCNCAR); /* insure writes dont hang */ (*(CU_end))(Dcf); DEBUG(5,"clsacu entered\n", ""); Dcf = -1; CU_end = nulldev;}/*** * exphone - expand phone number for given prefix and number * * return code - none */exphone(in, out)register char *in, *out;{ FILE *fn; char pre[MAXPH], npart[MAXPH], tpre[MAXPH], p[MAXPH]; char buf[BUFSIZ]; register char *s1; if (!isalpha(*in)) { strcpy(out, in); return; } s1=pre; while (isalpha(*in)) *s1++ = *in++; *s1 = '\0'; s1 = npart; while (*in != '\0') *s1++ = *in++; *s1 = '\0'; tpre[0] = '\0'; if ((fn = fopen(DIALFILE, "r")) == NULL) DEBUG(2, "CAN'T OPEN %s\n", DIALFILE); else { while (cfgets(buf, BUFSIZ, fn)) { sscanf(buf, "%s%s", p, tpre); if (strcmp(p, pre) == SAME) goto found; tpre[0] = '\0'; } DEBUG(2, "CAN'T FIND dialcodes prefix '%s'\n", pre); found:; fclose(fn); } strcpy(out, tpre); strcat(out, npart); return;}/*** * rddev - read and decode a line from device file * * return code - FAIL at end-of file; 0 otherwise * * EDIT HISTORY: * * Jul 10 1986 - marc * * Lines beginning with '#' are comments. */rddev(fp, dev)register struct Devices *dev;FILE *fp;{ char *fdig(); char buf[BUFSIZ]; int na;again: if (!cfgets(buf, BUFSIZ, fp)) return(FAIL); if (buf[0] == '#') goto again; na = sscanf(buf, "%s%s%s%s%s%s", dev->D_type, dev->D_line, dev->D_calldev, dev->D_class, dev->D_brand, dev->D_proto); ASSERT(na >= 4, "BAD DEVICE ENTRY", buf, 0); if (na < 6) dev->D_proto[0] = '\0'; if (na < 5) dev->D_brand[0] = '\0'; dev->D_speed = atoi(fdig(dev->D_class)); return(0);}/*** * finds(fsys, sysnam, info, flds) set system attribute vector * * return codes: * >0 - number of arguments in vector - succeeded * CF_SYSTEM - system name not found * CF_TIME - wrong time to call */finds(fsys, sysnam, info, flds)char *sysnam, info[], *flds[];FILE *fsys;{ char sysn[8]; int na; int fcode = 0; /* format of fields * 0 name; * 1 time * 2 acu/hardwired * 3 speed * etc */ while (cfgets(info, MAXC, fsys) != NULL) { na = getargs(info, flds); sprintf(sysn, "%.7s", flds[F_NAME]); if (strcmp(sysnam, sysn) != SAME) continue; if (ifdate(flds[F_TIME])) /* found a good entry */ return(na); DEBUG(2, "Wrong time ('%s') to call\n", flds[F_TIME]); fcode = CF_TIME; } return(fcode ? fcode : CF_SYSTEM);}/*** * login(nf, flds, dcr) do login conversation * char *flds[]; * int nf; * * return codes: 0 | FAIL */login(nf, flds, fn)register char *flds[];int nf, fn;{ register char *want, *altern; extern char *index(); int k, ok; ASSERT(nf > 4, "TOO FEW LOG FIELDS", "", nf); for (k = F_LOGIN; k < nf; k += 2) { want = flds[k]; ok = FAIL; while (ok != 0) { altern = index(want, '-'); if (altern != NULL) *altern++ = '\0'; DEBUG(4, "wanted %s ", want); ok = expect(want, fn); DEBUG(4, "got %s\n", ok ? "?" : "that"); if (ok == 0) break; if (altern == NULL) { logent("LOGIN", "FAILED"); /* close *not* needed here. rti!trt */ return(FAIL); } want = index(altern, '-'); if (want != NULL) *want++ = '\0'; sendthem(altern, fn); } sleep(2); if (k+1 < nf) sendthem(flds[k+1], fn); } return(0);}/* rti!trt: conditional table generation to support odd speeds *//* Suggested in n44a.139 by n44!dan (Dan Ts'o) */struct sg_spds {int sp_val, sp_name;} spds[] = {#ifdef B50 { 50, B50},#endif#ifdef B75 { 75, B75},#endif#ifdef B110 { 110, B110},#endif#ifdef B150 { 150, B150},#endif#ifdef B200 { 200, B200},#endif#ifdef B300 { 300, B300},#endif#ifdef B600 {600, B600},#endif#ifdef B1200 {1200, B1200},#endif#ifdef B1800 {1800, B1800},#endif#ifdef B2000 {2000, B2000},#endif#ifdef B2400 {2400, B2400},#endif#ifdef B3600 {3600, B3600},#endif#ifdef B4800 {4800, B4800},#endif#ifdef B7200 {7200, B7200},#endif#ifdef B9600 {9600, B9600},#endif#ifdef B19200 {19200, B19200},#endif#ifdef B38400 {38400, B38400},#endif#ifdef EXTA {19200, EXTA},#endif#ifdef EXTB {38400, EXTB},#endif {0, 0}};/*** * fixline(tty, spwant) set speed/echo/mode... * int tty, spwant; * * return codes: none */fixline(tty, spwant)int tty, spwant;{#ifdef SYSIII struct termio ttbuf;#endif#ifndef SYSIII struct sgttyb ttbuf;#endif register struct sg_spds *ps; int speed = -1; int ret; for (ps = spds; ps->sp_val; ps++) if (ps->sp_val == spwant) speed = ps->sp_name; ASSERT(speed >= 0, "BAD SPEED", "", speed);#ifdef SYSIII ioctl(tty, TCGETA, &ttbuf); /* ttbuf.sg_flags = (ANYP|RAW); ttbuf.sg_ispeed = ttbuf.sg_ospeed = speed; */ ttbuf.c_iflag = (ushort)0; ttbuf.c_oflag = (ushort)0; ttbuf.c_cflag = (speed|CS8|HUPCL|CREAD); ttbuf.c_lflag = (ushort)0; ttbuf.c_cc[VMIN] = 6; ttbuf.c_cc[VTIME] = 1; ret = ioctl(tty, TCSETA, &ttbuf);#endif#ifndef SYSIII ioctl(tty, TIOCGETP, &ttbuf); ttbuf.sg_flags = (ANYP|RAW); ttbuf.sg_ispeed = ttbuf.sg_ospeed = speed; ret = ioctl(tty, TIOCSETP, &ttbuf);#endif ASSERT(ret >= 0, "RETURN FROM STTY", "", ret);#ifdef V7M11 ioctl(tty, TIOCSDTR, (struct sgttyb *)NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -