diff options
author | Erik Troan <ewt@redhat.com> | 1999-08-08 14:04:09 +0000 |
---|---|---|
committer | Erik Troan <ewt@redhat.com> | 1999-08-08 14:04:09 +0000 |
commit | dd72b2827c5d572fd1d0c78b8893cc04e3987369 (patch) | |
tree | e19479bc0f9e20d98f79b5a974e2e73cadc32f73 /loader/net.c | |
parent | d82ac2b39e519eeea76c40973833d02e22ddc1b5 (diff) | |
download | anaconda-dd72b2827c5d572fd1d0c78b8893cc04e3987369.tar.gz anaconda-dd72b2827c5d572fd1d0c78b8893cc04e3987369.tar.xz anaconda-dd72b2827c5d572fd1d0c78b8893cc04e3987369.zip |
added hostname checking and resolv.conf creation
Diffstat (limited to 'loader/net.c')
-rw-r--r-- | loader/net.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/loader/net.c b/loader/net.c index 77c12b327..1a3dbfdb5 100644 --- a/loader/net.c +++ b/loader/net.c @@ -1,9 +1,12 @@ #include <arpa/inet.h> +#include <errno.h> +#include <resolv.h> #include <net/if.h> #include <newt.h> #include <stdlib.h> #include <string.h> +#include "isys/dns.h" #include "pump/pump.h" #include "lang.h" @@ -277,6 +280,9 @@ int readNetConfig(char * device, struct networkDeviceConfig * cfg, int flags) { newtPopWindow(); + findHostAndDomain(cfg, flags); + writeResolvConf(cfg); + return 0; } @@ -311,3 +317,71 @@ int writeNetInfo(const char * fn, struct networkDeviceConfig * dev) { return 0; } + +int writeResolvConf(struct networkDeviceConfig * net) { + char * filename = "/etc/resolv.conf"; + FILE * f; + int i; + + if (!(net->dev.set & PUMP_NETINFO_HAS_DOMAIN) && !net->dev.numDns) + return LOADER_ERROR; + + f = fopen(filename, "w"); + if (!f) { + logMessage("Cannot create %s: %s\n", filename, strerror(errno)); + return LOADER_ERROR; + } + + if (net->dev.set & PUMP_NETINFO_HAS_DOMAIN) + fprintf(f, "search %s\n", net->dev.domain); + + for (i = 0; i < net->dev.numDns; i++) + fprintf(f, "nameserver %s\n", inet_ntoa(net->dev.dnsServers[i])); + + fclose(f); + + res_init(); /* reinit the resolver so DNS changes take affect */ + + return 0; +} + +int findHostAndDomain(struct networkDeviceConfig * dev, int flags) { + char ips[50]; + char * name, * chptr; + + if (!FL_TESTING(flags)) { + writeResolvConf(dev); + strcpy(ips, inet_ntoa(dev->dev.ip)); + } + + if (!(dev->dev.set & PUMP_NETINFO_HAS_HOSTNAME)) { + winStatus(40, 3, _("Hostname"), + _("Determining host name and domain...")); + name = mygethostbyaddr(ips); + if (name) name = mygethostbyaddr(ips); + newtPopWindow(); + + if (!name) { + logMessage("reverse name lookup failed"); + return 1; + } + + logMessage("reverse name lookup worked"); + + dev->dev.hostname = strdup(name); + dev->dev.set |= PUMP_NETINFO_HAS_HOSTNAME; + } else { + name = dev->dev.hostname; + } + + if (!(dev->dev.set & PUMP_NETINFO_HAS_DOMAIN)) { + for (chptr = name; *chptr && (*chptr != '.'); chptr++) ; + if (*chptr == '.') { + if (dev->dev.domain) free(dev->dev.domain); + dev->dev.domain = strdup(chptr + 1); + dev->dev.set |= PUMP_NETINFO_HAS_DOMAIN; + } + } + + return 0; +} |