home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / telecom / dtr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-21  |  1.8 KB  |  59 lines

  1. 21-May-86 11:40:33-MDT,1821;000000000001
  2. Return-Path: <unix-sources-request@BRL.ARPA>
  3. Received: from BRL-SMOKE.ARPA by SIMTEL20.ARPA with TCP; Wed 21 May 86 11:40:23-MDT
  4. Received: from USENET by SMOKE.BRL.ARPA id a015715; 20 May 86 19:45 EDT
  5. From: "Brandon S. Allbery" <allbery@ncoast.uucp>
  6. Newsgroups: net.sources
  7. Subject: dtr - DTR on/off for sys3/sys5
  8. Message-ID: <1183@ncoast.UUCP>
  9. Date: 15 May 86 22:22:17 GMT
  10. To:       unix-sources@brl-smoke.arpa
  11.  
  12. The following program (NOT shar'ed!) is a utility to set/reset DTR on a serial
  13. port.  Usage is ``dtr [+-]ttyxx''.  + turns it on, - turns it off.
  14.  
  15. It's useful for telling a modem not to answer the phone after disabling a
  16. dialin line (I have a shell script which does this automatically).
  17.  
  18. Cut and enjoy.
  19.  
  20. --Brandon
  21.  
  22. ------------------------------- cut here ------------------------------------
  23. #include <sys/ioctl.h>
  24. #include <fcntl.h>
  25. #include <termio.h>
  26.  
  27. main(argc, argv)
  28. char **argv; {
  29.     struct termio tbuf;
  30.     int fd;
  31.     char ttypath[80];
  32.     
  33.     if (argc != 2 || (argv[1][0] != '-' && argv[1][0] != '+')) {
  34.         write(2, "usage: dtr [+-]tty\n", 19);
  35.         exit(1);
  36.     }
  37.     strcpy(ttypath, "/dev/");
  38.     strcat(ttypath, &argv[1][1]);
  39.     if ((fd = open(ttypath, O_RDONLY|O_NDELAY)) < 0) {
  40.         write(2, "can't open ", 11);
  41.         write(2, &argv[1][1], strlen(&argv[1][1]));
  42.         write(2, "\n", 1);
  43.         exit(2);
  44.     }
  45.     ioctl(fd, TCGETA, &tbuf);
  46.     tbuf.c_cflag &= ~CBAUD;
  47.     tbuf.c_cflag |= (argv[1][0] == '-'? B0: B300);
  48.     ioctl(fd, TCSETA, &tbuf);
  49.     close(fd);
  50.     exit(0);
  51. }
  52.  
  53.  
  54. -- 
  55. decvax!cwruecmp!ncoast!allbery  ncoast!allbery@Case.CSNET  ncoast!tdi2!brandon
  56. (ncoast!tdi2!root for business) 6615 Center St. #A1-105, Mentor, OH 44060-4101
  57. Phone: +01 216 974 9210      CIS 74106,1032      MCI MAIL BALLBERY (part-time)
  58. PC UNIX/UNIX PC - which do you like best?  See <1129@ncoast.UUCP> in net.unix.
  59.