diff options
author | jkh <jkh@FreeBSD.org> | 1999-09-01 04:29:30 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1999-09-01 04:29:30 +0000 |
commit | 2fdb12ea191206861f3cd9bf3a0d8ba85dd96aae (patch) | |
tree | 629d137afaab5d765bfc0fc21e0220e1f8acb9c7 /usr.sbin/sysinstall/tcpip.c | |
parent | 73a7a67d13cba01eb39397ff54125ce8d3e6f8cc (diff) | |
download | FreeBSD-src-2fdb12ea191206861f3cd9bf3a0d8ba85dd96aae.zip FreeBSD-src-2fdb12ea191206861f3cd9bf3a0d8ba85dd96aae.tar.gz |
MFC: Catch 3.2-stable sysinstall up to 4.0-current level functionality,
bringing in DHCP support. The only thing I left out were Poul-Henning's
newfs changes since I'm not sure if he's brought the rest of that support
into -stable yet. If it turns out that this is the case, I'll MFC those
changes too.
Diffstat (limited to 'usr.sbin/sysinstall/tcpip.c')
-rw-r--r-- | usr.sbin/sysinstall/tcpip.c | 138 |
1 files changed, 29 insertions, 109 deletions
diff --git a/usr.sbin/sysinstall/tcpip.c b/usr.sbin/sysinstall/tcpip.c index 105ed2c..0393cfe 100644 --- a/usr.sbin/sysinstall/tcpip.c +++ b/usr.sbin/sysinstall/tcpip.c @@ -39,7 +39,6 @@ #include "sysinstall.h" #include <sys/param.h> -#include <netdb.h> /* The help file for the TCP/IP setup screen */ #define TCP_HELPFILE "tcp" @@ -146,53 +145,6 @@ verifySettings(void) return 0; } -static void -dhcpGetInfo(Device *devp) -{ - /* If it fails, do it the old-fashioned way */ - if (dhcpParseLeases("/var/db/dhclient.leases", hostname, domainname, - nameserver, ipaddr, gateway, netmask) == -1) { - FILE *ifp; - char *cp, cmd[256], data[2048]; - int i, j; - - /* Bah, now we have to kludge getting the information from ifconfig */ - snprintf(cmd, sizeof cmd, "ifconfig %s", devp->name); - ifp = popen(cmd, "r"); - if (ifp) { - j = fread(data, 1, sizeof(data), ifp); - fclose(ifp); - if (j < 0) /* paranoia */ - j = 0; - data[j] = '\0'; - if (isDebug()) - msgDebug("DHCP configured interface returns %s\n", data); - /* XXX This is gross as it assumes a certain ordering to - ifconfig's output! XXX */ - if ((cp = strstr(data, "inet")) != NULL) { - i = 0; - cp += 5; /* move over keyword */ - while (*cp != ' ') - ipaddr[i++] = *(cp++); - ipaddr[i] = '\0'; - if (!strncmp(++cp, "netmask", 7)) { - i = 0; - cp += 8; - while (*cp != ' ') - netmask[i++] = *(cp++); - netmask[i] = '\0'; - } - } - } - } - - /* If we didn't get a name server value, hunt for it in resolv.conf */ - if (!nameserver[0] && file_readable("/etc/resolv.conf")) - configEnvironmentResolv("/etc/resolv.conf"); - if (hostname[0]) - variable_set2(VAR_HOSTNAME, hostname, 0); -} - /* This is it - how to get TCP setup values */ int tcpOpenDialog(Device *devp) @@ -201,7 +153,6 @@ tcpOpenDialog(Device *devp) ComposeObj *obj = NULL; int n = 0, filled = 0, cancel = FALSE; int max, ret = DITEM_SUCCESS; - int use_dhcp = FALSE; char *tmp; char title[80]; @@ -212,46 +163,22 @@ tcpOpenDialog(Device *devp) SAFE_STRCPY(ipaddr, di->ipaddr); SAFE_STRCPY(netmask, di->netmask); SAFE_STRCPY(extras, di->extras); - use_dhcp = di->use_dhcp; } else { /* See if there are any defaults */ char *cp; - /* First try a DHCP scan if such behavior is desired */ - if (!variable_cmp(VAR_TRY_DHCP, "YES") || !msgYesNo("Do you want to try DHCP configuration of the interface?")) { - int k; - - Mkdir("/var/db"); - Mkdir("/var/run"); - Mkdir("/tmp"); - msgNotify("Scanning for DHCP servers..."); - for (k = 1; k < 4; k++) { - if (0 == vsystem("dhclient -1 %s", devp->name)) { - dhcpGetInfo(devp); - use_dhcp = TRUE; - break; - } - msgNotify("Scanning for DHCP servers... Retry: %d", k); - } - } - - /* Get old IP address from variable space, if available */ if (!ipaddr[0]) { if ((cp = variable_get(VAR_IPADDR)) != NULL) SAFE_STRCPY(ipaddr, cp); else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_IPADDR))) != NULL) SAFE_STRCPY(ipaddr, cp); } - - /* Get old netmask from variable space, if available */ if (!netmask[0]) { if ((cp = variable_get(VAR_NETMASK)) != NULL) SAFE_STRCPY(netmask, cp); else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_NETMASK))) != NULL) SAFE_STRCPY(netmask, cp); } - - /* Get old extras string from variable space, if available */ if (!extras[0]) { if ((cp = variable_get(VAR_EXTRAS)) != NULL) SAFE_STRCPY(extras, cp); @@ -261,26 +188,26 @@ tcpOpenDialog(Device *devp) } /* Look up values already recorded with the system, or blank the string variables ready to accept some new data */ - if (!hostname[0]) { - tmp = variable_get(VAR_HOSTNAME); - if (tmp) - SAFE_STRCPY(hostname, tmp); - } - if (!domainname[0]) { - tmp = variable_get(VAR_DOMAINNAME); - if (tmp) - SAFE_STRCPY(domainname, tmp); - } - if (!gateway[0]) { - tmp = variable_get(VAR_GATEWAY); - if (tmp) - SAFE_STRCPY(gateway, tmp); - } - if (!nameserver[0]) { - tmp = variable_get(VAR_NAMESERVER); - if (tmp) - SAFE_STRCPY(nameserver, tmp); - } + tmp = variable_get(VAR_HOSTNAME); + if (tmp) + SAFE_STRCPY(hostname, tmp); + else + bzero(hostname, sizeof(hostname)); + tmp = variable_get(VAR_DOMAINNAME); + if (tmp) + SAFE_STRCPY(domainname, tmp); + else + bzero(domainname, sizeof(domainname)); + tmp = variable_get(VAR_GATEWAY); + if (tmp) + SAFE_STRCPY(gateway, tmp); + else + bzero(gateway, sizeof(gateway)); + tmp = variable_get(VAR_NAMESERVER); + if (tmp) + SAFE_STRCPY(nameserver, tmp); + else + bzero(nameserver, sizeof(nameserver)); save = savescr(); /* If non-interactive, jump straight over the dialog crap and into config section */ @@ -325,7 +252,7 @@ reenter: * the most appropriate one (entire class C, or subnetted * class A/B network). */ - if (!netmask[0]) { + if (netmask[0] == '\0') { strcpy(netmask, "255.255.255.0"); RefreshStringObj(layout[LAYOUT_NETMASK].obj); ++filled; @@ -361,18 +288,14 @@ netconfig: char temp[512], ifn[255]; char *ifaces; - if (hostname[0]) { - variable_set2(VAR_HOSTNAME, hostname, use_dhcp ? 0 : 1); - sethostname(hostname, strlen(hostname)); - } + variable_set2(VAR_HOSTNAME, hostname, 1); + sethostname(hostname, strlen(hostname)); if (domainname[0]) variable_set2(VAR_DOMAINNAME, domainname, 0); if (gateway[0]) - variable_set2(VAR_GATEWAY, gateway, use_dhcp ? 0 : 1); + variable_set2(VAR_GATEWAY, gateway, 1); if (nameserver[0]) variable_set2(VAR_NAMESERVER, nameserver, 0); - if (ipaddr[0]) - variable_set2(VAR_IPADDR, ipaddr, 0); if (!devp->private) devp->private = (DevInfo *)safe_malloc(sizeof(DevInfo)); @@ -380,13 +303,9 @@ netconfig: SAFE_STRCPY(di->ipaddr, ipaddr); SAFE_STRCPY(di->netmask, netmask); SAFE_STRCPY(di->extras, extras); - di->use_dhcp = use_dhcp; + sprintf(temp, "inet %s %s netmask %s", ipaddr, extras, netmask); sprintf(ifn, "%s%s", VAR_IFCONFIG, devp->name); - if (use_dhcp) - sprintf(temp, "DHCP"); - else - sprintf(temp, "inet %s %s netmask %s", ipaddr, extras, netmask); variable_set2(ifn, temp, 1); ifaces = variable_get(VAR_INTERFACES); if (!ifaces) @@ -396,8 +315,9 @@ netconfig: sprintf(ifn, "%s %s", devp->name, ifaces); variable_set2(VAR_INTERFACES, ifn, 1); } - if (!use_dhcp) - configResolv(NULL); /* XXX this will do it on the MFS copy XXX */ + if (ipaddr[0]) + variable_set2(VAR_IPADDR, ipaddr, 0); + configResolv(NULL); /* XXX this will do it on the MFS copy XXX */ ret = DITEM_SUCCESS; } else @@ -476,7 +396,7 @@ tcpMenuSelect(dialogMenuItem *self) Device *tmp; tmp = tcpDeviceSelect(); - if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name)) + if (tmp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name)) if (!tmp->init(tmp)) msgConfirm("Initialization of %s device failed.", tmp->name); return DITEM_SUCCESS | DITEM_RESTORE; |