home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / slip / cslip-2.6 / tip / cu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-30  |  2.8 KB  |  120 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #ifndef lint
  21. static char sccsid[] = "@(#)cu.c    5.7 (Berkeley) 9/2/88";
  22. #endif /* not lint */
  23.  
  24. #include "tip.h"
  25.  
  26. int    cleanup();
  27. int    timeout();
  28.  
  29. /*
  30.  * Botch the interface to look like cu's
  31.  */
  32. cumain(argc, argv)
  33.     char *argv[];
  34. {
  35.     register int i;
  36.     static char sbuf[12];
  37.  
  38.     if (argc < 2) {
  39.         printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
  40.         exit(8);
  41.     }
  42.     CU = DV = NOSTR;
  43.     BR = DEFBR;
  44.     for (; argc > 1; argv++, argc--) {
  45.         if (argv[1][0] != '-')
  46.             PN = argv[1];
  47.         else switch (argv[1][1]) {
  48.  
  49.         case 't':
  50.             HW = 1, DU = -1;
  51.             --argc;
  52.             continue;
  53.  
  54.         case 'a':
  55.             CU = argv[2]; ++argv; --argc;
  56.             break;
  57.  
  58.         case 's':
  59.             if (argc < 3 || speed(atoi(argv[2])) == 0) {
  60.                 fprintf(stderr, "cu: unsupported speed %s\n",
  61.                     argv[2]);
  62.                 exit(3);
  63.             }
  64.             BR = atoi(argv[2]); ++argv; --argc;
  65.             break;
  66.  
  67.         case 'l':
  68.             DV = argv[2]; ++argv; --argc;
  69.             break;
  70.  
  71.         case '0': case '1': case '2': case '3': case '4':
  72.         case '5': case '6': case '7': case '8': case '9':
  73.             if (CU)
  74.                 CU[strlen(CU)-1] = argv[1][1];
  75.             if (DV)
  76.                 DV[strlen(DV)-1] = argv[1][1];
  77.             break;
  78.  
  79.         default:
  80.             printf("Bad flag %s", argv[1]);
  81.             break;
  82.         }
  83.     }
  84.     signal(SIGINT, cleanup);
  85.     signal(SIGQUIT, cleanup);
  86.     signal(SIGHUP, cleanup);
  87.     signal(SIGTERM, cleanup);
  88.  
  89.     /*
  90.      * The "cu" host name is used to define the
  91.      * attributes of the generic dialer.
  92.      */
  93.     (void)sprintf(sbuf, "cu%d", BR);
  94.     if ((i = hunt(sbuf)) == 0) {
  95.         printf("all ports busy\n");
  96.         exit(3);
  97.     }
  98.     if (i == -1) {
  99.         printf("link down\n");
  100.         (void)uu_unlock(uucplock);
  101.         exit(3);
  102.     }
  103.     setbuf(stdout, NULL);
  104.     loginit();
  105.     user_uid();
  106.     vinit();
  107.     setparity("none");
  108.     boolean(value(VERBOSE)) = 0;
  109.     if (HW)
  110.         ttysetup(speed(BR));
  111.     if (lconnect()) {
  112.         printf("Connect failed\n");
  113.         daemon_uid();
  114.         (void)uu_unlock(uucplock);
  115.         exit(1);
  116.     }
  117.     if (!HW)
  118.         ttysetup(speed(BR));
  119. }
  120.