1995-05-16 04:53:31 +02:00
|
|
|
/*
|
1995-05-25 20:48:33 +02:00
|
|
|
* $Id: tcpip.c,v 1.13 1995/05/25 01:52:04 jkh Exp $
|
1995-05-16 04:53:31 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Gary J Palmer. 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,
|
|
|
|
* verbatim and that no modifications are made prior to this
|
|
|
|
* point in the file.
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Gary J Palmer
|
1995-05-21 17:40:54 +02:00
|
|
|
* for the FreeBSD Project.
|
|
|
|
* 4. The name of Gary J Palmer or the FreeBSD Project may
|
|
|
|
* not be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
1995-05-16 04:53:31 +02:00
|
|
|
*
|
1995-05-21 17:40:54 +02:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY GARY J PALMER ``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 GARY J PALMER 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, LIFE 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.
|
1995-05-16 04:53:31 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dialog.h>
|
|
|
|
#include "ui_objects.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "dialog.priv.h"
|
|
|
|
#include "colors.h"
|
|
|
|
#include "rc.h"
|
1995-05-16 13:37:27 +02:00
|
|
|
#include "sysinstall.h"
|
1995-05-16 04:53:31 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* These are nasty, but they make the layout structure a lot easier ... */
|
|
|
|
|
1995-05-16 04:53:31 +02:00
|
|
|
static char hostname[256], domainname[256],
|
1995-05-16 22:00:51 +02:00
|
|
|
gateway[32], nameserver[32], iface[8];
|
1995-05-16 04:53:31 +02:00
|
|
|
static int okbutton, cancelbutton;
|
1995-05-16 22:00:51 +02:00
|
|
|
static char ipaddr[32], netmask[32], extras[256];
|
1995-05-16 04:53:31 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* What the screen size is meant to be */
|
1995-05-16 04:53:31 +02:00
|
|
|
#define TCP_DIALOG_Y 0
|
|
|
|
#define TCP_DIALOG_X 8
|
|
|
|
#define TCP_DIALOG_WIDTH COLS - 16
|
|
|
|
#define TCP_DIALOG_HEIGHT LINES - 2
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* The per interface set of records */
|
1995-05-16 04:53:31 +02:00
|
|
|
typedef struct _interface {
|
1995-05-17 14:09:11 +02:00
|
|
|
char ipaddr[32];
|
|
|
|
char netmask[32];
|
|
|
|
char extras[256]; /* Extra stuff for ifconfig (link0, etc) */
|
|
|
|
int valid;
|
1995-05-18 15:18:35 +02:00
|
|
|
Device *dptr;
|
1995-05-16 04:53:31 +02:00
|
|
|
} Interface;
|
|
|
|
|
1995-05-16 22:00:51 +02:00
|
|
|
/* The names and details of the available interfaces, for the list */
|
|
|
|
Interface if_list[INTERFACE_MAX];
|
|
|
|
char *iface_names[INTERFACE_MAX];
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* The screen layout structure */
|
1995-05-16 04:53:31 +02:00
|
|
|
typedef struct _layout {
|
1995-05-17 14:09:11 +02:00
|
|
|
int y; /* x & Y co-ordinates */
|
1995-05-16 13:37:27 +02:00
|
|
|
int x;
|
1995-05-17 14:09:11 +02:00
|
|
|
int len; /* The size of the dialog on the screen */
|
|
|
|
int maxlen; /* How much the user can type in ... */
|
|
|
|
char *prompt; /* The string for the prompt */
|
|
|
|
char *help; /* The display for the help line */
|
|
|
|
void *var; /* The var to set when this changes */
|
|
|
|
int type; /* The type of the dialog to create */
|
|
|
|
void *obj; /* The obj pointer returned by libdialog */
|
1995-05-16 04:53:31 +02:00
|
|
|
} Layout;
|
|
|
|
|
|
|
|
static Layout layout[] = {
|
1995-05-16 13:37:27 +02:00
|
|
|
{ 1, 2, 25, 255,
|
1995-05-16 04:53:31 +02:00
|
|
|
"Host name:", "The name of your machine on a network, e.g. foo.bar.com",
|
|
|
|
hostname, STRINGOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_HOSTNAME 0
|
1995-05-16 13:37:27 +02:00
|
|
|
{ 1, 35, 20, 255,
|
1995-05-16 04:53:31 +02:00
|
|
|
"Domain name:",
|
|
|
|
"The name of the domain that your machine is in, e.g. bar.com",
|
|
|
|
domainname, STRINGOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_DOMAINNAME 1
|
1995-05-16 04:53:31 +02:00
|
|
|
{ 5, 2, 18, 15,
|
|
|
|
"Gateway:",
|
|
|
|
"IP address of host forwarding packets to non-local hosts or nets",
|
|
|
|
gateway, STRINGOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_GATEWAY 2
|
1995-05-16 04:53:31 +02:00
|
|
|
{ 5, 35, 18, 15,
|
|
|
|
"Name server:", "IP address of your local DNS server",
|
1995-05-16 13:37:27 +02:00
|
|
|
nameserver, STRINGOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_NAMESERVER 3
|
1995-05-16 13:37:27 +02:00
|
|
|
{ 9, 2, 9, 6,
|
1995-05-17 14:09:11 +02:00
|
|
|
"Interface:",
|
|
|
|
"Network devices found on boot (use <TAB> to exit from here)",
|
1995-05-16 13:37:27 +02:00
|
|
|
iface, LISTOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_IFACE 4
|
1995-05-16 13:37:27 +02:00
|
|
|
{ 10, 18, 18, 15,
|
1995-05-16 04:53:31 +02:00
|
|
|
"IP Address:",
|
1995-05-18 11:02:06 +02:00
|
|
|
"The IP address to be used for this interface - use 127.0.0.1 for lo0",
|
1995-05-16 04:53:31 +02:00
|
|
|
ipaddr, STRINGOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_IPADDR 5
|
1995-05-16 13:37:27 +02:00
|
|
|
{ 10, 37, 18, 15,
|
1995-05-16 04:53:31 +02:00
|
|
|
"Netmask:",
|
1995-05-18 11:02:06 +02:00
|
|
|
"The netmask for this interfaace, e.g. 0xffffff00 for a class C network",
|
1995-05-16 04:53:31 +02:00
|
|
|
netmask, STRINGOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_NETMASK 6
|
1995-05-16 13:37:27 +02:00
|
|
|
{ 14, 18, 37, 255,
|
|
|
|
"Extra options to ifconfig:",
|
1995-05-18 11:02:06 +02:00
|
|
|
"Any interface-specific options to ifconfig you'd like to use",
|
1995-05-16 04:53:31 +02:00
|
|
|
extras, STRINGOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_EXTRAS 7
|
1995-05-16 13:37:27 +02:00
|
|
|
{ 19, 10, 0, 0,
|
1995-05-16 04:53:31 +02:00
|
|
|
"OK", "Select this if you are happy with these settings",
|
|
|
|
&okbutton, BUTTONOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_OKBUTTON 8
|
1995-05-16 13:37:27 +02:00
|
|
|
{ 19, 30, 0, 0,
|
1995-05-16 04:53:31 +02:00
|
|
|
"CANCEL", "Select this if you wish to cancel this screen",
|
|
|
|
&cancelbutton, BUTTONOBJ, NULL },
|
1995-05-17 14:09:11 +02:00
|
|
|
#define LAYOUT_CANCELBUTTON 9
|
1995-05-16 04:53:31 +02:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define _validByte(b) ((b) > 0 && (b) < 255)
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* A JKH special - inform the user of an unusal error in a controlled
|
|
|
|
fashion */
|
1995-05-16 04:53:31 +02:00
|
|
|
static void
|
|
|
|
feepout(char *msg)
|
|
|
|
{
|
|
|
|
beep();
|
1995-05-16 13:37:27 +02:00
|
|
|
dialog_notify(msg);
|
1995-05-16 04:53:31 +02:00
|
|
|
}
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Very basic IP address integrity check - could be drastically improved */
|
1995-05-16 04:53:31 +02:00
|
|
|
static int
|
|
|
|
verifyIP(char *ip)
|
|
|
|
{
|
|
|
|
int a, b, c, d;
|
|
|
|
|
|
|
|
if (ip && sscanf(ip, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&
|
|
|
|
_validByte(a) && _validByte(b) && _validByte(c) &&
|
|
|
|
_validByte(d))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Check for the settings on the screen - the per interface stuff is
|
|
|
|
moved to the main handling code now to do it on the fly - sigh */
|
|
|
|
|
1995-05-16 04:53:31 +02:00
|
|
|
static int
|
|
|
|
verifySettings(void)
|
|
|
|
{
|
|
|
|
if (!hostname[0])
|
|
|
|
feepout("Must specify a host name of some sort!");
|
|
|
|
else if (gateway[0] && !verifyIP(gateway))
|
|
|
|
feepout("Invalid gateway IP address specified");
|
1995-05-16 13:37:27 +02:00
|
|
|
else if (nameserver[0] && !verifyIP(nameserver))
|
1995-05-16 04:53:31 +02:00
|
|
|
feepout("Invalid name server IP address specified");
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is it - how to get TCP setup values */
|
1995-05-16 13:37:27 +02:00
|
|
|
int
|
|
|
|
tcpOpenDialog(char *str)
|
1995-05-16 04:53:31 +02:00
|
|
|
{
|
|
|
|
WINDOW *ds_win;
|
|
|
|
ComposeObj *obj = NULL;
|
|
|
|
ComposeObj *first, *last;
|
|
|
|
int n=0, quit=FALSE, cancel=FALSE, ret,
|
1995-05-16 13:37:27 +02:00
|
|
|
max, n_iface;
|
1995-05-16 04:53:31 +02:00
|
|
|
char *tmp;
|
1995-05-16 13:37:27 +02:00
|
|
|
Device **devs;
|
1995-05-16 22:00:51 +02:00
|
|
|
char old_iface[8];
|
1995-05-17 16:40:00 +02:00
|
|
|
char help[FILENAME_MAX];
|
1995-05-16 04:53:31 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* We need a curses window */
|
1995-05-16 04:53:31 +02:00
|
|
|
ds_win = newwin(LINES, COLS, 0, 0);
|
1995-05-16 13:37:27 +02:00
|
|
|
if (ds_win == 0)
|
1995-05-16 04:53:31 +02:00
|
|
|
msgFatal("Cannot open TCP/IP dialog window!!");
|
1995-05-16 13:37:27 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Look for net.devices for us to configure */
|
1995-05-16 13:37:27 +02:00
|
|
|
devs = deviceFind(NULL, DEVICE_TYPE_NETWORK);
|
|
|
|
if (!devs) {
|
|
|
|
msgConfirm("Couldn't find any potential network devices!");
|
|
|
|
return 0;
|
1995-05-16 04:53:31 +02:00
|
|
|
}
|
1995-05-16 13:37:27 +02:00
|
|
|
|
|
|
|
while (devs[n] != NULL) {
|
|
|
|
iface_names[n] = (devs[n])->name;
|
1995-05-18 15:18:35 +02:00
|
|
|
if_list[n].dptr = devs[n];
|
1995-05-16 13:37:27 +02:00
|
|
|
++n;
|
|
|
|
}
|
1995-05-17 16:40:00 +02:00
|
|
|
n_iface = n;
|
1995-05-16 13:37:27 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Setup a nice screen for us to splat stuff onto */
|
1995-05-17 16:40:00 +02:00
|
|
|
systemHelpFile(TCP_HELPFILE, help);
|
|
|
|
use_helpfile(help);
|
1995-05-16 04:53:31 +02:00
|
|
|
draw_box(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X,
|
|
|
|
TCP_DIALOG_HEIGHT, TCP_DIALOG_WIDTH,
|
|
|
|
dialog_attr, border_attr);
|
|
|
|
wattrset(ds_win, dialog_attr);
|
|
|
|
mvwaddstr(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X + 20,
|
|
|
|
" Network Configuration ");
|
1995-05-16 13:37:27 +02:00
|
|
|
draw_box(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 16,
|
|
|
|
TCP_DIALOG_HEIGHT - 13, TCP_DIALOG_WIDTH - 21,
|
|
|
|
dialog_attr, border_attr);
|
|
|
|
wattrset(ds_win, dialog_attr);
|
|
|
|
mvwaddstr(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 24,
|
|
|
|
" Per Interface Configuration ");
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Initialise vars so that dialog has something to chew on */
|
1995-05-16 22:00:51 +02:00
|
|
|
strcpy(ipaddr, if_list[0].ipaddr);
|
|
|
|
strcpy(netmask, if_list[0].netmask);
|
|
|
|
strcpy(extras, if_list[0].extras);
|
1995-05-16 04:53:31 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Look up values already recorded with the system, or blank the
|
|
|
|
string variables ready to accept some new data */
|
1995-05-16 04:53:31 +02:00
|
|
|
tmp = getenv(VAR_HOSTNAME);
|
|
|
|
if (tmp)
|
|
|
|
strcpy(hostname, tmp);
|
|
|
|
else
|
|
|
|
bzero(hostname, sizeof(hostname));
|
|
|
|
tmp = getenv(VAR_DOMAINNAME);
|
|
|
|
if (tmp)
|
|
|
|
strcpy(domainname, tmp);
|
|
|
|
else
|
|
|
|
bzero(domainname, sizeof(domainname));
|
|
|
|
tmp = getenv(VAR_GATEWAY);
|
|
|
|
if (tmp)
|
|
|
|
strcpy(gateway, tmp);
|
|
|
|
else
|
|
|
|
bzero(gateway, sizeof(gateway));
|
|
|
|
tmp = getenv(VAR_NAMESERVER);
|
|
|
|
if (tmp)
|
1995-05-16 13:37:27 +02:00
|
|
|
strcpy(nameserver, tmp);
|
1995-05-16 04:53:31 +02:00
|
|
|
else
|
1995-05-16 13:37:27 +02:00
|
|
|
bzero(nameserver, sizeof(nameserver));
|
1995-05-16 04:53:31 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Loop over the layout list, create the objects, and add them
|
|
|
|
onto the chain of objects that dialog uses for traversal*/
|
1995-05-16 22:00:51 +02:00
|
|
|
n = 0;
|
1995-05-16 04:53:31 +02:00
|
|
|
#define lt layout[n]
|
|
|
|
while (lt.help != NULL) {
|
|
|
|
switch (lt.type) {
|
|
|
|
case STRINGOBJ:
|
|
|
|
lt.obj = NewStringObj(ds_win, lt.prompt, lt.var,
|
|
|
|
lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X,
|
|
|
|
lt.len, lt.maxlen);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTONOBJ:
|
|
|
|
lt.obj = NewButtonObj(ds_win, lt.prompt, lt.var,
|
|
|
|
lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LISTOBJ:
|
1995-05-16 13:37:27 +02:00
|
|
|
lt.obj = NewListObj(ds_win, lt.prompt, (char **) iface_names,
|
|
|
|
lt.var, lt.y + TCP_DIALOG_Y,
|
|
|
|
lt.x + TCP_DIALOG_X, lt.len, 12, n_iface);
|
|
|
|
break;
|
1995-05-16 04:53:31 +02:00
|
|
|
default:
|
1995-05-16 13:37:27 +02:00
|
|
|
msgFatal("Don't support this object yet!");
|
1995-05-16 04:53:31 +02:00
|
|
|
}
|
|
|
|
AddObj(&obj, lt.type, (void *) lt.obj);
|
|
|
|
n++;
|
|
|
|
}
|
1995-05-16 22:00:51 +02:00
|
|
|
max = n - 1;
|
1995-05-17 14:09:11 +02:00
|
|
|
|
|
|
|
/* Find the last object we can traverse to */
|
1995-05-16 04:53:31 +02:00
|
|
|
last = obj;
|
|
|
|
while (last->next)
|
|
|
|
last = last->next;
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Find the first object in the list */
|
1995-05-16 04:53:31 +02:00
|
|
|
first = obj;
|
|
|
|
while (first->prev)
|
|
|
|
first = first->prev;
|
1995-05-16 13:37:27 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Some more initialisation before we go into the main input loop */
|
1995-05-16 04:53:31 +02:00
|
|
|
n = 0;
|
1995-05-16 13:37:27 +02:00
|
|
|
cancelbutton = okbutton = 0;
|
1995-05-16 22:00:51 +02:00
|
|
|
strcpy(iface, iface_names[0]);
|
1995-05-17 14:09:11 +02:00
|
|
|
if_list[0].valid = FALSE;
|
1995-05-16 13:37:27 +02:00
|
|
|
strcpy(old_iface, iface);
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Incoming user data - DUCK! */
|
1995-05-16 13:37:27 +02:00
|
|
|
while (!quit) {
|
1995-05-16 04:53:31 +02:00
|
|
|
char help_line[80];
|
|
|
|
int i, len = strlen(lt.help);
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Display the help line at the bottom of the screen */
|
1995-05-16 04:53:31 +02:00
|
|
|
for (i = 0; i < 79; i++)
|
|
|
|
help_line[i] = (i < len) ? lt.help[i] : ' ';
|
|
|
|
help_line[i] = '\0';
|
|
|
|
use_helpline(help_line);
|
|
|
|
display_helpline(ds_win, LINES - 1, COLS - 1);
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Ask for libdialog to do its stuff */
|
1995-05-16 04:53:31 +02:00
|
|
|
ret = PollObj(&obj);
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* We are in the Hostname field - calculate the domainname */
|
|
|
|
if (n == 0) {
|
|
|
|
if ((tmp = index(hostname, '.')) != NULL) {
|
|
|
|
strncpy(domainname, tmp + 1, strlen(tmp + 1));
|
|
|
|
domainname[strlen(tmp+1)] = '\0';
|
|
|
|
RefreshStringObj(layout[1].obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle special case stuff that libdialog misses. Sigh */
|
1995-05-16 04:53:31 +02:00
|
|
|
switch (ret) {
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Bail out */
|
1995-05-16 04:53:31 +02:00
|
|
|
case SEL_ESC:
|
1995-05-16 13:37:27 +02:00
|
|
|
quit = TRUE, cancel=TRUE;
|
1995-05-16 04:53:31 +02:00
|
|
|
break;
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* This doesn't work for list dialogs. Oh well. Perhaps
|
|
|
|
should special case the move from the OK button ``up''
|
|
|
|
to make it go to the interface list, but then it gets
|
|
|
|
awkward for the user to go back and correct screw up's
|
|
|
|
in the per-interface section */
|
|
|
|
|
1995-05-16 04:53:31 +02:00
|
|
|
case KEY_UP:
|
|
|
|
if (obj->prev !=NULL ) {
|
|
|
|
obj = obj->prev;
|
|
|
|
--n;
|
1995-05-16 22:00:51 +02:00
|
|
|
} else {
|
1995-05-16 04:53:31 +02:00
|
|
|
obj = last;
|
|
|
|
n = max;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* More special case handling - if we are at the interface
|
|
|
|
list, move to the OK button - the user hasn't selected
|
|
|
|
one of the entries in the list by pressing CR, so (s)he
|
|
|
|
must be wanting to skip to <OK> & <CANCEL> */
|
1995-05-16 04:53:31 +02:00
|
|
|
case KEY_DOWN:
|
1995-05-17 14:09:11 +02:00
|
|
|
if (n == LAYOUT_EXTRAS) {
|
|
|
|
n = LAYOUT_IFACE;
|
1995-05-16 22:00:51 +02:00
|
|
|
obj = (((first->next)->next)->next)->next;
|
|
|
|
} else if (obj->next != NULL) {
|
1995-05-16 04:53:31 +02:00
|
|
|
obj = obj->next;
|
|
|
|
++n;
|
1995-05-16 22:00:51 +02:00
|
|
|
} else {
|
1995-05-16 04:53:31 +02:00
|
|
|
obj = first;
|
1995-05-16 13:37:27 +02:00
|
|
|
n = 0;
|
1995-05-16 04:53:31 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Same as KEY_DOWN, but dialog has already move us to the
|
|
|
|
next object on the list, which makes this slightly
|
|
|
|
different. */
|
1995-05-16 22:00:51 +02:00
|
|
|
case SEL_TAB:
|
1995-05-17 14:09:11 +02:00
|
|
|
if (n == LAYOUT_EXTRAS) {
|
|
|
|
n = LAYOUT_IFACE;
|
1995-05-16 22:00:51 +02:00
|
|
|
obj = (((first->next)->next)->next)->next;
|
1995-05-18 18:36:14 +02:00
|
|
|
} else if (n < max) {
|
1995-05-16 22:00:51 +02:00
|
|
|
++n;
|
|
|
|
} else {
|
|
|
|
n = 0;
|
|
|
|
}
|
1995-05-17 14:09:11 +02:00
|
|
|
|
|
|
|
/* This looks double dutch, but we have already MOVED onto
|
|
|
|
the next field, so we special case around getting to
|
|
|
|
that field, rather than moving off the previous
|
|
|
|
one. Hence we are really testing for
|
1995-05-17 16:40:00 +02:00
|
|
|
(n == LAYOUT_IFACE) */
|
1995-05-17 14:09:11 +02:00
|
|
|
|
|
|
|
if (n == LAYOUT_IPADDR) {
|
|
|
|
n = LAYOUT_OKBUTTON;
|
1995-05-16 22:00:51 +02:00
|
|
|
obj = ((obj->next)->next)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* The user has pressed enter over a button object */
|
1995-05-16 04:53:31 +02:00
|
|
|
case SEL_BUTTON:
|
1995-05-16 22:00:51 +02:00
|
|
|
if (cancelbutton) {
|
1995-05-16 13:37:27 +02:00
|
|
|
cancel = TRUE, quit = TRUE;
|
1995-05-16 22:00:51 +02:00
|
|
|
} else {
|
1995-05-16 13:37:27 +02:00
|
|
|
if (verifySettings())
|
|
|
|
quit = TRUE;
|
|
|
|
}
|
1995-05-16 04:53:31 +02:00
|
|
|
break;
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Generic CR handler */
|
1995-05-16 04:53:31 +02:00
|
|
|
case SEL_CR:
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Has the user selected a new interface? */
|
1995-05-16 13:37:27 +02:00
|
|
|
if (strcmp(old_iface, iface)) {
|
1995-05-16 22:00:51 +02:00
|
|
|
/* Now go find the new location */
|
|
|
|
n_iface = 0;
|
|
|
|
while (strcmp(iface, iface_names[n_iface]) &&
|
|
|
|
(iface_names[n_iface] != NULL))
|
|
|
|
++n_iface;
|
|
|
|
if (iface_names[n_iface] == NULL)
|
|
|
|
msgFatal("Erk - run off the end of the list of interfaces!");
|
|
|
|
strcpy(ipaddr, if_list[n_iface].ipaddr);
|
|
|
|
strcpy(netmask, if_list[n_iface].netmask);
|
|
|
|
strcpy(extras, if_list[n_iface].extras);
|
1995-05-17 14:09:11 +02:00
|
|
|
if_list[n_iface].valid = FALSE;
|
1995-05-16 22:00:51 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
RefreshStringObj(layout[LAYOUT_IPADDR].obj);
|
|
|
|
RefreshStringObj(layout[LAYOUT_NETMASK].obj);
|
|
|
|
RefreshStringObj(layout[LAYOUT_EXTRAS].obj);
|
1995-05-16 22:00:51 +02:00
|
|
|
|
|
|
|
strcpy(old_iface, iface);
|
1995-05-16 13:37:27 +02:00
|
|
|
}
|
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Loop back to the interface list from the extras box -
|
|
|
|
now we handle the case of saving out the data the user
|
1995-05-21 17:40:54 +02:00
|
|
|
typed in (and also do basic verification of its
|
1995-05-17 14:09:11 +02:00
|
|
|
sanity) */
|
|
|
|
if (n == LAYOUT_EXTRAS) {
|
|
|
|
n = LAYOUT_IFACE;
|
1995-05-16 22:00:51 +02:00
|
|
|
obj = (((first->next)->next)->next)->next;
|
1995-05-17 14:09:11 +02:00
|
|
|
/* First, find the old value */
|
|
|
|
n_iface = 0;
|
|
|
|
while (strcmp(old_iface, iface_names[n_iface]) &&
|
|
|
|
(iface_names[n_iface] != NULL))
|
|
|
|
++n_iface;
|
|
|
|
|
|
|
|
if (iface_names[n_iface] == NULL)
|
|
|
|
msgFatal("Erk - run off the end of the list of interfaces!");
|
|
|
|
|
|
|
|
/* Sanity check what the user supplied - this could probably
|
|
|
|
be better :-( */
|
|
|
|
|
|
|
|
if (!verifyIP(ipaddr)) {
|
|
|
|
feepout("Invalid or missing IP address!");
|
|
|
|
strcpy(iface, old_iface);
|
|
|
|
n = LAYOUT_IFACE;
|
|
|
|
obj = (((first->next)->next)->next)->next;
|
|
|
|
RefreshListObj(layout[LAYOUT_IFACE].obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netmask[0] < '0' || netmask[0] > '9') {
|
|
|
|
feepout("Invalid or missing netmask!");
|
|
|
|
strcpy(iface, old_iface);
|
|
|
|
n = LAYOUT_IFACE;
|
|
|
|
obj = (((first->next)->next)->next)->next;
|
|
|
|
RefreshListObj(layout[LAYOUT_IFACE].obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(if_list[n_iface].ipaddr, ipaddr);
|
|
|
|
strcpy(if_list[n_iface].netmask, netmask);
|
|
|
|
strcpy(if_list[n_iface].extras, extras);
|
|
|
|
if_list[n_iface].valid = TRUE;
|
1995-05-18 15:18:35 +02:00
|
|
|
if_list[n_iface].dptr->enabled = TRUE;
|
1995-05-16 22:00:51 +02:00
|
|
|
} else if (n < max)
|
1995-05-16 04:53:31 +02:00
|
|
|
++n;
|
|
|
|
else
|
|
|
|
n = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEL_BACKTAB:
|
|
|
|
if (n)
|
|
|
|
--n;
|
|
|
|
else
|
|
|
|
n = max;
|
|
|
|
break;
|
1995-05-21 17:40:54 +02:00
|
|
|
|
1995-05-17 16:40:00 +02:00
|
|
|
case KEY_F(1):
|
|
|
|
display_helpfile();
|
1995-05-16 04:53:31 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* They tried some key combination we don't support - tell them! */
|
1995-05-16 04:53:31 +02:00
|
|
|
default:
|
|
|
|
beep();
|
|
|
|
}
|
1995-05-17 14:09:11 +02:00
|
|
|
|
|
|
|
/* BODGE ALERT! */
|
|
|
|
if ((tmp = index(hostname, '.')) != NULL) {
|
|
|
|
strncpy(domainname, tmp + 1, strlen(tmp + 1));
|
|
|
|
domainname[strlen(tmp+1)] = '\0';
|
|
|
|
RefreshStringObj(layout[1].obj);
|
1995-05-16 04:53:31 +02:00
|
|
|
}
|
|
|
|
}
|
1995-05-16 13:37:27 +02:00
|
|
|
|
1995-05-17 14:09:11 +02:00
|
|
|
/* Clear this crap off the screen */
|
1995-05-16 13:37:27 +02:00
|
|
|
dialog_clear();
|
|
|
|
refresh();
|
1995-05-17 16:40:00 +02:00
|
|
|
use_helpfile(NULL);
|
1995-05-17 14:09:11 +02:00
|
|
|
|
|
|
|
/* We actually need to inform the rest of sysinstall about this
|
|
|
|
data now - if the user hasn't selected cancel, save the stuff
|
|
|
|
out to the environment via the variable_set layers */
|
1995-05-16 13:37:27 +02:00
|
|
|
|
1995-05-16 04:53:31 +02:00
|
|
|
if (!cancel) {
|
1995-05-17 14:09:11 +02:00
|
|
|
int foo;
|
1995-05-16 13:37:27 +02:00
|
|
|
variable_set2(VAR_HOSTNAME, hostname);
|
|
|
|
variable_set2(VAR_DOMAINNAME, domainname);
|
|
|
|
if (gateway[0])
|
|
|
|
variable_set2(VAR_GATEWAY, gateway);
|
|
|
|
if (nameserver[0])
|
|
|
|
variable_set2(VAR_NAMESERVER, nameserver);
|
1995-05-17 14:09:11 +02:00
|
|
|
|
|
|
|
/* Loop over the per-interface data saving data which has been
|
|
|
|
validated ... */
|
|
|
|
for (foo = 0 ; foo < INTERFACE_MAX ; foo++) {
|
|
|
|
if (if_list[foo].valid == TRUE) {
|
|
|
|
char temp[512], ifn[64];
|
|
|
|
sprintf(temp, "inet %s %s netmask %s",
|
|
|
|
if_list[foo].ipaddr, if_list[foo].extras,
|
|
|
|
if_list[foo].netmask);
|
1995-05-17 16:40:00 +02:00
|
|
|
sprintf(ifn, "%s%s", VAR_IFCONFIG, iface_names[foo]);
|
1995-05-17 14:09:11 +02:00
|
|
|
variable_set2(ifn, temp);
|
|
|
|
}
|
|
|
|
}
|
1995-05-16 13:37:27 +02:00
|
|
|
}
|
|
|
|
return 0;
|
1995-05-16 04:53:31 +02:00
|
|
|
}
|
1995-05-21 17:40:54 +02:00
|
|
|
|
|
|
|
static Device *netDevice;
|
|
|
|
|
|
|
|
static int
|
|
|
|
netHook(char *str)
|
|
|
|
{
|
|
|
|
Device **devs;
|
|
|
|
|
|
|
|
/* Clip garbage off the ends */
|
|
|
|
string_prune(str);
|
|
|
|
str = string_skipwhite(str);
|
|
|
|
if (!*str)
|
|
|
|
return 0;
|
|
|
|
devs = deviceFind(str, DEVICE_TYPE_NETWORK);
|
|
|
|
if (devs)
|
|
|
|
netDevice = devs[0];
|
|
|
|
return devs ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a network device */
|
|
|
|
Device *
|
|
|
|
tcpDeviceSelect(void)
|
|
|
|
{
|
|
|
|
DMenu *menu;
|
|
|
|
|
|
|
|
/* If we can't find a hostname, ask user to set up TCP/IP */
|
|
|
|
if (!getenv(VAR_HOSTNAME))
|
|
|
|
tcpOpenDialog(NULL);
|
|
|
|
|
|
|
|
/* If we still can't, user is a bonehead */
|
|
|
|
if (!getenv(VAR_HOSTNAME)) {
|
|
|
|
msgConfirm("Sorry, I can't do this if you don't set up your networking first!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
menu = deviceCreateMenu(&MenuNetworkDevice, DEVICE_TYPE_NETWORK, netHook);
|
|
|
|
if (!menu)
|
|
|
|
msgFatal("Unable to create network device menu! Argh!");
|
|
|
|
dmenuOpenSimple(menu);
|
|
|
|
free(menu);
|
|
|
|
return netDevice;
|
|
|
|
}
|
|
|
|
|
1995-05-23 20:06:16 +02:00
|
|
|
/* Start PPP on the 3rd screen */
|
|
|
|
Boolean
|
|
|
|
tcpStartPPP(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open("/dev/ttyv2", O_RDWR);
|
|
|
|
if (fd == -1)
|
|
|
|
return FALSE;
|
1995-05-25 03:52:04 +02:00
|
|
|
Mkdir("/var/log", NULL);
|
1995-05-25 20:48:33 +02:00
|
|
|
Mkdir("/var/spool/lock", NULL);
|
1995-05-23 20:06:16 +02:00
|
|
|
if (!fork()) {
|
|
|
|
dup2(fd, 0);
|
|
|
|
dup2(fd, 1);
|
|
|
|
dup2(fd, 2);
|
|
|
|
execl("/stand/ppp", "/stand/ppp", (char *)NULL);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|