Deleted Added
full compact
tcpip.c (8549) tcpip.c (8556)
1/*
1/*
2 * $Id$
2 * $Id: tcpip.c,v 1.1 1995/05/16 02:53:28 jkh Exp $
3 *
4 * Copyright (c) 1995
5 * Gary J Palmer. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright

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

42#include <sys/param.h>
43#include <string.h>
44#include <dialog.h>
45#include "ui_objects.h"
46#include "dir.h"
47#include "dialog.priv.h"
48#include "colors.h"
49#include "rc.h"
3 *
4 * Copyright (c) 1995
5 * Gary J Palmer. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright

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

42#include <sys/param.h>
43#include <string.h>
44#include <dialog.h>
45#include "ui_objects.h"
46#include "dir.h"
47#include "dialog.priv.h"
48#include "colors.h"
49#include "rc.h"
50#include "sysinstall.h"
50
51static char hostname[256], domainname[256],
52 ipaddr[32], netmask[32], gateway[32],
51
52static char hostname[256], domainname[256],
53 ipaddr[32], netmask[32], gateway[32],
53 dns[32], extras[256];
54 nameserver[32], extras[256], iface[4];
54static int okbutton, cancelbutton;
55
56#define TCP_DIALOG_Y 0
57#define TCP_DIALOG_X 8
58#define TCP_DIALOG_WIDTH COLS - 16
59#define TCP_DIALOG_HEIGHT LINES - 2
60
61/* The names of the available interfaces, for the list */
55static int okbutton, cancelbutton;
56
57#define TCP_DIALOG_Y 0
58#define TCP_DIALOG_X 8
59#define TCP_DIALOG_WIDTH COLS - 16
60#define TCP_DIALOG_HEIGHT LINES - 2
61
62/* The names of the available interfaces, for the list */
62char *iface_names[MAX_INTERFACE];
63char *iface_names[INTERFACE_MAX];
63
64typedef struct _interface {
64
65typedef struct _interface {
65 char *name;
66
67 char netmask[32];
68 char ifconfig_extras[256];
66 Device *dev;
67} Interface;
68
69typedef struct _layout {
69 Device *dev;
70} Interface;
71
72typedef struct _layout {
70 int y;
71 int x;
72 int len;
73 int maxlen;
74 char *prompt;
75 char *help;
76 void *var;
77 int type;
78 void *obj;
73 int y;
74 int x;
75 int len;
76 int maxlen;
77 char *prompt;
78 char *help;
79 void *var;
80 int type;
81 void *obj;
79} Layout;
80
81static Layout layout[] = {
82} Layout;
83
84static Layout layout[] = {
82{ 2, 2, 25, 255,
85{ 1, 2, 25, 255,
83 "Host name:", "The name of your machine on a network, e.g. foo.bar.com",
84 hostname, STRINGOBJ, NULL },
86 "Host name:", "The name of your machine on a network, e.g. foo.bar.com",
87 hostname, STRINGOBJ, NULL },
85{ 2, 35, 20, 255,
88{ 1, 35, 20, 255,
86 "Domain name:",
87 "The name of the domain that your machine is in, e.g. bar.com",
88 domainname, STRINGOBJ, NULL },
89{ 5, 2, 18, 15,
90 "Gateway:",
91 "IP address of host forwarding packets to non-local hosts or nets",
92 gateway, STRINGOBJ, NULL },
93{ 5, 35, 18, 15,
94 "Name server:", "IP address of your local DNS server",
89 "Domain name:",
90 "The name of the domain that your machine is in, e.g. bar.com",
91 domainname, STRINGOBJ, NULL },
92{ 5, 2, 18, 15,
93 "Gateway:",
94 "IP address of host forwarding packets to non-local hosts or nets",
95 gateway, STRINGOBJ, NULL },
96{ 5, 35, 18, 15,
97 "Name server:", "IP address of your local DNS server",
95 dns, STRINGOBJ, NULL },
96{ 8, 2, 10, 6,
98 nameserver, STRINGOBJ, NULL },
99{ 9, 2, 9, 6,
97 "Interface:", "One of potentially several network interfaces",
100 "Interface:", "One of potentially several network interfaces",
98 ifaces, LISTOBJ, NULL },
99{ 14, 2, 18, 15,
101 iface, LISTOBJ, NULL },
102{ 10, 18, 18, 15,
100 "IP Address:",
101 "The IP address to be used for your host - use 127.0.0.1 for loopback",
102 ipaddr, STRINGOBJ, NULL },
103 "IP Address:",
104 "The IP address to be used for your host - use 127.0.0.1 for loopback",
105 ipaddr, STRINGOBJ, NULL },
103{ 14, 35, 18, 15,
106{ 10, 37, 18, 15,
104 "Netmask:",
105 "The netmask for your network, e.g. 0xffffff00 for a class C network",
106 netmask, STRINGOBJ, NULL },
107 "Netmask:",
108 "The netmask for your network, e.g. 0xffffff00 for a class C network",
109 netmask, STRINGOBJ, NULL },
107{ 16, 2, 50, 255,
108 "Extra options:",
110{ 14, 18, 37, 255,
111 "Extra options to ifconfig:",
109 "Any options to ifconfig you'd like to specify manually",
110 extras, STRINGOBJ, NULL },
112 "Any options to ifconfig you'd like to specify manually",
113 extras, STRINGOBJ, NULL },
111{ 18, 2, 0, 0,
114{ 19, 10, 0, 0,
112 "OK", "Select this if you are happy with these settings",
113 &okbutton, BUTTONOBJ, NULL },
115 "OK", "Select this if you are happy with these settings",
116 &okbutton, BUTTONOBJ, NULL },
114{ 18, 15, 0, 0,
117{ 19, 30, 0, 0,
115 "CANCEL", "Select this if you wish to cancel this screen",
116 &cancelbutton, BUTTONOBJ, NULL },
117{ NULL },
118};
119
120#define _validByte(b) ((b) > 0 && (b) < 255)
121
122static void
123feepout(char *msg)
124{
125 beep();
118 "CANCEL", "Select this if you wish to cancel this screen",
119 &cancelbutton, BUTTONOBJ, NULL },
120{ NULL },
121};
122
123#define _validByte(b) ((b) > 0 && (b) < 255)
124
125static void
126feepout(char *msg)
127{
128 beep();
126 msgConfirm(msg);
127 dialog_clear();
128 refresh();
129 dialog_notify(msg);
129}
130
131static int
132verifyIP(char *ip)
133{
134 int a, b, c, d;
135
136 if (ip && sscanf(ip, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&

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

145verifySettings(void)
146{
147 if (!hostname[0])
148 feepout("Must specify a host name of some sort!");
149 else if (!verifyIP(ipaddr))
150 feepout("Invalid or missing value for IP address");
151 else if (gateway[0] && !verifyIP(gateway))
152 feepout("Invalid gateway IP address specified");
130}
131
132static int
133verifyIP(char *ip)
134{
135 int a, b, c, d;
136
137 if (ip && sscanf(ip, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&

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

146verifySettings(void)
147{
148 if (!hostname[0])
149 feepout("Must specify a host name of some sort!");
150 else if (!verifyIP(ipaddr))
151 feepout("Invalid or missing value for IP address");
152 else if (gateway[0] && !verifyIP(gateway))
153 feepout("Invalid gateway IP address specified");
153 else if (dns[0] && !verifyIP(dns))
154 else if (nameserver[0] && !verifyIP(nameserver))
154 feepout("Invalid name server IP address specified");
155 else if (netmask[0] < '0' || netmask[0] > '9')
156 feepout("Invalid or missing netmask");
157 else
158 return 1;
159 return 0;
160}
161
155 feepout("Invalid name server IP address specified");
156 else if (netmask[0] < '0' || netmask[0] > '9')
157 feepout("Invalid or missing netmask");
158 else
159 return 1;
160 return 0;
161}
162
162/* Call this to initialize the TCP dialog */
163void
164/* This is it - how to get TCP setup values */
163/* This is it - how to get TCP setup values */
165void
166tcpOpenDialog(void)
164int
165tcpOpenDialog(char *str)
167{
168 WINDOW *ds_win;
169 ComposeObj *obj = NULL;
170 ComposeObj *first, *last;
171 int n=0, quit=FALSE, cancel=FALSE, ret,
166{
167 WINDOW *ds_win;
168 ComposeObj *obj = NULL;
169 ComposeObj *first, *last;
170 int n=0, quit=FALSE, cancel=FALSE, ret,
172 max;
171 max, n_iface;
173 char *tmp;
172 char *tmp;
173 Device **devs;
174 char old_iface[4];
174
175 ds_win = newwin(LINES, COLS, 0, 0);
175
176 ds_win = newwin(LINES, COLS, 0, 0);
176 if (ds_win == 0) {
177 if (ds_win == 0)
177 msgFatal("Cannot open TCP/IP dialog window!!");
178 msgFatal("Cannot open TCP/IP dialog window!!");
178 exit(1);
179
180 devs = deviceFind(NULL, DEVICE_TYPE_NETWORK);
181 if (!devs) {
182 msgConfirm("Couldn't find any potential network devices!");
183 return 0;
179 }
184 }
185
186 while (devs[n] != NULL) {
187 iface_names[n] = (devs[n])->name;
188 ++n;
189 }
190 n_iface = --n;
191
180 draw_box(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X,
181 TCP_DIALOG_HEIGHT, TCP_DIALOG_WIDTH,
182 dialog_attr, border_attr);
183 wattrset(ds_win, dialog_attr);
184 mvwaddstr(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X + 20,
185 " Network Configuration ");
192 draw_box(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X,
193 TCP_DIALOG_HEIGHT, TCP_DIALOG_WIDTH,
194 dialog_attr, border_attr);
195 wattrset(ds_win, dialog_attr);
196 mvwaddstr(ds_win, TCP_DIALOG_Y, TCP_DIALOG_X + 20,
197 " Network Configuration ");
198 draw_box(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 16,
199 TCP_DIALOG_HEIGHT - 13, TCP_DIALOG_WIDTH - 21,
200 dialog_attr, border_attr);
201 wattrset(ds_win, dialog_attr);
202 mvwaddstr(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 24,
203 " Per Interface Configuration ");
186
204
205
187 bzero(ipaddr, sizeof(ipaddr));
188 bzero(netmask, sizeof(netmask));
189 bzero(extras, sizeof(extras));
190
191 tmp = getenv(VAR_HOSTNAME);
192 if (tmp)
193 strcpy(hostname, tmp);
194 else

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

200 bzero(domainname, sizeof(domainname));
201 tmp = getenv(VAR_GATEWAY);
202 if (tmp)
203 strcpy(gateway, tmp);
204 else
205 bzero(gateway, sizeof(gateway));
206 tmp = getenv(VAR_NAMESERVER);
207 if (tmp)
206 bzero(ipaddr, sizeof(ipaddr));
207 bzero(netmask, sizeof(netmask));
208 bzero(extras, sizeof(extras));
209
210 tmp = getenv(VAR_HOSTNAME);
211 if (tmp)
212 strcpy(hostname, tmp);
213 else

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

219 bzero(domainname, sizeof(domainname));
220 tmp = getenv(VAR_GATEWAY);
221 if (tmp)
222 strcpy(gateway, tmp);
223 else
224 bzero(gateway, sizeof(gateway));
225 tmp = getenv(VAR_NAMESERVER);
226 if (tmp)
208 strcpy(dns, tmp);
227 strcpy(nameserver, tmp);
209 else
228 else
210 bzero(dns, sizeof(dns));
229 bzero(nameserver, sizeof(nameserver));
211
230
231 n=0;
212#define lt layout[n]
213 while (lt.help != NULL) {
214 switch (lt.type) {
215 case STRINGOBJ:
216 lt.obj = NewStringObj(ds_win, lt.prompt, lt.var,
217 lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X,
218 lt.len, lt.maxlen);
219 break;
220
221 case BUTTONOBJ:
222 lt.obj = NewButtonObj(ds_win, lt.prompt, lt.var,
223 lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X);
224 break;
225
226 case LISTOBJ:
232#define lt layout[n]
233 while (lt.help != NULL) {
234 switch (lt.type) {
235 case STRINGOBJ:
236 lt.obj = NewStringObj(ds_win, lt.prompt, lt.var,
237 lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X,
238 lt.len, lt.maxlen);
239 break;
240
241 case BUTTONOBJ:
242 lt.obj = NewButtonObj(ds_win, lt.prompt, lt.var,
243 lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X);
244 break;
245
246 case LISTOBJ:
227 lt.obj = NewListObj(ds_win, lt.prompt, lt.var, "lo0",
228 lt.y + TCP_DIALOG_Y, lt.x + TCP_DIALOG_X,
229 4, 12, 1);
247 lt.obj = NewListObj(ds_win, lt.prompt, (char **) iface_names,
248 lt.var, lt.y + TCP_DIALOG_Y,
249 lt.x + TCP_DIALOG_X, lt.len, 12, n_iface);
250 break;
230 default:
251 default:
231 printf("Don't support this object yet!\n");
232 end_dialog();
233 exit(1);
252 msgFatal("Don't support this object yet!");
234 }
235 AddObj(&obj, lt.type, (void *) lt.obj);
236 n++;
237 }
238 max = n-1;
239
240 last = obj;
241 while (last->next)
242 last = last->next;
243
244 /* find the first object in the list */
245 first = obj;
246 while (first->prev)
247 first = first->prev;
253 }
254 AddObj(&obj, lt.type, (void *) lt.obj);
255 n++;
256 }
257 max = n-1;
258
259 last = obj;
260 while (last->next)
261 last = last->next;
262
263 /* find the first object in the list */
264 first = obj;
265 while (first->prev)
266 first = first->prev;
248
267
249 n = 0;
268 n = 0;
250 while (quit != TRUE) {
269 cancelbutton = okbutton = 0;
270 strcpy(old_iface, iface);
271
272 while (!quit) {
251 char help_line[80];
252 int i, len = strlen(lt.help);
253
254 for (i = 0; i < 79; i++)
255 help_line[i] = (i < len) ? lt.help[i] : ' ';
256 help_line[i] = '\0';
257 use_helpline(help_line);
258 display_helpline(ds_win, LINES - 1, COLS - 1);
259
260 ret = PollObj(&obj);
261
262 switch (ret) {
263 case SEL_ESC:
273 char help_line[80];
274 int i, len = strlen(lt.help);
275
276 for (i = 0; i < 79; i++)
277 help_line[i] = (i < len) ? lt.help[i] : ' ';
278 help_line[i] = '\0';
279 use_helpline(help_line);
280 display_helpline(ds_win, LINES - 1, COLS - 1);
281
282 ret = PollObj(&obj);
283
284 switch (ret) {
285 case SEL_ESC:
264 quit=TRUE;
265 cancel=TRUE;
286 quit = TRUE, cancel=TRUE;
266 break;
267
268 case KEY_UP:
269 if (obj->prev !=NULL ) {
270 obj = obj->prev;
271 --n;
272 }
273 else {

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

278
279 case KEY_DOWN:
280 if (obj->next != NULL) {
281 obj = obj->next;
282 ++n;
283 }
284 else {
285 obj = first;
287 break;
288
289 case KEY_UP:
290 if (obj->prev !=NULL ) {
291 obj = obj->prev;
292 --n;
293 }
294 else {

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

299
300 case KEY_DOWN:
301 if (obj->next != NULL) {
302 obj = obj->next;
303 ++n;
304 }
305 else {
306 obj = first;
286 n=0;
307 n = 0;
287 }
288 break;
289
290 case SEL_BUTTON:
308 }
309 break;
310
311 case SEL_BUTTON:
291 if (verifySettings())
292 quit=TRUE;
312 if (cancelbutton) {
313 cancel = TRUE, quit = TRUE;
314 }
315 else {
316 if (verifySettings())
317 quit = TRUE;
318 }
293 break;
294
295 case SEL_CR:
296 case SEL_TAB:
319 break;
320
321 case SEL_CR:
322 case SEL_TAB:
323 if (strcmp(old_iface, iface)) {
324 n_iface=0;
325 while(strcmp(iface, iface_names[n_iface]) &&
326 iface_names[n_iface])
327 n_iface++;
328
329 if (iface_names[n_iface]) {
330 msgFatal("Erk - run off the end of the list of interfaces!");
331 exit(1);
332 }
333
334 strcpy(ipaddr,
335
336 strcpy(old_iface, iface);
337 }
338
297 if (n < max)
298 ++n;
299 else
300 n = 0;
301 break;
302
303 case SEL_BACKTAB:
304 if (n)

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

313
314 if (n == 1) {
315 if ((tmp = index(hostname, '.')) != NULL) {
316 strncpy(domainname, tmp + 1, strlen(tmp + 1));
317 RefreshStringObj(layout[1].obj);
318 }
319 }
320 }
339 if (n < max)
340 ++n;
341 else
342 n = 0;
343 break;
344
345 case SEL_BACKTAB:
346 if (n)

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

355
356 if (n == 1) {
357 if ((tmp = index(hostname, '.')) != NULL) {
358 strncpy(domainname, tmp + 1, strlen(tmp + 1));
359 RefreshStringObj(layout[1].obj);
360 }
361 }
362 }
363
364 dialog_clear();
365 refresh();
366
321 if (!cancel) {
367 if (!cancel) {
322 variable_set2("hostname", hostname);
323 variable_set2("domainname", domainname);
324 variable_set2("ip_addr", ipaddr);
325 variable_set2("ip_gateway", gateway);
368 variable_set2(VAR_HOSTNAME, hostname);
369 variable_set2(VAR_DOMAINNAME, domainname);
370 if (gateway[0])
371 variable_set2(VAR_GATEWAY, gateway);
372 if (nameserver[0])
373 variable_set2(VAR_NAMESERVER, nameserver);
374 return 1;
375 }
376
377 return 0;
326}
378}