Annotation of src/distrib/utils/sysinst/net.c, Revision 1.3
1.3 ! phil 1: /* $NetBSD: net.c,v 1.2 1997/09/27 00:09:28 phil Exp $ */
1.1 phil 2:
3: /*
4: * Copyright 1997 Piermont Information Systems Inc.
5: * All rights reserved.
6: *
7: * Written by Philip A. Nelson for Piermont Information Systems Inc.
8: *
9: * Redistribution and use in source and binary forms, with or without
10: * modification, are permitted provided that the following conditions
11: * are met:
12: * 1. Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in the
16: * documentation and/or other materials provided with the distribution.
17: * 3. All advertising materials mentioning features or use of this software
18: * must display the following acknowledgement:
19: * This product includes software develooped for the NetBSD Project by
20: * Piermont Information Systems Inc.
21: * 4. The name of Piermont Information Systems Inc. may not be used to endorse
22: * or promote products derived from this software without specific prior
23: * written permission.
24: *
25: * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28: * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35: * THE POSSIBILITY OF SUCH DAMAGE.
36: *
37: */
38:
39: /* net.c -- routines to fetch files off the network. */
40:
41: #include <stdio.h>
42: #include <stdlib.h>
43: #include <string.h>
44: #include <curses.h>
45: #include <unistd.h>
46: #include "defs.h"
47: #include "md.h"
48: #include "msg_defs.h"
49: #include "menu_defs.h"
50: #include "txtwalk.h"
51:
52: static void found_net (struct data* list, int num);
53:
54: struct lookfor netbuf[] = {
55: {"ed", "%s:", "c", NULL, found_net},
56: {"el", "%s:", "c", NULL, found_net},
57: {"ep", "%s:", "c", NULL, found_net},
58: {"ie", "%s:", "c", NULL, found_net},
59: {"lc", "%s:", "c", NULL, found_net},
60: {"fea", "%s:", "c", NULL, found_net},
61: {"le", "%s:", "c", NULL, found_net},
62: {"de", "%s:", "c", NULL, found_net},
63: {"fpa", "%s:", "c", NULL, found_net},
64: {"fxp", "%s:", "c", NULL, found_net}
65: };
66:
67: int numnetbuf = sizeof(netbuf) / sizeof(struct lookfor);
68:
69:
70: static void found_net (struct data* list, int num)
71: {
72: int i;
1.3 ! phil 73: strncat (net_devices, list[0].u.s_val, STRSIZE-strlen(net_devices));
1.1 phil 74: i = strlen(net_devices);
75: net_devices[i] = ' ';
76: net_devices[i+1] = '\0';
77: }
78:
79: static void get_ifconfig_info (void)
80: {
81: char *textbuf;
82: int textsize;
83:
84: /* Get ifconfig information */
85:
86: textsize = collect (T_OUTPUT, &textbuf,
1.3 ! phil 87: "/sbin/ifconfig -l 2>/dev/null");
1.1 phil 88: if (textsize < 0) {
89: endwin();
90: (void) fprintf (stderr, "Could not run ifconfig.");
91: exit (1);
92: }
1.3 ! phil 93: /* walk (textbuf, textsize, netbuf, numnetbuf); */
! 94: (void) strtok(textbuf,"\n");
! 95: strncpy (net_devices, textbuf, textsize<STRSIZE ? textsize : STRSIZE);
! 96: net_devices[STRSIZE] = 0;
1.1 phil 97: free (textbuf);
98: }
99:
100:
1.3 ! phil 101: static int config_network (void)
1.1 phil 102: { char *tp;
103: char defname[255];
104: int octet0;
105: int pass;
106:
107: FILE *f;
108:
109: net_devices[0] = '\0';
110: get_ifconfig_info ();
111: strncpy (defname, net_devices, 255);
112: tp = defname;
113: strsep(&tp, " ");
114: msg_prompt (MSG_asknetdev, defname, net_dev, 255, net_devices);
115: tp = net_dev;
116: strsep(&tp, " ");
117: net_dev[strlen(net_dev)+1] = 0;
118: net_dev[strlen(net_dev)] = ' ';
119: while ((strlen(net_dev) != 4 && strlen(net_dev) != 5) ||
120: strstr(net_devices, net_dev) == NULL) {
121: msg_prompt (MSG_badnet, defname, net_dev, 10,
122: net_devices);
123: tp = net_dev;
124: strsep(&tp, " ");
125: net_dev[strlen(net_dev)+1] = 0;
126: net_dev[strlen(net_dev)] = ' ';
127: }
128:
129: /* Remove that space we added. */
130: net_dev[strlen(net_dev)-1] = 0;
131:
132: /* Get other net information */
133: msg_display (MSG_netinfo);
134: pass = 0;
135: do {
136: msg_prompt_add (MSG_net_domain, net_domain, net_domain,
137: STRSIZE);
138: msg_prompt_add (MSG_net_host, net_host, net_host, STRSIZE);
139: msg_prompt_add (MSG_net_ip, net_ip, net_ip, STRSIZE);
140: octet0 = atoi(net_ip);
141: if (!pass) {
142: if (0 <= octet0 && octet0 <= 127)
143: strcpy (net_mask, "0xff000000");
144: else if (127 <= octet0 && octet0 <= 191)
145: strcpy (net_mask, "0xffff0000");
146: else if (192 <= octet0 && octet0 <= 223)
147: strcpy (net_mask, "0xffff0000");
148: }
149: msg_prompt_add (MSG_net_mask, net_mask, net_mask, STRSIZE);
150: msg_prompt_add (MSG_net_namesrv, net_namesvr, net_namesvr,
151: STRSIZE);
152: msg_prompt_add (MSG_net_defroute, net_defroute, net_defroute,
153: STRSIZE);
154:
155: msg_display (MSG_netok, net_domain, net_host, net_ip,
156: net_mask, net_namesvr, net_defroute);
157: process_menu (MENU_yesno);
158: if (!yesno)
159: msg_display (MSG_netagain);
160: pass++;
161: } while (!yesno);
162:
163: /* Create /etc/resolv.conf */
164: #ifdef DEBUG
165: f = fopen ("/tmp/resolv.conf", "w");
166: #else
167: f = fopen ("/etc/resolv.conf", "w");
168: #endif
169: if (f == NULL) {
170: endwin();
171: (void)fprintf(stderr, "%s", msg_string(MSG_resolv));
172: exit(1);
173: }
174: (void)fprintf (f, "nameserver %s\nlookup file bind\nsearch %s",
175: net_namesvr, net_domain);
176: fclose (f);
177:
178: run_prog ("/sbin/ifconfig lo0 127.0.0.1");
179: run_prog ("/sbin/ifconfig %s inet %s netmask %s", net_dev, net_ip,
180: net_mask);
1.3 ! phil 181: run_prog ("/sbin/route -f 2> /dev/null");
! 182: run_prog ("/sbin/route add default %s 2> /dev/null", net_defroute);
! 183:
! 184: return run_prog ("/sbin/ping -c 2 %s > /dev/null", net_defroute)
! 185: || run_prog ("/sbin/ping -c 2 %s > /dev/null", net_namesvr);
1.1 phil 186: }
187:
1.2 phil 188: int
1.1 phil 189: get_via_ftp (void)
1.2 phil 190: {
1.1 phil 191: char **list;
192: char realdir[STRSIZE];
1.2 phil 193: int ret;
1.1 phil 194:
1.3 ! phil 195: while (config_network ()) {
! 196: msg_display (MSG_netnotup);
! 197: process_menu (MENU_yesno);
! 198: if (!yesno)
! 199: return 0;
! 200: }
! 201:
1.1 phil 202: strncat (ftp_dir, ftp_prefix, STRSIZE-strlen(ftp_dir));
203: process_menu (MENU_ftpsource);
204: msg_prompt (MSG_netdir, dist_dir, dist_dir, STRSIZE, "ftp");
205: snprintf (realdir, STRSIZE, "/mnt/%s", dist_dir);
206: strcpy (dist_dir, realdir);
207: run_prog ("/bin/mkdir %s", realdir);
1.2 phil 208: clean_dist_dir = 1;
1.1 phil 209: #ifndef DEBUG
210: if (chdir(realdir)) {
211: endwin();
212: (void)fprintf(stderr, msg_string(MSG_realdir), realdir);
213: exit(1);
214: }
215: #else
216: printf ("chdir (%s)\n", realdir);
217: #endif
218:
219: list = ftp_list;
220: endwin();
221: while (*list) {
222: if (strcmp ("ftp", ftp_user) == 0)
1.2 phil 223: ret = run_prog("/usr/bin/ftp -a ftp://%s/%s/%s%s%s",
224: ftp_host, ftp_dir,
225: *list, rels, ftp_postfix);
1.1 phil 226: else
1.2 phil 227: ret = run_prog("/usr/bin/ftp ftp://%s:%s@%s/%s/%s%s%s",
228: ftp_user, ftp_pass, ftp_host, ftp_dir,
229: *list, rels, ftp_postfix);
230: if (ret) {
231: /* Error getting the file. Bad host name ... ? */
232: wrefresh (stdscr);
233: msg_display (MSG_ftperror);
234: process_menu (MENU_yesno);
235: if (yesno)
236: process_menu (MENU_ftpsource);
237: else
238: return 0;
239: endwin();
240: } else
241: list++;
1.1 phil 242: }
243: puts (CL); /* Just to make sure. */
1.2 phil 244: wrefresh (stdscr);
1.1 phil 245: #ifndef DEBUG
246: chdir("/");
247: #endif
1.2 phil 248: return 1;
1.1 phil 249: }
250:
251: void
252: get_via_nfs(void)
253: {
254: config_network ();
255: /* Get server and filepath */
256: /* Mount it */
257: }
CVSweb <webmaster@jp.NetBSD.org>