Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Feb 1995 21:03:39 -0500
From:      Thomas David Rivers <ponds!rivers@dg-rtp.dg.com>
To:        freebsd-hackers@wcarchive.cdrom.com, longyear@netcom.com, rivers@dg-rtp.dg.com
Subject:   chat(8) improvements for SL/IP dialout.
Message-ID:  <199502020203.VAA01811@ponds.UUCP>

next in thread | raw e-mail | index | archive | help

Well, having wrestled with kermit, etc... to automate my SL/IP connections,
I decided to modify the chat(8) program for my purposes.  (Kermit, and
several other alternatives were not adequate because I don't want to
reset the modem with AT&D0, for SL/IP dial-out because I also have a 
getty on the dial-in side.)

The following changes to chat.c (and the chat.8 man page) add two
options:  
	-c <command>
	-s <speed>

which cause chat to set the baud rate of the terminal before "chatting" and,
if it is successful at the chat script, executing the command.

Thus, for starting up my SL/IP connection, I issue commands like:

   chat -s 19200 -c "my_slattach_script"  
              "" ATDT... OK ogin: .... < /dev/cua01 > /dev/cua01

where "my_slattach_script" sets up the default routes, /etc/resolv.conf,
and the appropriate ifconfig, and then executes an slattach command.

I have found this *extremely* helpful, and it could ease the problems
other people have encountered.  If we could, I'd like to have these
improvements in FreeBSD 2.1.  If someone commits this to the CVS tree,
please let me know (and if there are objections, please let me know,
and I'll try and change minds :-) )

	 - Thanks -
	- Dave Rivers -

---------------------- cut here (diffs to chat version 1.8) -----------
*** chat.c.ori	Wed Feb  1 20:08:48 1995
--- chat.c	Wed Feb  1 21:02:17 1995
***************
*** 4,9 ****
--- 4,11 ----
   *
   *	This software is in the public domain.
   *
+  *      Thomas David Rivers (ponds!rivers): Added -c and -s support.
+  *
   *	Please send all bug reports, requests for information, etc. to:
   *
   *		Al Longyear (longyear@netcom.com)
***************
*** 101,106 ****
--- 103,111 ----
  char *chat_file = (char *)0;
  int timeout = DEFAULT_CHAT_TIMEOUT;
  
+ char *command = NULL;
+ long speed = 0;
+ 
  int have_tty_parameters = 0;
  #ifdef TERMIO
  struct termio saved_tty_parameters;
***************
*** 166,171 ****
--- 171,177 ----
  
  /*
   *	chat [ -v ] [ -t timeout ] [ -l lock-file ] [ -f chat-file ] \
+ 		[ -c command ] [-s speed] \
   *		[...[[expect[-say[-expect...]] say expect[-say[-expect]] ...]]]
   *
   *	Perform a UUCP-dialer-like chat script on stdin and stdout.
***************
*** 196,202 ****
  		break;
  
  	    case 'l':
! 		if (arg = OPTARG(argc, argv))
  		    lock_file = copy_of(arg);
  		else
  		    usage();
--- 202,208 ----
  		break;
  
  	    case 'l':
! 		if (arg = OPTARG(argc, argv)) 
  		    lock_file = copy_of(arg);
  		else
  		    usage();
***************
*** 211,216 ****
--- 217,238 ----
  
  		break;
  
+ 	    case 's':
+ 		if (arg = OPTARG(argc, argv))  
+ 		    speed = atoi(arg);
+ 		else
+ 		    usage();
+ 		break;
+ 
+ 	    case 'c':
+ 		if (arg = OPTARG(argc,argv)) 
+ 		    command = (char *)copy_of(arg);
+ 		else 
+ 		    usage();
+ 		break;
+ 		
+ 
+ 
  	    default:
  		usage();
  	    }
***************
*** 248,253 ****
--- 270,279 ----
  	    }
  	}
  
+     if(command != NULL) {
+ 	/* Execute the given command */
+ 	system(command);
+     }
      terminate(0);
      }
  
***************
*** 336,342 ****
  void usage()
      {
      fprintf(stderr, "\
! Usage: %s [-v] [-l lock-file] [-t timeout] {-f chat-file || chat-script}\n",
  	    program_name);
      exit(1);
      }
--- 362,369 ----
  void usage()
      {
      fprintf(stderr, "\
! Usage: %s [-v] [-l lock-file] [-t timeout] \
! {-f chat-file || chat-script} [-c command] [-s speed]\n",
  	    program_name);
      exit(1);
      }
***************
*** 489,497 ****
--- 516,533 ----
      t.c_iflag |= IGNBRK | ISTRIP | IGNPAR;
      t.c_oflag  = 0;
      t.c_lflag  = 0;
+     if(command) {
+ 	  /* If we're going to execute a command, don't hang-up */
+ 	  /* the device when we're done. */
+ 	t.c_cflag &= ~HUPCL;
+     }
      t.c_cc[VERASE] = t.c_cc[VKILL] = 0;
      t.c_cc[VMIN] = 1;
      t.c_cc[VTIME] = 0;
+     if(speed != 0) {
+ 	t.c_ispeed = speed;
+ 	t.c_ospeed = speed;
+     }
  
  #ifdef TERMIO
      if (ioctl(0, TCSETA, &t) < 0)
***************
*** 513,518 ****
--- 549,559 ----
  void terminate(status)
  int status;
      {
+     if(command != (char *)0) {
+ 	/* NB: don't unlock when there is a command to execute. */
+ 	/*     and don't reset the tty. */
+ 	exit(status);
+     }
      if (have_tty_parameters &&
  #ifdef TERMIO
          ioctl(0, TCSETA, &saved_tty_parameters) < 0
*** chat.8.ori	Wed Feb  1 20:46:51 1995
--- chat.8	Wed Feb  1 21:03:44 1995
***************
*** 1,12 ****
  .\" -*- nroff -*-
! .\" manual page [] for chat 1.8
  .\" chat.8,v 1.1.1.1 1994/11/12 05:25:32 lars Exp
  .\" SH section heading
  .\" SS subsection heading
  .\" LP paragraph
  .\" IP indented paragraph
  .\" TP hanging label
! .TH CHAT 8 "17 April 1994" "Chat Version 1.8"
  .SH NAME
  chat \- Automated conversational script with a modem
  .SH SYNOPSIS
--- 1,12 ----
  .\" -*- nroff -*-
! .\" manual page [] for chat 1.9
  .\" chat.8,v 1.1.1.1 1994/11/12 05:25:32 lars Exp
  .\" SH section heading
  .\" SS subsection heading
  .\" LP paragraph
  .\" IP indented paragraph
  .\" TP hanging label
! .TH CHAT 8 "17 April 1994" "Chat Version 1.9"
  .SH NAME
  chat \- Automated conversational script with a modem
  .SH SYNOPSIS
***************
*** 20,28 ****
  The \fIchat\fR program defines a conversational exchange between the
  computer and the modem. Its primary purpose is to establish the
  connection between the Point-to-Point Protocol Daemon (\fIpppd\fR) and
! the remote's \fIpppd\fR process.
  .SH OPTIONS
  .TP
  .B -f \fI<chat file>
  Read the chat script from the chat \fIfile\fR. The use of this option
  is mutually exclusive with the chat script parameters. The user must
--- 20,41 ----
  The \fIchat\fR program defines a conversational exchange between the
  computer and the modem. Its primary purpose is to establish the
  connection between the Point-to-Point Protocol Daemon (\fIpppd\fR) and
! the remote's \fIpppd\fR process.  Or, chat can be used to negotiate
! any connect and then execute a command.
  .SH OPTIONS
  .TP
+ .B -c \fI<command>
+ .IP
+ Upon successful completion of the chat script;  the named \fIcommand\fR
+ will be executed.  This is helpful when using chat to negotiate a SL/IP
+ connection.  Chat can be used to dial the modem and connect to the
+ remote site, then, issue the appropriate \fPslattach()\fR command.
+ If the \fB-c\fR option is used, chat will set the line to no HUPCL, so
+ the subsequent termination of chat will not reset the modem.  Also, 
+ if \fB-c\fR is used, chat will not unlink any lock file specified with
+ the \fB-l\fR option, and will not reset the tty to it's previous state
+ when exiting.  The executed command is responsible for these items.
+ .TP
  .B -f \fI<chat file>
  Read the chat script from the chat \fIfile\fR. The use of this option
  is mutually exclusive with the chat script parameters. The user must
***************
*** 49,54 ****
--- 62,74 ----
  exclusive options and will cause one or the other program to fail to
  achieve the required lock if you use both.
  .TP
+ .B -s \fI<speed>
+ .IP
+ Set the baud rate.  This is useful when using chat directly in
+ combination with the
+ .B -c
+ option.
+ .TP
  .B -t \fI<timeout>
  Set the timeout for the expected string to be received. If the string
  is not received within the time limit then the reply string is not
***************
*** 240,251 ****
  Substitute the sequence with the control character represented by C.
  For example, the character DC1 (17) is shown as \^^Q.
  .I (some characters are not valid in expect.)
  .SH SEE ALSO
  Additional information about \fIchat\fR scripts may be found with UUCP
  documentation. The \fIchat\fR script was taken from the ideas proposed by the
! scripts used by the \fIuucico\fR program.
  .LP
! uucico(1), uucp(1)
  .SH COPYRIGHT
  The \fIchat\fR program is in public domain. This is not the GNU public
  license. If it breaks then you get to keep both pieces.
--- 260,282 ----
  Substitute the sequence with the control character represented by C.
  For example, the character DC1 (17) is shown as \^^Q.
  .I (some characters are not valid in expect.)
+ .SH USE WITH SL/IP
+ By taking advantage of the \fB-c\fR and the \fB-s\fR options, chat can
+ also be used to establish a SL/IP connection.  For example:
+ .IP
+ DEV=cua01
+ chat -s 19200 -c "slattach -s 19200 /dev/$DEV" ogin: ppp ssword: hello2u2 </dev/$DEV > /dev/$DEV
+ .LP
+ will cause the script to be executed on the /dev/cua01 device, at 19200 baud.
+ If that negotiation is successful, the \fBslattach\fR command will be
+ executed to establish the SL/IP connection.
  .SH SEE ALSO
  Additional information about \fIchat\fR scripts may be found with UUCP
  documentation. The \fIchat\fR script was taken from the ideas proposed by the
! scripts used by the \fIuucico\fR program.  For information on SL/IP, see
! the \fIslattach\fR man page.
  .LP
! uucico(1), uucp(1), slattach(8)
  .SH COPYRIGHT
  The \fIchat\fR program is in public domain. This is not the GNU public
  license. If it breaks then you get to keep both pieces.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199502020203.VAA01811>