From e4fdd132492fc7a4aaa448a72f13f3344f287ab1 Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 7 Nov 1997 02:54:49 +0000 Subject: Support interactive mode. --- usr.sbin/pppctl/pppctl.c | 64 +++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'usr.sbin/pppctl/pppctl.c') diff --git a/usr.sbin/pppctl/pppctl.c b/usr.sbin/pppctl/pppctl.c index ca0748a..da44a60 100644 --- a/usr.sbin/pppctl/pppctl.c +++ b/usr.sbin/pppctl/pppctl.c @@ -15,7 +15,7 @@ static char Buffer[LINELEN], Command[LINELEN]; static int Usage() { - fprintf(stderr, "Usage: pppctl [-v] [ -t n ] [ -p passwd ] Port|LocalSock command[;command]...\n"); + fprintf(stderr, "Usage: pppctl [-v] [ -t n ] [ -p passwd ] Port|LocalSock [command[;command]...]\n"); fprintf(stderr, " -v tells pppctl to output all conversation\n"); fprintf(stderr, " -t n specifies a timeout of n seconds (default 2)\n"); fprintf(stderr, " -p passwd specifies your password\n"); @@ -150,7 +150,7 @@ main(int argc, char **argv) break; - if (argc < arg + 2) + if (argc < arg + 1) return Usage(); if (*argv[arg] == '/') { @@ -261,28 +261,46 @@ main(int argc, char **argv) break; case 0: - start = Command; - do { - next = index(start, ';'); - while (*start == ' ' || *start == '\t') - start++; - if (next) - *next = '\0'; - strcpy(Buffer, start); - Buffer[sizeof(Buffer)-2] = '\0'; - strcat(Buffer, "\n"); - if (verbose) - write(1, Buffer, strlen(Buffer)); - write(fd, Buffer, strlen(Buffer)); - if (Receive(fd, TimeoutVal, verbose | REC_SHOW) != 0) { - fprintf(stderr, "No reply from ppp\n"); - break; + if (len == 0) { + if (!verbose) { + /* Give a \n to ppp for a prompt */ + write(fd, "\n", 1); + if (Receive(fd, TimeoutVal, REC_VERBOSE | REC_SHOW) != 0) { + fprintf(stderr, "Connection closed\n"); + break; + } + } + while (fgets(Buffer, sizeof(Buffer)-1, stdin)) { + write(fd, Buffer, strlen(Buffer)); + if (Receive(fd, TimeoutVal, REC_VERBOSE | REC_SHOW) != 0) { + fprintf(stderr, "Connection closed\n"); + break; + } } - if (next) - start = ++next; - } while (next && *next); - if (verbose) - puts(""); + } else { + start = Command; + do { + next = index(start, ';'); + while (*start == ' ' || *start == '\t') + start++; + if (next) + *next = '\0'; + strcpy(Buffer, start); + Buffer[sizeof(Buffer)-2] = '\0'; + strcat(Buffer, "\n"); + if (verbose) + write(1, Buffer, strlen(Buffer)); + write(fd, Buffer, strlen(Buffer)); + if (Receive(fd, TimeoutVal, verbose | REC_SHOW) != 0) { + fprintf(stderr, "No reply from ppp\n"); + break; + } + if (next) + start = ++next; + } while (next && *next); + if (verbose) + puts(""); + } break; default: -- cgit v1.1