Bumped NAMESIZE from 15 to 32; the old value was clearly insufficient.
[unix-history] / usr / src / usr.bin / tip / tip.c
index 898ec23..7cf75a3 100644 (file)
@@ -1,6 +1,18 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)tip.c      4.15 (Berkeley) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1983 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)tip.c      5.2 (Berkeley) %G%";
+#endif not lint
 
 /*
  * tip - UNIX link to other systems
 
 /*
  * tip - UNIX link to other systems
@@ -23,6 +35,7 @@ int   intprompt();
 int    timeout();
 int    cleanup();
 char   *sname();
 int    timeout();
 int    cleanup();
 char   *sname();
+char   PNbuf[256];                     /* This limits the size of a number */
 extern char *sprintf();
 
 main(argc, argv)
 extern char *sprintf();
 
 main(argc, argv)
@@ -73,7 +86,20 @@ main(argc, argv)
        for (p = system; *p; p++)
                if (isalpha(*p))
                        goto notnumber;
        for (p = system; *p; p++)
                if (isalpha(*p))
                        goto notnumber;
-       PN = system;            /* system name is really a phone number */
+       /*
+        * System name is really a phone number...
+        * Copy the number then stomp on the original (in case the number
+        *      is private, we don't want 'ps' or 'w' to find it).
+        */
+       if (strlen(system) > sizeof PNbuf - 1) {
+               fprintf(stderr, "tip: phone number too long (max = %d bytes)\n",
+                       sizeof PNbuf - 1);
+               exit(1);
+       }
+       strncpy( PNbuf, system, sizeof PNbuf - 1 );
+       for (p = system; *p; p++)
+               *p = '\0';
+       PN = PNbuf;
        system = sprintf(sbuf, "tip%d", BR);
 
 notnumber:
        system = sprintf(sbuf, "tip%d", BR);
 
 notnumber:
@@ -110,7 +136,7 @@ notnumber:
        if ((PH = getenv("PHONES")) == NOSTR)
                PH = "/etc/phones";
        vinit();                                /* init variables */
        if ((PH = getenv("PHONES")) == NOSTR)
                PH = "/etc/phones";
        vinit();                                /* init variables */
-       setparity();                            /* set the parity table */
+       setparity("even");                      /* set the parity table */
        if ((i = speed(number(value(BAUDRATE)))) == NULL) {
                printf("tip: bad baud rate %d\n", number(value(BAUDRATE)));
                delock(uucplock);
        if ((i = speed(number(value(BAUDRATE)))) == NULL) {
                printf("tip: bad baud rate %d\n", number(value(BAUDRATE)));
                delock(uucplock);
@@ -154,7 +180,7 @@ cucommon:
 
        /*
         * Everything's set up now:
 
        /*
         * Everything's set up now:
-        *      connection established (hardwired or diaulup)
+        *      connection established (hardwired or dialup)
         *      line conditioned (baud rate, mode, etc.)
         *      internal data structures (variables)
         * so, fork one process for local side and one for remote.
         *      line conditioned (baud rate, mode, etc.)
         *      internal data structures (variables)
         * so, fork one process for local side and one for remote.
@@ -451,26 +477,33 @@ pwrite(fd, buf, n)
 {
        register int i;
        register char *bp;
 {
        register int i;
        register char *bp;
+       extern int errno;
 
        bp = buf;
        for (i = 0; i < n; i++) {
                *bp = partab[(*bp) & 0177];
                bp++;
        }
 
        bp = buf;
        for (i = 0; i < n; i++) {
                *bp = partab[(*bp) & 0177];
                bp++;
        }
-       write(fd, buf, n);
+       if (write(fd, buf, n) < 0) {
+               if (errno == EIO)
+                       abort("Lost carrier.");
+               /* this is questionable */
+               perror("write");
+       }
 }
 
 /*
  * Build a parity table with appropriate high-order bit.
  */
 }
 
 /*
  * Build a parity table with appropriate high-order bit.
  */
-setparity()
+setparity(defparity)
+       char *defparity;
 {
        register int i;
        char *parity;
        extern char evenpartab[];
 
        if (value(PARITY) == NOSTR)
 {
        register int i;
        char *parity;
        extern char evenpartab[];
 
        if (value(PARITY) == NOSTR)
-               value(PARITY) = "even";
+               value(PARITY) = defparity;
        parity = value(PARITY);
        for (i = 0; i < 0200; i++)
                partab[i] = evenpartab[i];
        parity = value(PARITY);
        for (i = 0; i < 0200; i++)
                partab[i] = evenpartab[i];