Deleted Added
full compact
main.c (25445) main.c (25630)
1/*
2 * User Process PPP
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * User Process PPP
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: main.c,v 1.45 1997/04/21 01:01:48 brian Exp $
20 * $Id: main.c,v 1.46 1997/05/04 02:39:03 ache Exp $
21 *
22 * TODO:
23 * o Add commands for traffic summary, version display, etc.
24 * o Add signal handler for misc controls.
25 */
26#include "fsm.h"
27#include <fcntl.h>
28#include <paths.h>

--- 27 unchanged lines hidden (view full) ---

56
57#ifndef O_NONBLOCK
58#ifdef O_NDELAY
59#define O_NONBLOCK O_NDELAY
60#endif
61#endif
62
63extern void VjInit(), AsyncInit();
21 *
22 * TODO:
23 * o Add commands for traffic summary, version display, etc.
24 * o Add signal handler for misc controls.
25 */
26#include "fsm.h"
27#include <fcntl.h>
28#include <paths.h>

--- 27 unchanged lines hidden (view full) ---

56
57#ifndef O_NONBLOCK
58#ifdef O_NDELAY
59#define O_NONBLOCK O_NDELAY
60#endif
61#endif
62
63extern void VjInit(), AsyncInit();
64extern void AsyncInput(), IpOutput();
64extern void AsyncInput();
65extern int SelectSystem();
66
67extern void DecodeCommand(), Prompt();
68extern int aft_cmd;
69extern int IsInteractive();
65extern int SelectSystem();
66
67extern void DecodeCommand(), Prompt();
68extern int aft_cmd;
69extern int IsInteractive();
70extern struct in_addr ifnetmask;
71static void DoLoop(void);
72static void TerminalStop();
73
74static struct termios oldtio; /* Original tty mode */
75static struct termios comtio; /* Command level tty mode */
76int TermMode;
77static int server;
78static pid_t BGPid = 0;
79struct sockaddr_in ifsin;
80char pid_filename[128];
81int tunno;
82
83static void
84TtyInit()
85{
86 struct termios newtio;
87 int stat;
88
89 stat = fcntl(0, F_GETFL, 0);
70static void DoLoop(void);
71static void TerminalStop();
72
73static struct termios oldtio; /* Original tty mode */
74static struct termios comtio; /* Command level tty mode */
75int TermMode;
76static int server;
77static pid_t BGPid = 0;
78struct sockaddr_in ifsin;
79char pid_filename[128];
80int tunno;
81
82static void
83TtyInit()
84{
85 struct termios newtio;
86 int stat;
87
88 stat = fcntl(0, F_GETFL, 0);
90 stat |= O_NONBLOCK;
91 fcntl(0, F_SETFL, stat);
89 if (stat > 0) {
90 stat |= O_NONBLOCK;
91 (void)fcntl(0, F_SETFL, stat);
92 }
92 newtio = oldtio;
93 newtio.c_lflag &= ~(ECHO|ISIG|ICANON);
94 newtio.c_iflag = 0;
95 newtio.c_oflag &= ~OPOST;
96 newtio.c_cc[VEOF] = _POSIX_VDISABLE;
97 newtio.c_cc[VINTR] = _POSIX_VDISABLE;
98 newtio.c_cc[VMIN] = 1;
99 newtio.c_cc[VTIME] = 0;

--- 15 unchanged lines hidden (view full) ---

115 if (!(mode & MODE_INTER))
116 return;
117 tcgetattr(0, &newtio);
118 newtio.c_lflag |= (ECHO|ISIG|ICANON);
119 newtio.c_iflag = oldtio.c_iflag;
120 newtio.c_oflag |= OPOST;
121 tcsetattr(0, TCSADRAIN, &newtio);
122 stat = fcntl(0, F_GETFL, 0);
93 newtio = oldtio;
94 newtio.c_lflag &= ~(ECHO|ISIG|ICANON);
95 newtio.c_iflag = 0;
96 newtio.c_oflag &= ~OPOST;
97 newtio.c_cc[VEOF] = _POSIX_VDISABLE;
98 newtio.c_cc[VINTR] = _POSIX_VDISABLE;
99 newtio.c_cc[VMIN] = 1;
100 newtio.c_cc[VTIME] = 0;

--- 15 unchanged lines hidden (view full) ---

116 if (!(mode & MODE_INTER))
117 return;
118 tcgetattr(0, &newtio);
119 newtio.c_lflag |= (ECHO|ISIG|ICANON);
120 newtio.c_iflag = oldtio.c_iflag;
121 newtio.c_oflag |= OPOST;
122 tcsetattr(0, TCSADRAIN, &newtio);
123 stat = fcntl(0, F_GETFL, 0);
123 stat |= O_NONBLOCK;
124 fcntl(0, F_SETFL, stat);
124 if (stat > 0) {
125 stat |= O_NONBLOCK;
126 (void)fcntl(0, F_SETFL, stat);
127 }
125 TermMode = 0;
128 TermMode = 0;
126 if(prompt) Prompt(0);
129 if(prompt) Prompt();
127}
128
129/*
130 * Set tty into terminal mode which is used while we invoke term command.
131 */
132void
133TtyTermMode()
134{
135 int stat;
136
137 tcsetattr(0, TCSADRAIN, &comtio);
138 stat = fcntl(0, F_GETFL, 0);
130}
131
132/*
133 * Set tty into terminal mode which is used while we invoke term command.
134 */
135void
136TtyTermMode()
137{
138 int stat;
139
140 tcsetattr(0, TCSADRAIN, &comtio);
141 stat = fcntl(0, F_GETFL, 0);
139 stat &= ~O_NONBLOCK;
140 fcntl(0, F_SETFL, stat);
142 if (stat > 0) {
143 stat &= ~O_NONBLOCK;
144 (void)fcntl(0, F_SETFL, stat);
145 }
141 TermMode = 1;
142}
143
144void
145TtyOldMode()
146{
147 int stat;
148
149 stat = fcntl(0, F_GETFL, 0);
146 TermMode = 1;
147}
148
149void
150TtyOldMode()
151{
152 int stat;
153
154 stat = fcntl(0, F_GETFL, 0);
150 stat &= ~O_NONBLOCK;
151 fcntl(0, F_SETFL, stat);
155 if (stat > 0) {
156 stat &= ~O_NONBLOCK;
157 (void)fcntl(0, F_SETFL, stat);
158 }
152 tcsetattr(0, TCSANOW, &oldtio);
153}
154
155void
156Cleanup(excode)
157int excode;
158{
159

--- 225 unchanged lines hidden (view full) ---

385 if ((mode & MODE_AUTO) && DefHisAddress.ipaddr.s_addr == INADDR_ANY) {
386 fprintf(stderr, "Must specify dstaddr with auto or ddial mode.\n");
387 Cleanup(EX_START);
388 }
389 }
390 if (mode & MODE_DIRECT)
391 printf("Packet mode enabled.\n");
392
159 tcsetattr(0, TCSANOW, &oldtio);
160}
161
162void
163Cleanup(excode)
164int excode;
165{
166

--- 225 unchanged lines hidden (view full) ---

392 if ((mode & MODE_AUTO) && DefHisAddress.ipaddr.s_addr == INADDR_ANY) {
393 fprintf(stderr, "Must specify dstaddr with auto or ddial mode.\n");
394 Cleanup(EX_START);
395 }
396 }
397 if (mode & MODE_DIRECT)
398 printf("Packet mode enabled.\n");
399
393#ifdef notdef
394 if (mode & MODE_AUTO) {
395 OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask);
396 }
397#endif
398
399 if (!(mode & MODE_INTER)) {
400 int port = SERVER_PORT + tunno;
401 if (mode & MODE_BACKGROUND) {
402 if (pipe (BGFiledes)) {
403 perror("pipe");
404 Cleanup(EX_SOCK);
405 }
406 }

--- 10 unchanged lines hidden (view full) ---

417 ifsin.sin_addr.s_addr = INADDR_ANY;
418 ifsin.sin_port = htons(port);
419 if (bind(server, (struct sockaddr *) &ifsin, sizeof(ifsin)) < 0) {
420 perror("bind");
421 if (errno == EADDRINUSE)
422 fprintf(stderr, "Wait for a while, then try again.\n");
423 Cleanup(EX_SOCK);
424 }
400 if (!(mode & MODE_INTER)) {
401 int port = SERVER_PORT + tunno;
402 if (mode & MODE_BACKGROUND) {
403 if (pipe (BGFiledes)) {
404 perror("pipe");
405 Cleanup(EX_SOCK);
406 }
407 }

--- 10 unchanged lines hidden (view full) ---

418 ifsin.sin_addr.s_addr = INADDR_ANY;
419 ifsin.sin_port = htons(port);
420 if (bind(server, (struct sockaddr *) &ifsin, sizeof(ifsin)) < 0) {
421 perror("bind");
422 if (errno == EADDRINUSE)
423 fprintf(stderr, "Wait for a while, then try again.\n");
424 Cleanup(EX_SOCK);
425 }
425 listen(server, 5);
426 if (listen(server, 5) != 0) {
427 fprintf(stderr, "Unable to listen to socket - OS overload?\n");
428 }
426 }
427
428 DupLog();
429 if (!(mode & MODE_DIRECT)) {
430 int fd;
431 char pid[32];
432 pid_t bgpid;
433

--- 488 unchanged lines hidden (view full) ---

922 /* Fall down */
923 case VALID:
924 VarLocalAuth = LOCAL_AUTH;
925 break;
926 default:
927 break;
928 }
929 (void) IsInteractive();
429 }
430
431 DupLog();
432 if (!(mode & MODE_DIRECT)) {
433 int fd;
434 char pid[32];
435 pid_t bgpid;
436

--- 488 unchanged lines hidden (view full) ---

925 /* Fall down */
926 case VALID:
927 VarLocalAuth = LOCAL_AUTH;
928 break;
929 default:
930 break;
931 }
932 (void) IsInteractive();
930 Prompt(0);
933 Prompt();
931 }
932
933 if ((mode & MODE_INTER) && (netfd >= 0 && FD_ISSET(netfd, &rfds)) &&
934 ((mode & MODE_AUTO) || pgroup == tcgetpgrp(0))) {
935 /* something to read from tty */
936 ReadTty();
937 }
938 if (modem >= 0) {

--- 19 unchanged lines hidden (view full) ---

958 /*
959 * LCP packet is detected. Turn ourselves into packet mode.
960 */
961 if (cp != rbuff) {
962 write(1, rbuff, cp - rbuff);
963 write(1, "\r\n", 2);
964 }
965 PacketMode();
934 }
935
936 if ((mode & MODE_INTER) && (netfd >= 0 && FD_ISSET(netfd, &rfds)) &&
937 ((mode & MODE_AUTO) || pgroup == tcgetpgrp(0))) {
938 /* something to read from tty */
939 ReadTty();
940 }
941 if (modem >= 0) {

--- 19 unchanged lines hidden (view full) ---

961 /*
962 * LCP packet is detected. Turn ourselves into packet mode.
963 */
964 if (cp != rbuff) {
965 write(1, rbuff, cp - rbuff);
966 write(1, "\r\n", 2);
967 }
968 PacketMode();
966#ifdef notdef
967 AsyncInput(cp, n - (cp - rbuff));
968#endif
969 } else
970 write(1, rbuff, n);
971 }
972 } else {
973 if (n > 0)
974 AsyncInput(rbuff, n);
969 } else
970 write(1, rbuff, n);
971 }
972 } else {
973 if (n > 0)
974 AsyncInput(rbuff, n);
975#ifdef notdef
976 continue; /* THIS LINE RESULT AS POOR PERFORMANCE */
977#endif
978 }
979 }
980 }
981
982 if (tun_in >= 0 && FD_ISSET(tun_in, &rfds)) { /* something to read from tun */
983 n = read(tun_in, rbuff, sizeof(rbuff));
984 if (n < 0) {
985 perror("read from tun");

--- 30 unchanged lines hidden ---
975 }
976 }
977 }
978
979 if (tun_in >= 0 && FD_ISSET(tun_in, &rfds)) { /* something to read from tun */
980 n = read(tun_in, rbuff, sizeof(rbuff));
981 if (n < 0) {
982 perror("read from tun");

--- 30 unchanged lines hidden ---