Bumped NAMESIZE from 15 to 32; the old value was clearly insufficient.
[unix-history] / usr / src / usr.bin / tip / tip.c
index f328b80..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.16 (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:
@@ -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,13 +477,19 @@ 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");
+       }
 }
 
 /*
 }
 
 /*