Move the terminal/diagnostic socket stuff out of main.c

and into the new `prompt.c'.  struct prompt is (of course)
a `sort' of descriptor.
This commit is contained in:
Brian Somers 1998-02-10 03:23:50 +00:00
parent b77776a7f2
commit 85b542cf4f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=33209
29 changed files with 836 additions and 653 deletions

View File

@ -1,10 +1,10 @@
# $Id: Makefile,v 1.36.2.4 1998/02/06 02:23:26 brian Exp $
# $Id: Makefile,v 1.36.2.5 1998/02/07 20:49:12 brian Exp $
PROG= ppp
SRCS= arp.c async.c auth.c bundle.c ccp.c chap.c chat.c command.c deflate.c \
defs.c filter.c fsm.c hdlc.c id.c ip.c ipcp.c iplist.c lcp.c \
link.c log.c lqr.c main.c mbuf.c modem.c pap.c physical.c \
pred.c route.c server.c sig.c slcompress.c systems.c throughput.c \
link.c log.c lqr.c main.c mbuf.c modem.c pap.c physical.c pred.c \
prompt.c route.c server.c sig.c slcompress.c systems.c throughput.c \
timer.c tun.c vars.c vjcomp.c
CFLAGS+=-Wall -Wpointer-arith
LDADD+= -lmd -lcrypt -lutil -lz

View File

@ -2,7 +2,7 @@
* The code in this file was written by Eivind Eklund <perhaps@yes.no>,
* who places it in the public domain without restriction.
*
* $Id: alias_cmd.c,v 1.12 1998/01/21 02:15:07 brian Exp $
* $Id: alias_cmd.c,v 1.12.2.1 1998/01/29 23:11:30 brian Exp $
*/
#include <sys/param.h>
@ -14,6 +14,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include "defs.h"
#include "command.h"
@ -22,6 +23,8 @@
#include "loadalias.h"
#include "vars.h"
#include "alias_cmd.h"
#include "descriptor.h"
#include "prompt.h"
static int StrToAddr(const char *, struct in_addr *);
@ -33,8 +36,7 @@ int
AliasRedirectPort(struct cmdargs const *arg)
{
if (!(mode & MODE_ALIAS)) {
if (VarTerm)
fprintf(VarTerm, "Alias not enabled\n");
prompt_Printf(&prompt, "Alias not enabled\n");
return 1;
} else if (arg->argc == 3) {
char proto_constant;
@ -52,28 +54,24 @@ AliasRedirectPort(struct cmdargs const *arg)
} else if (strcmp(proto, "udp") == 0) {
proto_constant = IPPROTO_UDP;
} else {
if (VarTerm) {
fprintf(VarTerm, "port redirect: protocol must be tcp or udp\n");
fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name,
arg->cmd->syntax);
}
prompt_Printf(&prompt, "port redirect: protocol must be tcp or udp\n");
prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name,
arg->cmd->syntax);
return 1;
}
error = StrToAddrAndPort(arg->argv[1], &local_addr, &local_port, proto);
if (error) {
if (VarTerm) {
fprintf(VarTerm, "port redirect: error reading local addr:port\n");
fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, arg->cmd->syntax);
}
prompt_Printf(&prompt, "port redirect: error reading local addr:port\n");
prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name,
arg->cmd->syntax);
return 1;
}
error = StrToPort(arg->argv[2], &alias_port, proto);
if (error) {
if (VarTerm) {
fprintf(VarTerm, "port redirect: error reading alias port\n");
fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, arg->cmd->syntax);
}
prompt_Printf(&prompt, "port redirect: error reading alias port\n");
prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name,
arg->cmd->syntax);
return 1;
}
null_addr.s_addr = INADDR_ANY;
@ -83,8 +81,8 @@ AliasRedirectPort(struct cmdargs const *arg)
null_addr, alias_port,
proto_constant);
if (link == NULL && VarTerm)
fprintf(VarTerm, "port redirect: error returned by packed"
if (link == NULL)
prompt_Printf(&prompt, "port redirect: error returned by packed"
" aliasing engine (code=%d)\n", error);
} else
return -1;
@ -97,8 +95,7 @@ int
AliasRedirectAddr(struct cmdargs const *arg)
{
if (!(mode & MODE_ALIAS)) {
if (VarTerm)
fprintf(VarTerm, "alias not enabled\n");
prompt_Printf(&prompt, "alias not enabled\n");
return 1;
} else if (arg->argc == 2) {
int error;
@ -108,22 +105,22 @@ AliasRedirectAddr(struct cmdargs const *arg)
error = StrToAddr(arg->argv[0], &local_addr);
if (error) {
if (VarTerm)
fprintf(VarTerm, "address redirect: invalid local address\n");
prompt_Printf(&prompt, "address redirect: invalid local address\n");
return 1;
}
error = StrToAddr(arg->argv[1], &alias_addr);
if (error) {
if (VarTerm) {
fprintf(VarTerm, "address redirect: invalid alias address\n");
fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, arg->cmd->syntax);
}
prompt_Printf(&prompt, "address redirect: invalid alias address\n");
prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name,
arg->cmd->syntax);
return 1;
}
link = VarPacketAliasRedirectAddr(local_addr, alias_addr);
if (link == NULL && VarTerm) {
fprintf(VarTerm, "address redirect: packet aliasing engine error\n");
fprintf(VarTerm, "Usage: alias %s %s\n", arg->cmd->name, arg->cmd->syntax);
if (link == NULL) {
prompt_Printf(&prompt, "address redirect: packet aliasing"
" engine error\n");
prompt_Printf(&prompt, "Usage: alias %s %s\n", arg->cmd->name,
arg->cmd->syntax);
}
} else
return -1;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.6 1998/02/08 19:29:43 brian Exp $
* $Id: bundle.c,v 1.1.2.7 1998/02/09 19:20:33 brian Exp $
*/
#include <sys/param.h>
@ -73,6 +73,7 @@
#include "pap.h"
#include "chap.h"
#include "tun.h"
#include "prompt.h"
static const char *PhaseNames[] = {
"Dead", "Establish", "Authenticate", "Network", "Terminate"
@ -115,7 +116,7 @@ bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new)
if (LcpInfo.want_auth == PROTO_CHAP)
StartAuthChallenge(&AuthChapInfo, physical);
bundle->phase = new;
Prompt(bundle);
prompt_Display(&prompt, bundle);
} else
bundle_NewPhase(bundle, physical, PHASE_NETWORK);
break;
@ -130,7 +131,7 @@ bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new)
case PHASE_TERMINATE:
bundle->phase = new;
Prompt(bundle);
prompt_Display(&prompt, bundle);
break;
}
}
@ -286,8 +287,8 @@ bundle_Create(const char *prefix)
}
if (bundle.unit > MAX_TUN) {
if (VarTerm)
fprintf(VarTerm, "No tunnel device is available (%s).\n", strerror(err));
prompt_Printf(&prompt, "No tunnel device is available (%s).\n",
strerror(err));
return NULL;
}
@ -339,8 +340,7 @@ bundle_Create(const char *prefix)
return NULL;
}
if (VarTerm)
fprintf(VarTerm, "Using interface: %s\n", bundle.ifname);
prompt_Printf(&prompt, "Using interface: %s\n", bundle.ifname);
LogPrintf(LogPHASE, "Using interface: %s\n", bundle.ifname);
bundle.routing_seq = 0;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ccp.c,v 1.30.2.7 1998/02/07 20:49:26 brian Exp $
* $Id: ccp.c,v 1.30.2.8 1998/02/08 11:04:45 brian Exp $
*
* TODO:
* o Support other compression protocols
@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include "command.h"
#include "mbuf.h"
@ -42,6 +43,8 @@
#include "pred.h"
#include "deflate.h"
#include "bundle.h"
#include "descriptor.h"
#include "prompt.h"
static void CcpSendConfigReq(struct fsm *);
static void CcpSendTerminateReq(struct fsm *);
@ -128,15 +131,13 @@ static const struct ccp_algorithm *algorithm[] = {
int
ReportCcpStatus(struct cmdargs const *arg)
{
if (VarTerm) {
fprintf(VarTerm, "%s [%s]\n", CcpInfo.fsm.name,
StateNames[CcpInfo.fsm.state]);
fprintf(VarTerm, "My protocol = %s, His protocol = %s\n",
protoname(CcpInfo.my_proto), protoname(CcpInfo.his_proto));
fprintf(VarTerm, "Output: %ld --> %ld, Input: %ld --> %ld\n",
CcpInfo.uncompout, CcpInfo.compout,
CcpInfo.compin, CcpInfo.uncompin);
}
prompt_Printf(&prompt, "%s [%s]\n", CcpInfo.fsm.name,
StateNames[CcpInfo.fsm.state]);
prompt_Printf(&prompt, "My protocol = %s, His protocol = %s\n",
protoname(CcpInfo.my_proto), protoname(CcpInfo.his_proto));
prompt_Printf(&prompt, "Output: %ld --> %ld, Input: %ld --> %ld\n",
CcpInfo.uncompout, CcpInfo.compout,
CcpInfo.compin, CcpInfo.uncompin);
return 0;
}

View File

@ -18,7 +18,7 @@
* Columbus, OH 43221
* (614)451-1883
*
* $Id: chat.c,v 1.44.2.4 1998/02/06 02:23:30 brian Exp $
* $Id: chat.c,v 1.44.2.5 1998/02/09 19:20:36 brian Exp $
*
* TODO:
* o Support more UUCP compatible control sequences.
@ -58,6 +58,7 @@
#include "descriptor.h"
#include "physical.h"
#include "chat.h"
#include "prompt.h"
#ifndef isblank
#define isblank(c) ((c) == '\t' || (c) == ' ')
@ -202,8 +203,7 @@ ExpandString(const char *str, char *result, int reslen, int sendmode)
strncpy(result, phone, reslen);
reslen -= strlen(result);
result += strlen(result);
if (VarTerm)
fprintf(VarTerm, "Phone: %s\n", phone);
prompt_Printf(&prompt, "Phone: %s\n", phone);
LogPrintf(LogPHASE, "Phone: %s\n", phone);
break;
case 'U':

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.13 1998/02/09 19:23:58 brian Exp $
* $Id: command.c,v 1.131.2.14 1998/02/10 03:21:39 brian Exp $
*
*/
#include <sys/param.h>
@ -77,6 +77,7 @@
#include "descriptor.h"
#include "physical.h"
#include "server.h"
#include "prompt.h"
struct in_addr ifnetmask;
static const char *HIDDEN = "********";
@ -105,14 +106,11 @@ HelpCommand(struct cmdargs const *arg)
struct cmdtab const *cmd;
int n, cmax, dmax, cols;
if (!VarTerm)
return 0;
if (arg->argc > 0) {
for (cmd = arg->cmd; cmd->name; cmd++)
if (strcasecmp(cmd->name, *arg->argv) == 0 &&
(cmd->lauth & VarLocalAuth)) {
fprintf(VarTerm, "%s\n", cmd->syntax);
prompt_Printf(&prompt, "%s\n", cmd->syntax);
return 0;
}
return -1;
@ -130,13 +128,13 @@ HelpCommand(struct cmdargs const *arg)
n = 0;
for (cmd = arg->cmd; cmd->func; cmd++)
if (cmd->name && (cmd->lauth & VarLocalAuth)) {
fprintf(VarTerm, " %-*.*s: %-*.*s",
prompt_Printf(&prompt, " %-*.*s: %-*.*s",
cmax, cmax, cmd->name, dmax, dmax, cmd->helpmes);
if (++n % cols == 0)
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, "\n");
}
if (n % cols != 0)
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, "\n");
return 0;
}
@ -159,8 +157,8 @@ IsInteractive(int Display)
else if (mode & MODE_INTER)
m = "interactive";
if (m) {
if (Display && VarTerm)
fprintf(VarTerm, "Working in %s mode\n", m);
if (Display)
prompt_Printf(&prompt, "Working in %s mode\n", m);
}
return mode & MODE_INTER;
}
@ -172,8 +170,8 @@ DialCommand(struct cmdargs const *arg)
int res;
if (LcpInfo.fsm.state > ST_CLOSED) {
if (VarTerm)
fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpInfo.fsm.state]);
prompt_Printf(&prompt, "LCP state is [%s]\n",
StateNames[LcpInfo.fsm.state]);
return 0;
}
@ -193,11 +191,9 @@ DialCommand(struct cmdargs const *arg)
VarRedialNextTimeout);
nointr_sleep(VarRedialNextTimeout);
}
if (VarTerm)
fprintf(VarTerm, "Dial attempt %u of %d\n", ++tries, VarDialTries);
prompt_Printf(&prompt, "Dial attempt %u of %d\n", ++tries, VarDialTries);
if (modem_Open(arg->bundle->physical, arg->bundle) < 0) {
if (VarTerm)
fprintf(VarTerm, "Failed to open modem.\n");
prompt_Printf(&prompt, "Failed to open modem.\n");
break;
}
if ((res = modem_Dial(arg->bundle->physical, arg->bundle)) == EX_DONE) {
@ -246,7 +242,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
* we want to stop shell commands when we've got a telnet connection to an
* auto mode ppp
*/
if (VarTerm && !(mode & MODE_INTER)) {
if (prompt_Active(&prompt) && !(mode & MODE_INTER)) {
LogPrintf(LogWARN, "Shell is not allowed interactively in auto mode\n");
return 1;
}
@ -254,7 +250,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
if (arg->argc == 0)
if (!(mode & MODE_INTER)) {
if (VarTerm)
if (prompt_Active(&prompt))
LogPrintf(LogWARN, "Can't start an interactive shell from"
" a telnet session\n");
else
@ -279,8 +275,8 @@ ShellCommand(struct cmdargs const *arg, int bg)
signal(SIGHUP, SIG_DFL);
signal(SIGALRM, SIG_DFL);
if (VarTerm)
fd = fileno(VarTerm);
if (prompt_Active(&prompt))
fd = prompt.fd_out;
else if ((fd = open("/dev/null", O_RDWR)) == -1) {
LogPrintf(LogALERT, "Failed to open /dev/null: %s\n", strerror(errno));
exit(1);
@ -291,7 +287,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
for (dtablesize = getdtablesize(), i = 3; i < dtablesize; i++)
close(i);
TtyOldMode();
prompt_TtyOldMode(&prompt);
setuid(geteuid());
if (arg->argc > 0) {
/* substitute pseudo args */
@ -315,11 +311,11 @@ ShellCommand(struct cmdargs const *arg, int bg)
LogPrintf(LogERROR, "%d: daemon: %s\n", p, strerror(errno));
exit(1);
}
} else if (VarTerm)
} else if (prompt_Active(&prompt))
printf("ppp: Pausing until %s finishes\n", arg->argv[0]);
execvp(argv[0], argv);
} else {
if (VarTerm)
if (prompt_Active(&prompt))
printf("ppp: Pausing until %s finishes\n", shell);
execl(shell, shell, NULL);
}
@ -336,7 +332,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
waitpid(shpid, &status, 0);
}
TtyCommandMode(arg->bundle, 0);
prompt_TtyCommandMode(&prompt);
return (0);
}
@ -412,9 +408,7 @@ static struct cmdtab const Commands[] = {
static int
ShowLoopback(struct cmdargs const *arg)
{
if (VarTerm)
fprintf(VarTerm, "Local loopback is %s\n", VarLoopback ? "on" : "off");
prompt_Printf(&prompt, "Local loopback is %s\n", VarLoopback ? "on" : "off");
return 0;
}
@ -423,20 +417,17 @@ ShowLogLevel(struct cmdargs const *arg)
{
int i;
if (!VarTerm)
return 0;
fprintf(VarTerm, "Log: ");
prompt_Printf(&prompt, "Log: ");
for (i = LogMIN; i <= LogMAX; i++)
if (LogIsKept(i) & LOG_KEPT_SYSLOG)
fprintf(VarTerm, " %s", LogName(i));
prompt_Printf(&prompt, " %s", LogName(i));
fprintf(VarTerm, "\nLocal:");
prompt_Printf(&prompt, "\nLocal:");
for (i = LogMIN; i <= LogMAX; i++)
if (LogIsKept(i) & LOG_KEPT_LOCAL)
fprintf(VarTerm, " %s", LogName(i));
prompt_Printf(&prompt, " %s", LogName(i));
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, "\n");
return 0;
}
@ -446,15 +437,13 @@ ShowEscape(struct cmdargs const *arg)
{
int code, bit;
if (!VarTerm)
return 0;
if (EscMap[32]) {
for (code = 0; code < 32; code++)
if (EscMap[code])
for (bit = 0; bit < 8; bit++)
if (EscMap[code] & (1 << bit))
fprintf(VarTerm, " 0x%02x", (code << 3) + bit);
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, " 0x%02x", (code << 3) + bit);
prompt_Printf(&prompt, "\n");
}
return 0;
}
@ -462,44 +451,43 @@ ShowEscape(struct cmdargs const *arg)
static int
ShowTimeout(struct cmdargs const *arg)
{
if (VarTerm) {
int remaining;
int remaining;
prompt_Printf(&prompt, " Idle Timer: %d secs LQR Timer: %d secs"
" Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout,
VarRetryTimeout);
remaining = RemainingIdleTime();
if (remaining != -1)
prompt_Printf(&prompt, " %d secs remaining\n", remaining);
fprintf(VarTerm, " Idle Timer: %d secs LQR Timer: %d secs"
" Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout,
VarRetryTimeout);
remaining = RemainingIdleTime();
if (remaining != -1)
fprintf(VarTerm, " %d secs remaining\n", remaining);
}
return 0;
}
static int
ShowStopped(struct cmdargs const *arg)
{
if (!VarTerm)
return 0;
fprintf(VarTerm, " Stopped Timer: LCP: ");
prompt_Printf(&prompt, " Stopped Timer: LCP: ");
if (!LcpInfo.fsm.StoppedTimer.load)
fprintf(VarTerm, "Disabled");
prompt_Printf(&prompt, "Disabled");
else
fprintf(VarTerm, "%ld secs", LcpInfo.fsm.StoppedTimer.load / SECTICKS);
prompt_Printf(&prompt, "%ld secs",
LcpInfo.fsm.StoppedTimer.load / SECTICKS);
fprintf(VarTerm, ", IPCP: ");
prompt_Printf(&prompt, ", IPCP: ");
if (!IpcpInfo.fsm.StoppedTimer.load)
fprintf(VarTerm, "Disabled");
prompt_Printf(&prompt, "Disabled");
else
fprintf(VarTerm, "%ld secs", IpcpInfo.fsm.StoppedTimer.load / SECTICKS);
prompt_Printf(&prompt, "%ld secs",
IpcpInfo.fsm.StoppedTimer.load / SECTICKS);
fprintf(VarTerm, ", CCP: ");
prompt_Printf(&prompt, ", CCP: ");
if (!CcpInfo.fsm.StoppedTimer.load)
fprintf(VarTerm, "Disabled");
prompt_Printf(&prompt, "Disabled");
else
fprintf(VarTerm, "%ld secs", CcpInfo.fsm.StoppedTimer.load / SECTICKS);
prompt_Printf(&prompt, "%ld secs",
CcpInfo.fsm.StoppedTimer.load / SECTICKS);
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, "\n");
return 0;
}
@ -507,12 +495,10 @@ ShowStopped(struct cmdargs const *arg)
static int
ShowAuthKey(struct cmdargs const *arg)
{
if (!VarTerm)
return 0;
fprintf(VarTerm, "AuthName = %s\n", VarAuthName);
fprintf(VarTerm, "AuthKey = %s\n", HIDDEN);
prompt_Printf(&prompt, "AuthName = %s\n", VarAuthName);
prompt_Printf(&prompt, "AuthKey = %s\n", HIDDEN);
#ifdef HAVE_DES
fprintf(VarTerm, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" );
prompt_Printf(&prompt, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" );
#endif
return 0;
}
@ -520,64 +506,56 @@ ShowAuthKey(struct cmdargs const *arg)
static int
ShowVersion(struct cmdargs const *arg)
{
if (VarTerm)
fprintf(VarTerm, "%s - %s \n", VarVersion, VarLocalVersion);
prompt_Printf(&prompt, "%s - %s \n", VarVersion, VarLocalVersion);
return 0;
}
static int
ShowInitialMRU(struct cmdargs const *arg)
{
if (VarTerm)
fprintf(VarTerm, " Initial MRU: %d\n", VarMRU);
prompt_Printf(&prompt, " Initial MRU: %d\n", VarMRU);
return 0;
}
static int
ShowPreferredMTU(struct cmdargs const *arg)
{
if (VarTerm)
if (VarPrefMTU)
fprintf(VarTerm, " Preferred MTU: %d\n", VarPrefMTU);
else
fprintf(VarTerm, " Preferred MTU: unspecified\n");
if (VarPrefMTU)
prompt_Printf(&prompt, " Preferred MTU: %d\n", VarPrefMTU);
else
prompt_Printf(&prompt, " Preferred MTU: unspecified\n");
return 0;
}
static int
ShowReconnect(struct cmdargs const *arg)
{
if (VarTerm)
fprintf(VarTerm, " Reconnect Timer: %d, %d tries\n",
VarReconnectTimer, VarReconnectTries);
prompt_Printf(&prompt, " Reconnect Timer: %d, %d tries\n",
VarReconnectTimer, VarReconnectTries);
return 0;
}
static int
ShowRedial(struct cmdargs const *arg)
{
if (!VarTerm)
return 0;
fprintf(VarTerm, " Redial Timer: ");
prompt_Printf(&prompt, " Redial Timer: ");
if (VarRedialTimeout >= 0) {
fprintf(VarTerm, " %d seconds, ", VarRedialTimeout);
} else {
fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD);
}
if (VarRedialTimeout >= 0)
prompt_Printf(&prompt, " %d seconds, ", VarRedialTimeout);
else
prompt_Printf(&prompt, " Random 0 - %d seconds, ", REDIAL_PERIOD);
fprintf(VarTerm, " Redial Next Timer: ");
prompt_Printf(&prompt, " Redial Next Timer: ");
if (VarRedialNextTimeout >= 0) {
fprintf(VarTerm, " %d seconds, ", VarRedialNextTimeout);
} else {
fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD);
}
if (VarRedialNextTimeout >= 0)
prompt_Printf(&prompt, " %d seconds, ", VarRedialNextTimeout);
else
prompt_Printf(&prompt, " Random 0 - %d seconds, ", REDIAL_PERIOD);
if (VarDialTries)
fprintf(VarTerm, "%d dial tries", VarDialTries);
prompt_Printf(&prompt, "%d dial tries", VarDialTries);
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, "\n");
return 0;
}
@ -586,17 +564,16 @@ ShowRedial(struct cmdargs const *arg)
static int
ShowMSExt(struct cmdargs const *arg)
{
if (VarTerm) {
fprintf(VarTerm, " MS PPP extention values \n");
fprintf(VarTerm, " Primary NS : %s\n",
inet_ntoa(IpcpInfo.ns_entries[0]));
fprintf(VarTerm, " Secondary NS : %s\n",
inet_ntoa(IpcpInfo.ns_entries[1]));
fprintf(VarTerm, " Primary NBNS : %s\n",
inet_ntoa(IpcpInfo.nbns_entries[0]));
fprintf(VarTerm, " Secondary NBNS : %s\n",
inet_ntoa(IpcpInfo.nbns_entries[1]));
}
prompt_Printf(&prompt, " MS PPP extention values \n");
prompt_Printf(&prompt, " Primary NS : %s\n",
inet_ntoa(IpcpInfo.ns_entries[0]));
prompt_Printf(&prompt, " Secondary NS : %s\n",
inet_ntoa(IpcpInfo.ns_entries[1]));
prompt_Printf(&prompt, " Primary NBNS : %s\n",
inet_ntoa(IpcpInfo.nbns_entries[0]));
prompt_Printf(&prompt, " Secondary NBNS : %s\n",
inet_ntoa(IpcpInfo.nbns_entries[1]));
return 0;
}
@ -722,37 +699,6 @@ FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc,
return val;
}
int aft_cmd = 1;
void
Prompt(struct bundle *bundle)
{
const char *pconnect, *pauth;
if (!VarTerm || TermMode || CleaningUp)
return;
if (!aft_cmd)
fprintf(VarTerm, "\n");
else
aft_cmd = 0;
if (VarLocalAuth == LOCAL_AUTH)
pauth = " ON ";
else
pauth = " on ";
if (IpcpInfo.fsm.state == ST_OPENED)
pconnect = "PPP";
else if (bundle_Phase(bundle) == PHASE_NETWORK)
pconnect = "PPp";
else if (bundle_Phase(bundle) == PHASE_AUTHENTICATE)
pconnect = "Ppp";
else
pconnect = "ppp";
fprintf(VarTerm, "%s%s%s> ", pconnect, pauth, VarShortHost);
fflush(VarTerm);
}
void
InterpretCommand(char *buff, int nb, int *argc, char ***argv)
{
@ -831,10 +777,12 @@ DecodeCommand(struct bundle *bundle, char *buff, int nb, const char *label)
static int
ShowCommand(struct cmdargs const *arg)
{
if (arg->argc > 0)
if (!prompt_Active(&prompt))
LogPrintf(LogWARN, "show: Cannot show without a prompt\n");
else if (arg->argc > 0)
FindExec(arg->bundle, ShowCommands, arg->argc, arg->argv, "show ");
else if (VarTerm)
fprintf(VarTerm, "Use ``show ?'' to get a list.\n");
else if (prompt_Active(&prompt))
prompt_Printf(&prompt, "Use ``show ?'' to get a list.\n");
else
LogPrintf(LogWARN, "show command must have arguments\n");
@ -845,30 +793,27 @@ static int
TerminalCommand(struct cmdargs const *arg)
{
if (LcpInfo.fsm.state > ST_CLOSED) {
if (VarTerm)
fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpInfo.fsm.state]);
prompt_Printf(&prompt, "LCP state is [%s]\n",
StateNames[LcpInfo.fsm.state]);
return 1;
}
if (!IsInteractive(1))
return (1);
if (modem_Open(arg->bundle->physical, arg->bundle) < 0) {
if (VarTerm)
fprintf(VarTerm, "Failed to open modem.\n");
prompt_Printf(&prompt, "Failed to open modem.\n");
return (1);
}
if (VarTerm) {
fprintf(VarTerm, "Entering terminal mode.\n");
fprintf(VarTerm, "Type `~?' for help.\n");
}
TtyTermMode();
return (0);
prompt_Printf(&prompt, "Entering terminal mode.\n");
prompt_Printf(&prompt, "Type `~?' for help.\n");
prompt_TtyTermMode(&prompt);
return 0;
}
static int
QuitCommand(struct cmdargs const *arg)
{
if (VarTerm) {
DropClient(1);
if (prompt_Active(&prompt)) {
prompt_Drop(&prompt, 1);
if ((mode & MODE_INTER) ||
(arg->argc > 0 && !strcasecmp(*arg->argv, "all") &&
(VarLocalAuth & LOCAL_AUTH)))
@ -1526,8 +1471,8 @@ SetCommand(struct cmdargs const *arg)
{
if (arg->argc > 0)
FindExec(arg->bundle, SetCommands, arg->argc, arg->argv, "set ");
else if (VarTerm)
fprintf(VarTerm, "Use `set ?' to get a list or `set ? <var>' for"
else if (prompt_Active(&prompt))
prompt_Printf(&prompt, "Use `set ?' to get a list or `set ? <var>' for"
" syntax help.\n");
else
LogPrintf(LogWARN, "set command must have arguments\n");
@ -1634,8 +1579,8 @@ AliasCommand(struct cmdargs const *arg)
{
if (arg->argc > 0)
FindExec(arg->bundle, AliasCommands, arg->argc, arg->argv, "alias ");
else if (VarTerm)
fprintf(VarTerm, "Use `alias help' to get a list or `alias help"
else if (prompt_Active(&prompt))
prompt_Printf(&prompt, "Use `alias help' to get a list or `alias help"
" <option>' for syntax help.\n");
else
LogPrintf(LogWARN, "alias command must have arguments\n");
@ -1706,8 +1651,8 @@ AllowCommand(struct cmdargs const *arg)
/* arg->bundle may be NULL (see ValidSystem()) ! */
if (arg->argc > 0)
FindExec(arg->bundle, AllowCommands, arg->argc, arg->argv, "allow ");
else if (VarTerm)
fprintf(VarTerm, "Use `allow ?' to get a list or `allow ? <cmd>' for"
else if (prompt_Active(&prompt))
prompt_Printf(&prompt, "Use `allow ?' to get a list or `allow ? <cmd>' for"
" syntax help.\n");
else
LogPrintf(LogWARN, "allow command must have arguments\n");

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.h,v 1.12.2.1 1998/02/02 19:32:04 brian Exp $
* $Id: command.h,v 1.12.2.2 1998/02/07 20:49:33 brian Exp $
*
* TODO:
*/
@ -56,7 +56,6 @@ extern struct in_addr ifnetmask;
extern int aft_cmd;
extern int SetVariable(struct cmdargs const *);
extern void Prompt(struct bundle *);
extern int IsInteractive(int);
extern void InterpretCommand(char *, int, int *, char ***);
extern void RunCommand(struct bundle *, int, char const *const *, const char *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: defs.c,v 1.11.4.1 1998/01/29 20:45:16 brian Exp $
* $Id: defs.c,v 1.11.4.2 1998/02/02 19:32:05 brian Exp $
*/
#include <sys/param.h>
@ -46,7 +46,6 @@
int mode = MODE_INTER;
int BGFiledes[2] = { -1, -1 };
int modem = -1;
int netfd = -1;
static char dstsystem[50];
@ -96,20 +95,3 @@ GetShortHost()
return 1;
}
void
DropClient(int verbose)
{
FILE *oVarTerm;
if (VarTerm && !(mode & MODE_INTER)) {
oVarTerm = VarTerm;
VarTerm = 0;
if (oVarTerm)
fclose(oVarTerm);
close(netfd);
netfd = -1;
if (verbose)
LogPrintf(LogPHASE, "Client connection dropped.\n");
}
}

View File

@ -23,11 +23,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: descriptor.h,v 1.1.2.2 1998/02/09 19:23:59 brian Exp $
* $Id: descriptor.h,v 1.1.2.3 1998/02/10 03:21:55 brian Exp $
*/
#define PHYSICAL_DESCRIPTOR (1)
#define SERVER_DESCRIPTOR (1)
#define SERVER_DESCRIPTOR (2)
#define PROMPT_DESCRIPTOR (3)
struct descriptor {
int type;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: filter.c,v 1.22.2.2 1998/01/30 19:45:38 brian Exp $
* $Id: filter.c,v 1.22.2.3 1998/01/31 02:48:17 brian Exp $
*
* TODO: Shoud send ICMP error message when we discard packets.
*/
@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <termios.h>
#include "command.h"
#include "mbuf.h"
@ -45,6 +46,8 @@
#include "fsm.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
#include "prompt.h"
struct filterent ifilters[MAXFILTERS]; /* incoming packet filter */
struct filterent ofilters[MAXFILTERS]; /* outgoing packet filter */
@ -444,34 +447,32 @@ ShowFilter(struct filterent * fp)
{
int n;
if (!VarTerm)
return;
for (n = 0; n < MAXFILTERS; n++, fp++) {
if (fp->action != A_NONE) {
fprintf(VarTerm, "%2d %s", n, actname[fp->action & (A_PERMIT|A_DENY)]);
prompt_Printf(&prompt, "%2d %s", n,
actname[fp->action & (A_PERMIT|A_DENY)]);
if (fp->action & A_UHOST)
fprintf(VarTerm, "host ");
prompt_Printf(&prompt, "host ");
else if (fp->action & A_UPORT)
fprintf(VarTerm, "port ");
prompt_Printf(&prompt, "port ");
else
fprintf(VarTerm, " ");
fprintf(VarTerm, "%s/%d ", inet_ntoa(fp->saddr), fp->swidth);
fprintf(VarTerm, "%s/%d ", inet_ntoa(fp->daddr), fp->dwidth);
prompt_Printf(&prompt, " ");
prompt_Printf(&prompt, "%s/%d ", inet_ntoa(fp->saddr), fp->swidth);
prompt_Printf(&prompt, "%s/%d ", inet_ntoa(fp->daddr), fp->dwidth);
if (fp->proto) {
fprintf(VarTerm, "%s", protoname[fp->proto]);
prompt_Printf(&prompt, "%s", protoname[fp->proto]);
if (fp->opt.srcop)
fprintf(VarTerm, " src %s %d", opname[fp->opt.srcop],
prompt_Printf(&prompt, " src %s %d", opname[fp->opt.srcop],
fp->opt.srcport);
if (fp->opt.dstop)
fprintf(VarTerm, " dst %s %d", opname[fp->opt.dstop],
prompt_Printf(&prompt, " dst %s %d", opname[fp->opt.dstop],
fp->opt.dstport);
if (fp->opt.estab)
fprintf(VarTerm, " estab");
prompt_Printf(&prompt, " estab");
}
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, "\n");
}
}
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: hdlc.c,v 1.28.2.7 1998/02/07 20:49:36 brian Exp $
* $Id: hdlc.c,v 1.28.2.8 1998/02/09 19:20:47 brian Exp $
*
* TODO:
*/
@ -53,6 +53,7 @@
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "prompt.h"
static struct hdlcstat {
int badfcs;
@ -448,13 +449,10 @@ DecodePacket(struct bundle *bundle, u_short proto, struct mbuf * bp,
int
ReportHdlcStatus(struct cmdargs const *arg)
{
struct hdlcstat *hp = &HdlcStat;
if (VarTerm) {
fprintf(VarTerm, "HDLC level errors\n\n");
fprintf(VarTerm, "FCS: %u ADDR: %u COMMAND: %u PROTO: %u\n",
hp->badfcs, hp->badaddr, hp->badcommand, hp->unknownproto);
}
prompt_Printf(&prompt, "HDLC level errors\n\n");
prompt_Printf(&prompt, "FCS: %u ADDR: %u COMMAND: %u PROTO: %u\n",
HdlcStat.badfcs, HdlcStat.badaddr,
HdlcStat.badcommand, HdlcStat.unknownproto);
return 0;
}
@ -463,15 +461,14 @@ static struct hdlcstat laststat;
void
HdlcErrorCheck()
{
struct hdlcstat *hp = &HdlcStat;
struct hdlcstat *op = &laststat;
if (memcmp(hp, op, sizeof laststat)) {
if (memcmp(&HdlcStat, &laststat, sizeof laststat)) {
LogPrintf(LogPHASE, "HDLC errors -> FCS: %u ADDR: %u COMD: %u PROTO: %u\n",
hp->badfcs - op->badfcs, hp->badaddr - op->badaddr,
hp->badcommand - op->badcommand, hp->unknownproto - op->unknownproto);
HdlcStat.badfcs - laststat.badfcs,
HdlcStat.badaddr - laststat.badaddr,
HdlcStat.badcommand - laststat.badcommand,
HdlcStat.unknownproto - laststat.unknownproto);
laststat = HdlcStat;
}
laststat = HdlcStat;
}
void

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.c,v 1.50.2.11 1998/02/08 19:29:44 brian Exp $
* $Id: ipcp.c,v 1.50.2.12 1998/02/09 19:20:52 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -67,6 +67,7 @@
#include "id.h"
#include "arp.h"
#include "systems.h"
#include "prompt.h"
struct compreq {
u_short proto;
@ -152,38 +153,36 @@ IpcpAddOutOctets(int n)
int
ReportIpcpStatus(struct cmdargs const *arg)
{
if (!VarTerm)
return 1;
fprintf(VarTerm, "%s [%s]\n", IpcpInfo.fsm.name,
prompt_Printf(&prompt, "%s [%s]\n", IpcpInfo.fsm.name,
StateNames[IpcpInfo.fsm.state]);
if (IpcpInfo.fsm.state == ST_OPENED) {
fprintf(VarTerm, " His side: %s, %s\n",
prompt_Printf(&prompt, " His side: %s, %s\n",
inet_ntoa(IpcpInfo.his_ipaddr), vj2asc(IpcpInfo.his_compproto));
fprintf(VarTerm, " My side: %s, %s\n",
prompt_Printf(&prompt, " My side: %s, %s\n",
inet_ntoa(IpcpInfo.want_ipaddr), vj2asc(IpcpInfo.want_compproto));
}
fprintf(VarTerm, "\nDefaults:\n");
fprintf(VarTerm, " My Address: %s/%d\n",
prompt_Printf(&prompt, "\nDefaults:\n");
prompt_Printf(&prompt, " My Address: %s/%d\n",
inet_ntoa(IpcpInfo.DefMyAddress.ipaddr), IpcpInfo.DefMyAddress.width);
if (iplist_isvalid(&IpcpInfo.DefHisChoice))
fprintf(VarTerm, " His Address: %s\n",
prompt_Printf(&prompt, " His Address: %s\n",
IpcpInfo.DefHisChoice.src);
else
fprintf(VarTerm, " His Address: %s/%d\n",
prompt_Printf(&prompt, " His Address: %s/%d\n",
inet_ntoa(IpcpInfo.DefHisAddress.ipaddr),
IpcpInfo.DefHisAddress.width);
if (IpcpInfo.HaveTriggerAddress)
fprintf(VarTerm, " Negotiation(trigger): %s\n",
prompt_Printf(&prompt, " Negotiation(trigger): %s\n",
inet_ntoa(IpcpInfo.TriggerAddress));
else
fprintf(VarTerm, " Negotiation(trigger): MYADDR\n");
fprintf(VarTerm, " Initial VJ slots: %d\n", IpcpInfo.VJInitSlots);
fprintf(VarTerm, " Initial VJ compression: %s\n",
prompt_Printf(&prompt, " Negotiation(trigger): MYADDR\n");
prompt_Printf(&prompt, " Initial VJ slots: %d\n", IpcpInfo.VJInitSlots);
prompt_Printf(&prompt, " Initial VJ compression: %s\n",
IpcpInfo.VJInitComp ? "on" : "off");
fprintf(VarTerm, "\n");
throughput_disp(&IpcpInfo.throughput, VarTerm);
prompt_Printf(&prompt, "\n");
throughput_disp(&IpcpInfo.throughput);
return 0;
}
@ -531,8 +530,7 @@ IpcpLayerUp(struct fsm *fp)
if (ipcp_SetIPaddress(fp->bundle, ipcp, ipcp->want_ipaddr,
ipcp->his_ipaddr, ifnetmask, 0) < 0) {
if (VarTerm)
LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
return;
}
@ -557,7 +555,7 @@ IpcpLayerUp(struct fsm *fp)
throughput_start(&ipcp->throughput);
StartIdleTimer();
Prompt(fp->bundle);
prompt_Display(&prompt, fp->bundle);
}
void

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lcp.c,v 1.55.2.12 1998/02/08 11:04:54 brian Exp $
* $Id: lcp.c,v 1.55.2.13 1998/02/09 19:20:54 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -67,6 +67,7 @@
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "prompt.h"
/* for received LQRs */
struct lqrreq {
@ -165,28 +166,27 @@ LcpReportTime(void *v)
int
ReportLcpStatus(struct cmdargs const *arg)
{
if (!VarTerm)
return 1;
fprintf(VarTerm, "%s [%s]\n", LcpInfo.fsm.name,
StateNames[LcpInfo.fsm.state]);
fprintf(VarTerm,
" his side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n"
" MAGIC %08lx, REJECT %04x\n",
LcpInfo.his_mru, (u_long)LcpInfo.his_accmap, LcpInfo.his_protocomp,
LcpInfo.his_acfcomp, (u_long)LcpInfo.his_magic, LcpInfo.his_reject);
fprintf(VarTerm,
" my side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n"
" MAGIC %08lx, REJECT %04x\n",
LcpInfo.want_mru, (u_long)LcpInfo.want_accmap, LcpInfo.want_protocomp,
LcpInfo.want_acfcomp, (u_long)LcpInfo.want_magic, LcpInfo.my_reject);
fprintf(VarTerm, "\nDefaults: MRU = %d, ACCMAP = %08lx\t",
VarMRU, (u_long)VarAccmap);
fprintf(VarTerm, "Open Mode: %s",
(VarOpenMode == OPEN_PASSIVE) ? "passive" : "active");
prompt_Printf(&prompt, "%s [%s]\n", LcpInfo.fsm.name,
StateNames[LcpInfo.fsm.state]);
prompt_Printf(&prompt,
" his side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n"
" MAGIC %08lx, REJECT %04x\n",
LcpInfo.his_mru, (u_long)LcpInfo.his_accmap,
LcpInfo.his_protocomp, LcpInfo.his_acfcomp,
(u_long)LcpInfo.his_magic, LcpInfo.his_reject);
prompt_Printf(&prompt,
" my side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n"
" MAGIC %08lx, REJECT %04x\n",
LcpInfo.want_mru, (u_long)LcpInfo.want_accmap,
LcpInfo.want_protocomp, LcpInfo.want_acfcomp,
(u_long)LcpInfo.want_magic, LcpInfo.my_reject);
prompt_Printf(&prompt, "\nDefaults: MRU = %d, ACCMAP = %08lx\t",
VarMRU, (u_long)VarAccmap);
prompt_Printf(&prompt, "Open Mode: %s",
(VarOpenMode == OPEN_PASSIVE) ? "passive" : "active");
if (VarOpenMode > 0)
fprintf(VarTerm, " (delay %d)", VarOpenMode);
fputc('\n', VarTerm);
prompt_Printf(&prompt, " (delay %d)", VarOpenMode);
prompt_Printf(&prompt, "\n");
return 0;
}

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: link.c,v 1.1.2.3 1998/02/06 02:23:35 brian Exp $
* $Id: link.c,v 1.1.2.4 1998/02/07 20:49:47 brian Exp $
*
*/
@ -31,6 +31,7 @@
#include <netinet/in.h>
#include <stdio.h>
#include <termios.h>
#include "command.h"
#include "mbuf.h"
@ -44,6 +45,8 @@
#include "vars.h"
#include "link.h"
#include "bundle.h"
#include "descriptor.h"
#include "prompt.h"
void
link_AddInOctets(struct link *l, int n)
@ -189,14 +192,14 @@ link_ReportProtocolStatus(struct link *l)
{
int i;
fprintf(VarTerm,
" Protocol in out Protocol in out\n");
prompt_Printf(&prompt, " Protocol in out "
"Protocol in out\n");
for (i = 0; i < NPROTOSTAT; i++) {
fprintf(VarTerm, " %-9s: %8lu, %8lu",
prompt_Printf(&prompt, " %-9s: %8lu, %8lu",
ProtocolStat[i].name, l->proto_in[i], l->proto_out[i]);
if ((i % 2) == 0)
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, "\n");
}
if (i % 2)
fprintf(VarTerm, "\n");
prompt_Printf(&prompt, "\n");
}

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: log.c,v 1.24 1997/12/24 09:29:05 brian Exp $
* $Id: log.c,v 1.25 1998/01/21 02:15:18 brian Exp $
*/
#include <sys/param.h>
@ -32,6 +32,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
#include <termios.h>
#include "command.h"
#include "mbuf.h"
@ -39,6 +40,8 @@
#include "loadalias.h"
#include "defs.h"
#include "vars.h"
#include "descriptor.h"
#include "prompt.h"
static const char *LogNames[] = {
"Async",
@ -169,17 +172,17 @@ LogPrintf(int lev, const char *fmt,...)
if (LogIsKept(lev)) {
static char nfmt[200];
if ((LogIsKept(lev) & LOG_KEPT_LOCAL) && VarTerm) {
if ((LogIsKept(lev) & LOG_KEPT_LOCAL) && prompt_Active(&prompt)) {
if ((LogIsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1)
snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s",
LogTunno, LogName(lev), fmt);
else
snprintf(nfmt, sizeof nfmt, "%s: %s", LogName(lev), fmt);
vfprintf(VarTerm, nfmt, ap);
fflush(VarTerm);
prompt_vPrintf(&prompt, nfmt, ap);
}
if ((LogIsKept(lev) & LOG_KEPT_SYSLOG) && (lev != LogWARN || !VarTerm)) {
if ((LogIsKept(lev) & LOG_KEPT_SYSLOG) && (lev != LogWARN ||
!prompt_Active(&prompt))) {
if ((LogIsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1)
snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s",
LogTunno, LogName(lev), fmt);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
* $Id: log.h,v 1.18 1997/12/21 12:11:07 brian Exp $
*/
#define LogMIN (1)
@ -49,6 +49,8 @@
#define LogALERT (19) /* syslog(LOG_ALERT, ....) */
#define LogMAX (19)
struct mbuf;
/* The first int arg for all of the following is one of the above values */
extern const char *LogName(int);
extern void LogKeep(int);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.121.2.17 1998/02/09 19:24:00 brian Exp $
* $Id: main.c,v 1.121.2.18 1998/02/10 03:21:57 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -78,6 +78,7 @@
#include "descriptor.h"
#include "physical.h"
#include "server.h"
#include "prompt.h"
#ifndef O_NONBLOCK
#ifdef O_NDELAY
@ -85,10 +86,6 @@
#endif
#endif
int TermMode = 0;
static struct termios oldtio; /* Original tty mode */
static struct termios comtio; /* Command level tty mode */
static pid_t BGPid = 0;
static char pid_filename[MAXPATHLEN];
static int dial_up;
@ -97,87 +94,6 @@ static void DoLoop(struct bundle *);
static void TerminalStop(int);
static const char *ex_desc(int);
static void
TtyInit(int DontWantInt)
{
struct termios newtio;
int stat;
stat = fcntl(netfd, F_GETFL, 0);
if (stat > 0) {
stat |= O_NONBLOCK;
(void) fcntl(netfd, F_SETFL, stat);
}
newtio = oldtio;
newtio.c_lflag &= ~(ECHO | ISIG | ICANON);
newtio.c_iflag = 0;
newtio.c_oflag &= ~OPOST;
newtio.c_cc[VEOF] = _POSIX_VDISABLE;
if (DontWantInt)
newtio.c_cc[VINTR] = _POSIX_VDISABLE;
newtio.c_cc[VMIN] = 1;
newtio.c_cc[VTIME] = 0;
newtio.c_cflag |= CS8;
tcsetattr(netfd, TCSANOW, &newtio);
comtio = newtio;
}
/*
* Set tty into command mode. We allow canonical input and echo processing.
*/
void
TtyCommandMode(struct bundle *bundle, int prompt)
{
struct termios newtio;
int stat;
if (!(mode & MODE_INTER))
return;
tcgetattr(netfd, &newtio);
newtio.c_lflag |= (ECHO | ISIG | ICANON);
newtio.c_iflag = oldtio.c_iflag;
newtio.c_oflag |= OPOST;
tcsetattr(netfd, TCSADRAIN, &newtio);
stat = fcntl(netfd, F_GETFL, 0);
if (stat > 0) {
stat |= O_NONBLOCK;
(void) fcntl(netfd, F_SETFL, stat);
}
TermMode = 0;
if (prompt)
Prompt(bundle);
}
/*
* Set tty into terminal mode which is used while we invoke term command.
*/
void
TtyTermMode()
{
int stat;
tcsetattr(netfd, TCSADRAIN, &comtio);
stat = fcntl(netfd, F_GETFL, 0);
if (stat > 0) {
stat &= ~O_NONBLOCK;
(void) fcntl(netfd, F_SETFL, stat);
}
TermMode = 1;
}
void
TtyOldMode()
{
int stat;
stat = fcntl(netfd, F_GETFL, 0);
if (stat > 0) {
stat &= ~O_NONBLOCK;
(void) fcntl(netfd, F_SETFL, stat);
}
tcsetattr(netfd, TCSADRAIN, &oldtio);
}
static struct bundle *SignalBundle;
int CleaningUp;
@ -196,7 +112,7 @@ Cleanup(int excode)
void
AbortProgram(int excode)
{
DropClient(1);
prompt_Drop(&prompt, 1);
ServerClose();
ID0unlink(pid_filename);
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
@ -209,7 +125,7 @@ AbortProgram(int excode)
close(BGFiledes[1]);
}
LogPrintf(LogPHASE, "PPP Terminated (%s).\n", ex_desc(excode));
TtyOldMode();
prompt_TtyOldMode(&prompt);
link_Destroy(physical2link(SignalBundle->physical));
LogClose();
bundle_Destroy(SignalBundle);
@ -245,14 +161,16 @@ TerminalCont(int signo)
{
pending_signal(SIGCONT, SIG_DFL);
pending_signal(SIGTSTP, TerminalStop);
TtyCommandMode(SignalBundle, getpgrp() == tcgetpgrp(netfd));
prompt_TtyCommandMode(&prompt);
if (getpgrp() == prompt_pgrp(&prompt))
prompt_Display(&prompt, SignalBundle);
}
static void
TerminalStop(int signo)
{
pending_signal(SIGCONT, TerminalCont);
TtyOldMode();
prompt_TtyOldMode(&prompt);
pending_signal(SIGTSTP, SIG_DFL);
kill(getpid(), signo);
}
@ -374,17 +292,31 @@ main(int argc, char **argv)
while (--nfds > 2)
close(nfds);
VarTerm = 0;
name = strrchr(argv[0], '/');
LogOpen(name ? name + 1 : argv[0]);
tcgetattr(STDIN_FILENO, &oldtio); /* Save original tty mode */
argc--;
argv++;
label = ProcessArgs(argc, argv);
if (!(mode & MODE_DIRECT))
VarTerm = stdout;
#ifdef __FreeBSD__
/*
* A FreeBSD hack to dodge a bug in the tty driver that drops output
* occasionally.... I must find the real reason some time. To display
* the dodgy behaviour, comment out this bit, make yourself a large
* routing table and then run ppp in interactive mode. The `show route'
* command will drop chunks of data !!!
*/
if (mode & MODE_INTER) {
close(STDIN_FILENO);
if (open(_PATH_TTY, O_RDONLY) != STDIN_FILENO) {
fprintf(stderr, "Cannot open %s for input !\n", _PATH_TTY);
return 2;
}
}
#endif
prompt_Init(&prompt, (mode & MODE_DIRECT) ? PROMPT_NONE : PROMPT_STD);
ID0init();
if (ID0realuid() != 0) {
@ -427,14 +359,14 @@ main(int argc, char **argv)
SignalBundle = bundle;
if (SelectSystem(bundle, "default", CONFFILE) < 0 && VarTerm)
fprintf(VarTerm, "Warning: No default entry is given in config file.\n");
if (SelectSystem(bundle, "default", CONFFILE) < 0)
prompt_Printf(&prompt,
"Warning: No default entry is given in config file.\n");
if ((mode & MODE_OUTGOING_DAEMON) && !(mode & MODE_DEDICATED))
if (label == NULL) {
if (VarTerm)
fprintf(VarTerm, "Destination system must be specified in"
" auto, background or ddial mode.\n");
prompt_Printf(&prompt, "Destination system must be specified in"
" auto, background or ddial mode.\n");
return EX_START;
}
@ -511,13 +443,13 @@ main(int argc, char **argv)
BGPid = bgpid;
close(BGFiledes[1]);
if (read(BGFiledes[0], &c, 1) != 1) {
fprintf(VarTerm, "Child exit, no status.\n");
prompt_Printf(&prompt, "Child exit, no status.\n");
LogPrintf(LogPHASE, "Parent: Child exit, no status.\n");
} else if (c == EX_NORMAL) {
fprintf(VarTerm, "PPP enabled.\n");
prompt_Printf(&prompt, "PPP enabled.\n");
LogPrintf(LogPHASE, "Parent: PPP enabled.\n");
} else {
fprintf(VarTerm, "Child failed (%s).\n", ex_desc((int) c));
prompt_Printf(&prompt, "Child failed (%s).\n", ex_desc((int) c));
LogPrintf(LogPHASE, "Parent: Child failed (%s).\n",
ex_desc((int) c));
}
@ -528,26 +460,22 @@ main(int argc, char **argv)
close(BGFiledes[0]);
}
VarTerm = 0; /* We know it's currently stdout */
prompt_Init(&prompt, PROMPT_NONE);
close(STDOUT_FILENO);
close(STDERR_FILENO);
if (mode & MODE_DIRECT)
/* STDIN_FILENO gets used by modem_Open in DIRECT mode */
TtyInit(1);
prompt_TtyInit(&prompt, PROMPT_DONT_WANT_INT);
else if (mode & MODE_DAEMON) {
setsid();
close(STDIN_FILENO);
}
} else {
close(STDIN_FILENO);
if ((netfd = open(_PATH_TTY, O_RDONLY)) < 0) {
fprintf(stderr, "Cannot open %s for intput !\n", _PATH_TTY);
return 2;
}
close(STDERR_FILENO);
TtyInit(0);
TtyCommandMode(bundle, 1);
prompt_TtyInit(&prompt, PROMPT_WANT_INT);
prompt_TtyCommandMode(&prompt);
prompt_Display(&prompt, bundle);
}
snprintf(pid_filename, sizeof pid_filename, "%stun%d.pid",
@ -591,107 +519,8 @@ PacketMode(struct bundle *bundle, int delay)
LcpUp();
LcpOpen(delay);
if (mode & MODE_INTER)
TtyCommandMode(bundle, 0);
if (VarTerm) {
fprintf(VarTerm, "Packet mode.\n");
/* aft_cmd = 1; */
}
}
static void
ShowHelp(void)
{
fprintf(stderr, "The following commands are available:\r\n");
fprintf(stderr, " ~p\tEnter Packet mode\r\n");
fprintf(stderr, " ~-\tDecrease log level\r\n");
fprintf(stderr, " ~+\tIncrease log level\r\n");
fprintf(stderr, " ~t\tShow timers (only in \"log debug\" mode)\r\n");
fprintf(stderr, " ~m\tShow memory map (only in \"log debug\" mode)\r\n");
fprintf(stderr, " ~.\tTerminate program\r\n");
fprintf(stderr, " ~?\tThis help\r\n");
}
static void
ReadTty(struct bundle *bundle)
{
int n;
char ch;
static int ttystate;
char linebuff[LINE_LEN];
LogPrintf(LogDEBUG, "termode = %d, netfd = %d, mode = %d\n",
TermMode, netfd, mode);
if (!TermMode) {
n = read(netfd, linebuff, sizeof linebuff - 1);
if (n > 0) {
aft_cmd = 1;
if (linebuff[n-1] == '\n')
linebuff[--n] = '\0';
else
linebuff[n] = '\0';
if (n)
DecodeCommand(bundle, linebuff, n, IsInteractive(0) ? NULL : "Client");
Prompt(bundle);
} else if (n <= 0) {
LogPrintf(LogPHASE, "Client connection closed.\n");
DropClient(0);
}
return;
}
/*
* We are in terminal mode, decode special sequences
*/
n = read(netfd, &ch, 1);
LogPrintf(LogDEBUG, "Got %d bytes (reading from the terminal)\n", n);
if (n > 0) {
switch (ttystate) {
case 0:
if (ch == '~')
ttystate++;
else
/* XXX missing return value check */
Physical_Write(bundle->physical, &ch, n);
break;
case 1:
switch (ch) {
case '?':
ShowHelp();
break;
case 'p':
/*
* XXX: Should check carrier.
*/
if (LcpInfo.fsm.state <= ST_CLOSED)
PacketMode(bundle, 0);
break;
case '.':
TermMode = 1;
aft_cmd = 1;
TtyCommandMode(bundle, 1);
break;
case 't':
if (LogIsKept(LogDEBUG)) {
ShowTimers();
break;
}
case 'm':
if (LogIsKept(LogDEBUG)) {
ShowMemMap(NULL);
break;
}
default:
if (Physical_Write(bundle->physical, &ch, n) < 0)
LogPrintf(LogERROR, "error writing to modem.\n");
break;
}
ttystate = 0;
break;
}
}
prompt_TtyCommandMode(&prompt);
prompt_Printf(&prompt, "Packet mode.\n");
}
static struct pppTimer RedialTimer;
@ -748,7 +577,6 @@ DoLoop(struct bundle *bundle)
while (modem_Open(bundle->physical, bundle) < 0)
nointr_sleep(VarReconnectTimer);
}
fflush(VarTerm);
timeout.tv_sec = 0;
timeout.tv_usec = 0;
@ -862,6 +690,8 @@ DoLoop(struct bundle *bundle)
qlen = link_QueueLen(physical2link(bundle->physical));
}
/* handle_signals(); */
descriptor_UpdateSet(&bundle->physical->desc, &rfds, &wfds, &efds, &nfds);
descriptor_UpdateSet(&server.desc, &rfds, &wfds, &efds, &nfds);
@ -884,14 +714,7 @@ DoLoop(struct bundle *bundle)
FD_SET(bundle->tun_fd, &rfds);
}
if (netfd >= 0) {
if (netfd + 1 > nfds)
nfds = netfd + 1;
FD_SET(netfd, &rfds);
FD_SET(netfd, &efds);
}
handle_signals();
descriptor_UpdateSet(&prompt.desc, &rfds, &wfds, &efds, &nfds);
#ifndef SIGALRM
@ -926,7 +749,7 @@ DoLoop(struct bundle *bundle)
break;
}
if ((netfd >= 0 && FD_ISSET(netfd, &efds)) ||
if (descriptor_IsSet(&prompt.desc, &efds) ||
descriptor_IsSet(&bundle->physical->desc, &efds)) {
LogPrintf(LogALERT, "Exception detected.\n");
break;
@ -935,9 +758,8 @@ DoLoop(struct bundle *bundle)
if (descriptor_IsSet(&server.desc, &rfds))
descriptor_Read(&server.desc, bundle, &rfds);
if (netfd >= 0 && FD_ISSET(netfd, &rfds))
/* something to read from tty */
ReadTty(bundle);
if (descriptor_IsSet(&prompt.desc, &rfds))
descriptor_Read(&prompt.desc, bundle, &rfds);
if (descriptor_IsSet(&bundle->physical->desc, &wfds)) {
/* ready to write into modem */

View File

@ -17,11 +17,10 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.h,v 1.9.2.2 1998/02/07 20:49:55 brian Exp $
* $Id: main.h,v 1.9.2.3 1998/02/08 11:07:32 brian Exp $
*
*/
extern int TermMode;
extern int CleaningUp;
extern void Cleanup(int);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: mbuf.c,v 1.13.2.2 1998/02/06 02:23:40 brian Exp $
* $Id: mbuf.c,v 1.13.2.3 1998/02/09 19:24:01 brian Exp $
*
*/
#include <sys/param.h>
@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include "command.h"
#include "mbuf.h"
@ -33,6 +34,8 @@
#include "defs.h"
#include "loadalias.h"
#include "vars.h"
#include "descriptor.h"
#include "prompt.h"
static struct memmap {
struct mbuf *queue;
@ -153,11 +156,8 @@ ShowMemMap(struct cmdargs const *arg)
{
int i;
if (!VarTerm)
return 1;
for (i = 0; i <= MB_MAX; i += 2)
fprintf(VarTerm, "%d: %d %d: %d\n",
prompt_Printf(&prompt, "%d: %d %d: %d\n",
i, MemMap[i].count, i + 1, MemMap[i + 1].count);
return 0;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.c,v 1.77.2.12 1998/02/09 19:21:03 brian Exp $
* $Id: modem.c,v 1.77.2.13 1998/02/10 03:22:00 brian Exp $
*
* TODO:
*/
@ -61,13 +61,10 @@
#include "throughput.h"
#include "async.h"
#include "bundle.h"
#undef mode
/* We're defining a physical device, and thus need the real headers. */
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "prompt.h"
#ifndef O_NONBLOCK
@ -745,10 +742,8 @@ modem_Hangup(struct link *l, int dedicated_force)
StopTimer(&modem->link.Timer);
throughput_stop(&modem->link.throughput);
if (TermMode) {
LogPrintf(LogDEBUG, "modem_Hangup: Not in 'term' mode\n");
return;
}
if (prompt_IsTermMode(&prompt))
prompt_TtyCommandMode(&prompt);
if (!isatty(modem->fd)) {
modem->mbits &= ~TIOCM_DTR;
@ -881,15 +876,13 @@ modem_Dial(struct physical *modem, struct bundle *bundle)
strncpy(ScriptBuffer, VarDialScript, sizeof ScriptBuffer - 1);
ScriptBuffer[sizeof ScriptBuffer - 1] = '\0';
if ((excode = DoChat(modem, ScriptBuffer)) > 0) {
if (VarTerm)
fprintf(VarTerm, "dial OK!\n");
prompt_Printf(&prompt, "dial OK!\n");
strncpy(ScriptBuffer, VarLoginScript, sizeof ScriptBuffer - 1);
if ((excode = DoChat(modem, ScriptBuffer)) > 0) {
struct timeoutArg to;
VarAltPhone = NULL;
if (VarTerm)
fprintf(VarTerm, "login OK!\n");
prompt_Printf(&prompt, "login OK!\n");
to.modem = modem;
to.bundle = bundle;
modem_Timeout(&to);
@ -920,52 +913,49 @@ modem_ShowStatus(struct cmdargs const *arg)
int nb;
#endif
if (!VarTerm)
return 1;
dev = *VarDevice ? VarDevice : "network";
fprintf(VarTerm, "device: %s speed: ", dev);
prompt_Printf(&prompt, "device: %s speed: ", dev);
if (Physical_IsSync(modem))
fprintf(VarTerm, "sync\n");
prompt_Printf(&prompt, "sync\n");
else
fprintf(VarTerm, "%d\n", modem->speed);
prompt_Printf(&prompt, "%d\n", modem->speed);
switch (modem->parity & CSIZE) {
case CS7:
fprintf(VarTerm, "cs7, ");
prompt_Printf(&prompt, "cs7, ");
break;
case CS8:
fprintf(VarTerm, "cs8, ");
prompt_Printf(&prompt, "cs8, ");
break;
}
if (modem->parity & PARENB) {
if (modem->parity & PARODD)
fprintf(VarTerm, "odd parity, ");
prompt_Printf(&prompt, "odd parity, ");
else
fprintf(VarTerm, "even parity, ");
prompt_Printf(&prompt, "even parity, ");
} else
fprintf(VarTerm, "no parity, ");
prompt_Printf(&prompt, "no parity, ");
fprintf(VarTerm, "CTS/RTS %s.\n", (modem->rts_cts ? "on" : "off"));
prompt_Printf(&prompt, "CTS/RTS %s.\n", (modem->rts_cts ? "on" : "off"));
if (LogIsKept(LogDEBUG))
fprintf(VarTerm, "fd = %d, modem control = %o\n", modem->fd, modem->mbits);
fprintf(VarTerm, "connect count: %d\n", modem->connect_count);
prompt_Printf(&prompt, "fd = %d, modem control = %o\n", modem->fd, modem->mbits);
prompt_Printf(&prompt, "connect count: %d\n", modem->connect_count);
#ifdef TIOCOUTQ
if (modem->fd >= 0)
if (ioctl(modem->fd, TIOCOUTQ, &nb) >= 0)
fprintf(VarTerm, "outq: %d\n", nb);
prompt_Printf(&prompt, "outq: %d\n", nb);
else
fprintf(VarTerm, "outq: ioctl probe failed: %s\n", strerror(errno));
prompt_Printf(&prompt, "outq: ioctl probe failed: %s\n", strerror(errno));
#endif
fprintf(VarTerm, "outqlen: %d\n", link_QueueLen(&modem->link));
fprintf(VarTerm, "DialScript = %s\n", VarDialScript);
fprintf(VarTerm, "LoginScript = %s\n", VarLoginScript);
fprintf(VarTerm, "PhoneNumber(s) = %s\n", VarPhoneList);
prompt_Printf(&prompt, "outqlen: %d\n", link_QueueLen(&modem->link));
prompt_Printf(&prompt, "DialScript = %s\n", VarDialScript);
prompt_Printf(&prompt, "LoginScript = %s\n", VarLoginScript);
prompt_Printf(&prompt, "PhoneNumber(s) = %s\n", VarPhoneList);
fprintf(VarTerm, "\n");
throughput_disp(&modem->link.throughput, VarTerm);
prompt_Printf(&prompt, "\n");
throughput_disp(&modem->link.throughput);
return 0;
}
@ -1019,8 +1009,8 @@ modem_DescriptorRead(struct descriptor *d, struct bundle *bundle,
Physical_Write(p, "\r\n", 2);
}
PacketMode(bundle, 0);
} else if (VarTerm)
write(fileno(VarTerm), rbuff, n);
} else
prompt_Printf(&prompt, "%.*s", n, rbuff);
}
} else if (n > 0)
async_Input(bundle, rbuff, n, p);

383
usr.sbin/ppp/prompt.c Normal file
View File

@ -0,0 +1,383 @@
/*-
* Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <termios.h>
#include <unistd.h>
#include "defs.h"
#include "timer.h"
#include "command.h"
#include "log.h"
#include "bundle.h"
#include "descriptor.h"
#include "prompt.h"
#include "fsm.h"
#include "lcp.h"
#include "auth.h"
#include "loadalias.h"
#include "vars.h"
#include "main.h"
#include "iplist.h"
#include "throughput.h"
#include "ipcp.h"
static int prompt_nonewline = 1;
static int
prompt_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
{
struct prompt *p = descriptor2prompt(d);
LogPrintf(LogDEBUG, "descriptor2prompt; %p -> %p\n", d, p);
if (p->fd_in >= 0) {
if (*n < p->fd_in + 1)
*n = p->fd_in + 1;
FD_SET(p->fd_in, r);
FD_SET(p->fd_in, e);
return 2;
}
return 0;
}
static int
prompt_IsSet(struct descriptor *d, fd_set *fdset)
{
struct prompt *p = descriptor2prompt(d);
LogPrintf(LogDEBUG, "descriptor2prompt; %p -> %p\n", d, p);
return p->fd_in >= 0 && FD_ISSET(p->fd_in, fdset);
}
static void
prompt_ShowHelp(struct prompt *p)
{
prompt_Printf(p, "The following commands are available:\r\n");
prompt_Printf(p, " ~p\tEnter Packet mode\r\n");
prompt_Printf(p, " ~-\tDecrease log level\r\n");
prompt_Printf(p, " ~+\tIncrease log level\r\n");
prompt_Printf(p, " ~t\tShow timers (only in \"log debug\" mode)\r\n");
prompt_Printf(p, " ~m\tShow memory map (only in \"log debug\" mode)\r\n");
prompt_Printf(p, " ~.\tTerminate program\r\n");
prompt_Printf(p, " ~?\tThis help\r\n");
}
static void
prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
{
struct prompt *p = descriptor2prompt(d);
int n;
char ch;
static int ttystate;
char linebuff[LINE_LEN];
LogPrintf(LogDEBUG, "descriptor2prompt; %p -> %p\n", d, p);
LogPrintf(LogDEBUG, "termode = %d, p->fd_in = %d, mode = %d\n",
p->TermMode, p->fd_in, mode);
if (!p->TermMode) {
n = read(p->fd_in, linebuff, sizeof linebuff - 1);
if (n > 0) {
if (linebuff[n-1] == '\n')
linebuff[--n] = '\0';
else
linebuff[n] = '\0';
if (n)
DecodeCommand(bundle, linebuff, n, IsInteractive(0) ? NULL : "Client");
prompt_nonewline = 1;
prompt_Display(&prompt, bundle);
} else if (n <= 0) {
LogPrintf(LogPHASE, "Client connection closed.\n");
prompt_Drop(&prompt, 0);
}
return;
}
/*
* We are in terminal mode, decode special sequences
*/
n = read(p->fd_in, &ch, 1);
LogPrintf(LogDEBUG, "Got %d bytes (reading from the terminal)\n", n);
if (n > 0) {
switch (ttystate) {
case 0:
if (ch == '~')
ttystate++;
else
/* XXX missing return value check */
Physical_Write(bundle->physical, &ch, n);
break;
case 1:
switch (ch) {
case '?':
prompt_ShowHelp(p);
break;
case 'p':
/*
* XXX: Should check carrier.
*/
if (LcpInfo.fsm.state <= ST_CLOSED)
PacketMode(bundle, 0);
break;
case '.':
p->TermMode = 1;
prompt_TtyCommandMode(&prompt);
prompt_nonewline = 0;
prompt_Display(&prompt, bundle);
break;
case 't':
if (LogIsKept(LogDEBUG)) {
ShowTimers();
break;
}
case 'm':
if (LogIsKept(LogDEBUG)) {
ShowMemMap(NULL);
break;
}
default:
if (Physical_Write(bundle->physical, &ch, n) < 0)
LogPrintf(LogERROR, "error writing to modem.\n");
break;
}
ttystate = 0;
break;
}
}
}
static void
prompt_Write(struct descriptor *d, const fd_set *fdset)
{
/* We don't set the write descriptor (yet) */
}
struct prompt prompt = {
{
PROMPT_DESCRIPTOR,
NULL,
prompt_UpdateSet,
prompt_IsSet,
prompt_Read,
prompt_Write
},
-1,
-1,
NULL
};
int
prompt_Init(struct prompt *p, int fd)
{
if (p->Term && p->Term != stdout)
return 0; /* must prompt_Drop() first */
if (fd == PROMPT_NONE) {
p->fd_in = p->fd_out = -1;
p->Term = NULL;
} else if (fd == PROMPT_STD) {
p->fd_in = STDIN_FILENO;
p->fd_out = STDOUT_FILENO;
p->Term = stdout;
} else {
p->fd_in = p->fd_out = fd;
p->Term = fdopen(fd, "a+");
}
p->TermMode = 0;
tcgetattr(STDIN_FILENO, &p->oldtio); /* Save original tty mode */
return 1;
}
int
prompt_Display(struct prompt *p, struct bundle *bundle)
{
const char *pconnect, *pauth;
if (!p->Term || p->TermMode || CleaningUp)
return;
if (prompt_nonewline)
prompt_nonewline = 0;
else
fprintf(p->Term, "\n");
if (VarLocalAuth == LOCAL_AUTH)
pauth = " ON ";
else
pauth = " on ";
if (IpcpInfo.fsm.state == ST_OPENED)
pconnect = "PPP";
else if (bundle_Phase(bundle) == PHASE_NETWORK)
pconnect = "PPp";
else if (bundle_Phase(bundle) == PHASE_AUTHENTICATE)
pconnect = "Ppp";
else
pconnect = "ppp";
fprintf(p->Term, "%s%s%s> ", pconnect, pauth, VarShortHost);
fflush(p->Term);
}
void
prompt_Drop(struct prompt *p, int verbose)
{
if (p->Term && p->Term != stdout) {
FILE *oVarTerm;
oVarTerm = p->Term;
p->Term = NULL;
if (oVarTerm)
fclose(oVarTerm);
close(p->fd_in);
if (p->fd_out != p->fd_in)
close(p->fd_out);
p->fd_in = p->fd_out = -1;
if (verbose)
LogPrintf(LogPHASE, "Client connection dropped.\n");
}
}
void
prompt_Printf(struct prompt *p, const char *fmt,...)
{
if (p->Term) {
va_list ap;
va_start(ap, fmt);
vfprintf(p->Term, fmt, ap);
fflush(p->Term);
va_end(ap);
}
}
void
prompt_vPrintf(struct prompt *p, const char *fmt, va_list ap)
{
if (p->Term) {
vfprintf(p->Term, fmt, ap);
fflush(p->Term);
}
}
void
prompt_TtyInit(struct prompt *p, int DontWantInt)
{
struct termios newtio;
int stat;
stat = fcntl(p->fd_in, F_GETFL, 0);
if (stat > 0) {
stat |= O_NONBLOCK;
(void) fcntl(p->fd_in, F_SETFL, stat);
}
newtio = p->oldtio;
newtio.c_lflag &= ~(ECHO | ISIG | ICANON);
newtio.c_iflag = 0;
newtio.c_oflag &= ~OPOST;
newtio.c_cc[VEOF] = _POSIX_VDISABLE;
if (DontWantInt)
newtio.c_cc[VINTR] = _POSIX_VDISABLE;
newtio.c_cc[VMIN] = 1;
newtio.c_cc[VTIME] = 0;
newtio.c_cflag |= CS8;
tcsetattr(p->fd_in, TCSANOW, &newtio);
p->comtio = newtio;
}
/*
* Set tty into command mode. We allow canonical input and echo processing.
*/
void
prompt_TtyCommandMode(struct prompt *p)
{
struct termios newtio;
int stat;
if (!(mode & MODE_INTER))
return;
tcgetattr(p->fd_in, &newtio);
newtio.c_lflag |= (ECHO | ISIG | ICANON);
newtio.c_iflag = p->oldtio.c_iflag;
newtio.c_oflag |= OPOST;
tcsetattr(p->fd_in, TCSADRAIN, &newtio);
stat = fcntl(p->fd_in, F_GETFL, 0);
if (stat > 0) {
stat |= O_NONBLOCK;
(void) fcntl(p->fd_in, F_SETFL, stat);
}
p->TermMode = 0;
}
/*
* Set tty into terminal mode which is used while we invoke term command.
*/
void
prompt_TtyTermMode(struct prompt *p)
{
int stat;
tcsetattr(p->fd_in, TCSADRAIN, &p->comtio);
stat = fcntl(p->fd_in, F_GETFL, 0);
if (stat > 0) {
stat &= ~O_NONBLOCK;
(void) fcntl(p->fd_in, F_SETFL, stat);
}
p->TermMode = 1;
}
void
prompt_TtyOldMode(struct prompt *p)
{
int stat;
stat = fcntl(p->fd_in, F_GETFL, 0);
if (stat > 0) {
stat &= ~O_NONBLOCK;
(void) fcntl(p->fd_in, F_SETFL, stat);
}
tcsetattr(p->fd_in, TCSADRAIN, &p->oldtio);
}
pid_t
prompt_pgrp(struct prompt *p)
{
return p->Term ? tcgetpgrp(p->fd_in) : -1;
}

60
usr.sbin/ppp/prompt.h Normal file
View File

@ -0,0 +1,60 @@
/*-
* Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*/
struct prompt {
struct descriptor desc;
int fd_in, fd_out;
int TermMode;
FILE *Term; /* sits on top of fd_out */
struct termios oldtio; /* Original tty mode */
struct termios comtio; /* Command level tty mode */
};
#define prompt2descriptor(p) (&(p)->desc)
#define descriptor2prompt(d) \
((d)->type == PROMPT_DESCRIPTOR ? (struct prompt *)(d) : NULL)
extern struct prompt prompt;
#define prompt_Active(p) ((p)->Term ? 1 : 0)
#define PROMPT_NONE -2
#define PROMPT_STD -1
extern int prompt_Init(struct prompt *, int);
extern int prompt_Display(struct prompt *, struct bundle *);
extern void prompt_Drop(struct prompt *, int);
extern void prompt_Printf(struct prompt *, const char *, ...);
extern void prompt_vPrintf(struct prompt *, const char *, _BSD_VA_LIST_);
#define PROMPT_DONT_WANT_INT 1
#define PROMPT_WANT_INT 0
extern void prompt_TtyInit(struct prompt *, int);
extern void prompt_TtyCommandMode(struct prompt *);
extern void prompt_TtyTermMode(struct prompt *);
extern void prompt_TtyOldMode(struct prompt *);
extern pid_t prompt_pgrp(struct prompt *);
#define prompt_IsTermMode(p) ((p)->TermMode ? 1 : 0)

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: route.c,v 1.42.2.5 1998/02/02 19:33:01 brian Exp $
* $Id: route.c,v 1.42.2.6 1998/02/07 20:50:06 brian Exp $
*
*/
@ -38,6 +38,7 @@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/sysctl.h>
#include <termios.h>
#include <unistd.h>
#include "command.h"
@ -56,6 +57,8 @@
#include "fsm.h"
#include "ipcp.h"
#include "route.h"
#include "descriptor.h"
#include "prompt.h"
static void
p_sockaddr(struct sockaddr *phost, struct sockaddr *pmask, int width)
@ -129,7 +132,7 @@ p_sockaddr(struct sockaddr *phost, struct sockaddr *pmask, int width)
break;
}
fprintf(VarTerm, "%-*s ", width-1, buf);
prompt_Printf(&prompt, "%-*s ", width-1, buf);
}
static struct bits {
@ -172,19 +175,17 @@ static struct bits {
static void
p_flags(u_long f, int max)
{
if (VarTerm) {
char name[33], *flags;
register struct bits *p = bits;
char name[33], *flags;
register struct bits *p = bits;
if (max > sizeof name - 1)
max = sizeof name - 1;
if (max > sizeof name - 1)
max = sizeof name - 1;
for (flags = name; p->b_mask && flags - name < max; p++)
if (p->b_mask & f)
*flags++ = p->b_val;
*flags = '\0';
fprintf(VarTerm, "%-*.*s", max, max, name);
}
for (flags = name; p->b_mask && flags - name < max; p++)
if (p->b_mask & f)
*flags++ = p->b_val;
*flags = '\0';
prompt_Printf(&prompt, "%-*.*s", max, max, name);
}
const char *
@ -277,9 +278,6 @@ ShowRoute(struct cmdargs const *arg)
size_t needed;
int mib[6];
if (!VarTerm)
return 1;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0;
@ -302,7 +300,7 @@ ShowRoute(struct cmdargs const *arg)
}
ep = sp + needed;
fprintf(VarTerm, "%-20s%-20sFlags Netif\n", "Destination", "Gateway");
prompt_Printf(&prompt, "%-20s%-20sFlags Netif\n", "Destination", "Gateway");
for (cp = sp; cp < ep; cp += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *) cp;
wp = (char *)(rtm+1);
@ -329,7 +327,7 @@ ShowRoute(struct cmdargs const *arg)
p_sockaddr(sa_gw, NULL, 20);
p_flags(rtm->rtm_flags, 6);
fprintf(VarTerm, " %s\n", Index2Nam(rtm->rtm_index));
prompt_Printf(&prompt, " %s\n", Index2Nam(rtm->rtm_index));
}
free(sp);
return 0;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: server.c,v 1.16.2.2 1998/02/09 19:24:02 brian Exp $
* $Id: server.c,v 1.16.2.3 1998/02/10 03:22:05 brian Exp $
*/
#include <sys/param.h>
@ -37,6 +37,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <termios.h>
#include <unistd.h>
#include "command.h"
@ -48,6 +49,7 @@
#include "descriptor.h"
#include "server.h"
#include "id.h"
#include "prompt.h"
static int
server_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
@ -56,9 +58,9 @@ server_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
LogPrintf(LogDEBUG, "descriptor2server; %p -> %p\n", d, s);
if (s->fd >= 0) {
FD_SET(s->fd, r);
if (*n < s->fd + 1)
*n = s->fd + 1;
FD_SET(s->fd, r);
return 1;
}
return 0;
@ -117,15 +119,13 @@ server_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
return;
}
if (netfd >= 0) {
if (!prompt_Init(&prompt, wfd)) {
write(wfd, "Connection already in use.\n", 27);
close(wfd);
} else {
netfd = wfd;
VarTerm = fdopen(netfd, "a+");
LocalAuthInit();
IsInteractive(1);
Prompt(bundle);
prompt_Display(&prompt, bundle);
}
}
@ -188,8 +188,8 @@ ServerLocalOpen(const char *name, mode_t mask)
if (mask != (mode_t)-1)
umask(mask);
LogPrintf(LogERROR, "Local: bind: %s\n", strerror(errno));
if (errno == EADDRINUSE && VarTerm)
fprintf(VarTerm, "Wait for a while, then try again.\n");
if (errno == EADDRINUSE)
prompt_Printf(&prompt, "Wait for a while, then try again.\n");
close(s);
return 4;
}
@ -237,8 +237,8 @@ ServerTcpOpen(int port)
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &s, sizeof s);
if (bind(s, (struct sockaddr *)&ifsin, sizeof ifsin) < 0) {
LogPrintf(LogERROR, "Tcp: bind: %s\n", strerror(errno));
if (errno == EADDRINUSE && VarTerm)
fprintf(VarTerm, "Wait for a while, then try again.\n");
if (errno == EADDRINUSE)
prompt_Printf(&prompt, "Wait for a while, then try again.\n");
close(s);
return 8;
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: slcompress.c,v 1.15 1997/12/24 09:29:17 brian Exp $
* $Id: slcompress.c,v 1.15.2.1 1998/01/29 23:11:43 brian Exp $
*
* Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
* - Initial distribution.
@ -31,6 +31,7 @@
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include "command.h"
#include "mbuf.h"
@ -39,6 +40,8 @@
#include "slcompress.h"
#include "loadalias.h"
#include "vars.h"
#include "descriptor.h"
#include "prompt.h"
static struct slstat {
int sls_packets; /* outbound packets */
@ -572,16 +575,13 @@ bad:
int
ReportCompress(struct cmdargs const *arg)
{
if (!VarTerm)
return 1;
fprintf(VarTerm, "Out: %d (compress) / %d (total)",
slstat.sls_compressed, slstat.sls_packets);
fprintf(VarTerm, " %d (miss) / %d (search)\n",
slstat.sls_misses, slstat.sls_searches);
fprintf(VarTerm, "In: %d (compress), %d (uncompress)",
slstat.sls_compressedin, slstat.sls_uncompressedin);
fprintf(VarTerm, " %d (error), %d (tossed)\n",
slstat.sls_errorin, slstat.sls_tossed);
prompt_Printf(&prompt, "Out: %d (compress) / %d (total)",
slstat.sls_compressed, slstat.sls_packets);
prompt_Printf(&prompt, " %d (miss) / %d (search)\n",
slstat.sls_misses, slstat.sls_searches);
prompt_Printf(&prompt, "In: %d (compress), %d (uncompress)",
slstat.sls_compressedin, slstat.sls_uncompressedin);
prompt_Printf(&prompt, " %d (error), %d (tossed)\n",
slstat.sls_errorin, slstat.sls_tossed);
return 0;
}

View File

@ -23,14 +23,15 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
* $Id: throughput.c,v 1.4 1997/12/21 12:11:09 brian Exp $
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <stdio.h>
#include <termios.h>
#include <time.h>
#include <netinet/in.h>
#include "command.h"
#include "mbuf.h"
@ -40,6 +41,8 @@
#include "defs.h"
#include "loadalias.h"
#include "vars.h"
#include "descriptor.h"
#include "prompt.h"
void
throughput_init(struct pppThroughput *t)
@ -54,22 +57,25 @@ throughput_init(struct pppThroughput *t)
}
void
throughput_disp(struct pppThroughput *t, FILE *f)
throughput_disp(struct pppThroughput *t)
{
int secs_up;
secs_up = t->uptime ? time(NULL) - t->uptime : 0;
fprintf(f, "Connect time: %d secs\n", secs_up);
prompt_Printf(&prompt, "Connect time: %d secs\n", secs_up);
if (secs_up == 0)
secs_up = 1;
fprintf(f, "%ld octets in, %ld octets out\n", t->OctetsIn, t->OctetsOut);
prompt_Printf(&prompt, "%ld octets in, %ld octets out\n",
t->OctetsIn, t->OctetsOut);
if (Enabled(ConfThroughput)) {
fprintf(f, " overall %5ld bytes/sec\n",
(t->OctetsIn+t->OctetsOut)/secs_up);
fprintf(f, " currently %5d bytes/sec\n", t->OctetsPerSecond);
fprintf(f, " peak %5d bytes/sec\n", t->BestOctetsPerSecond);
prompt_Printf(&prompt, " overall %5ld bytes/sec\n",
(t->OctetsIn+t->OctetsOut)/secs_up);
prompt_Printf(&prompt, " currently %5d bytes/sec\n", t->OctetsPerSecond);
prompt_Printf(&prompt, " peak %5d bytes/sec\n",
t->BestOctetsPerSecond);
} else
fprintf(f, "Overall %ld bytes/sec\n", (t->OctetsIn+t->OctetsOut)/secs_up);
prompt_Printf(&prompt, "Overall %ld bytes/sec\n",
(t->OctetsIn+t->OctetsOut)/secs_up);
}

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
* $Id: throughput.h,v 1.2 1997/12/21 12:11:09 brian Exp $
*/
#define SAMPLE_PERIOD 5
@ -40,7 +40,7 @@ struct pppThroughput {
};
extern void throughput_init(struct pppThroughput *);
extern void throughput_disp(struct pppThroughput *, FILE *);
extern void throughput_disp(struct pppThroughput *);
extern void throughput_log(struct pppThroughput *, int, const char *);
extern void throughput_start(struct pppThroughput *);
extern void throughput_stop(struct pppThroughput *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: vars.c,v 1.45.2.4 1998/02/06 02:22:52 brian Exp $
* $Id: vars.c,v 1.45.2.5 1998/02/09 19:21:11 brian Exp $
*
*/
#include <sys/param.h>
@ -43,9 +43,10 @@
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "prompt.h"
char VarVersion[] = "PPP Version 1.90";
char VarLocalVersion[] = "$Date: 1998/02/06 02:22:52 $";
char VarLocalVersion[] = "$Date: 1998/02/09 19:21:11 $";
int Utmp = 0;
int ipKeepAlive = 0;
int reconnectState = RECON_UNKNOWN;
@ -84,18 +85,15 @@ DisplayCommand(struct cmdargs const *arg)
{
struct confdesc *vp;
if (!VarTerm)
return 1;
fprintf(VarTerm, "Current configuration option settings..\n\n");
fprintf(VarTerm, "Name\t\tMy Side\t\tHis Side\n");
fprintf(VarTerm, "----------------------------------------\n");
prompt_Printf(&prompt, "Current configuration option settings..\n\n");
prompt_Printf(&prompt, "Name\t\tMy Side\t\tHis Side\n");
prompt_Printf(&prompt, "----------------------------------------\n");
for (vp = pppConfs; vp->name; vp++)
fprintf(VarTerm, "%-10s\t%s\t\t%s\n", vp->name,
(vp->myside == CONF_ENABLE) ? "enable" :
(vp->myside == CONF_DISABLE ? "disable" : "N/A"),
(vp->hisside == CONF_ACCEPT) ? "accept" :
(vp->hisside == CONF_DENY ? "deny" : "N/A"));
prompt_Printf(&prompt, "%-10s\t%s\t\t%s\n", vp->name,
(vp->myside == CONF_ENABLE) ? "enable" :
(vp->myside == CONF_DISABLE ? "disable" : "N/A"),
(vp->hisside == CONF_ACCEPT) ? "accept" :
(vp->hisside == CONF_DENY ? "deny" : "N/A"));
return 0;
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: vars.h,v 1.42.2.1 1998/01/29 00:49:31 brian Exp $
* $Id: vars.h,v 1.42.2.2 1998/02/06 02:23:48 brian Exp $
*
* TODO:
*/
@ -78,7 +78,6 @@ struct pppvars {
#define LOCAL_NO_AUTH 0x02
#define LOCAL_DENY 0x03
u_char lauth; /* Local Authorized status */
FILE *termfp; /* The terminal */
/* The rest are just default initialized in vars.c */
#define DIALUP_REQ 0x01
@ -138,7 +137,6 @@ struct pppvars {
#define VarRedialNextTimeout pppVars.redial_next_timeout
#define VarDialTries pppVars.dial_tries
#define VarLoopback pppVars.loopback
#define VarTerm pppVars.termfp
#define VarAliasHandlers pppVars.handler
#define VarPacketAliasGetFragment (*pppVars.handler.PacketAliasGetFragment)