Browse Source

fix seed_hostname_from_dns for DHCP. static is a hairier issue which will be dealt with soon

r15425
tags/0.64
Joshua Kwan 17 years ago
parent
commit
24a1c32a5d
3 changed files with 35 additions and 15 deletions
  1. +25
    -6
      dhcp.c
  2. +8
    -8
      netcfg-common.c
  3. +2
    -1
      netcfg.h

+ 25
- 6
dhcp.c View File

@@ -14,7 +14,9 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <time.h>
#include <netdb.h>

@@ -24,10 +26,8 @@ int dhcp_running = 0, dhcp_exit_status = 1;
static void dhcp_client_sigchld(int sig __attribute__ ((unused)))
{
if (dhcp_running == 1) {
di_info("in sighandler, PID = %d", dhcp_pid);
dhcp_running = 0;
wait(&dhcp_exit_status);
di_info("exited");
}
}

@@ -95,8 +95,6 @@ int start_dhcp_client (struct debconfclient *client, char* dhostname)

if ((dhcp_pid = fork()) == 0) /* child */
{
di_info("in child, PID = %d", getpid());
/* get dhcp lease */
switch (dhcp_client)
{
@@ -159,7 +157,6 @@ int start_dhcp_client (struct debconfclient *client, char* dhostname)
}
else
{
di_info("in parent, PID = %d, child PID = %d", getpid(), dhcp_pid);
dhcp_running = 1;
signal(SIGCHLD, &dhcp_client_sigchld);
return 0;
@@ -343,7 +340,29 @@ int netcfg_activate_dhcp (struct debconfclient *client)
if (gethostname(buf, sizeof(buf)) == 0 && strcmp(buf, "(none)") != 0)
debconf_set(client, "netcfg/get_hostname", buf);
else
seed_hostname_from_dns(client);
{
int skfd = socket(AF_INET, SOCK_DGRAM, 0);

if (skfd)
{
struct ifreq ifr;
struct in_addr d_ipaddr = { 0 };
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, interface, IFNAMSIZ);
if (ioctl(skfd, SIOCGIFADDR, &ifr) == 0)
{
d_ipaddr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;
seed_hostname_from_dns(client, &d_ipaddr);
}
else
di_error("ioctl failed (%s)", strerror(errno));

close(skfd);
}
else
di_error("skfd could not be allocated!");
}

state = HOSTNAME;
}


+ 8
- 8
netcfg-common.c View File

@@ -530,10 +530,8 @@ void netcfg_write_common(const char *prebaseconfig, struct in_addr ipaddress,
}


void deconfigure_network(void) {

char buf[256];

void deconfigure_network(void)
{
/* deconfiguring network interfaces */
ifconfig_down("lo");
ifconfig_down(interface);
@@ -551,7 +549,7 @@ void loop_setup(void)
di_exec_shell_log("ifconfig lo 127.0.0.1 up");
}

void seed_hostname_from_dns (struct debconfclient * client)
void seed_hostname_from_dns (struct debconfclient * client, struct in_addr *ipaddr)
{
struct addrinfo hints = {
.ai_family = PF_UNSPEC,
@@ -561,19 +559,21 @@ void seed_hostname_from_dns (struct debconfclient * client)
};
struct addrinfo *res;
struct sockaddr tmp;
char ip[16]; /* 255.255.255.255 + 1 */
char ip[INET_ADDRSTRLEN] = { 0 };
int err;

/* convert ipaddress into a char* */
inet_ntop(AF_INET, (void*)&ipaddress, ip, 16);
inet_ntop(AF_INET, (void*)ipaddr, ip, sizeof(ip));

/* attempt resolution */
err = getaddrinfo(ip, NULL, &hints, &res);

/* got it? */
if (!err && res->ai_canonname && !empty_str(res->ai_canonname) &&
if (err == 0 && res->ai_canonname && !empty_str(res->ai_canonname) &&
inet_pton(AF_INET, res->ai_canonname, &tmp) == 0)
debconf_set(client, "netcfg/get_hostname", res->ai_canonname);

freeaddrinfo(res);
}

void ifconfig_up (char* iface)


+ 2
- 1
netcfg.h View File

@@ -76,6 +76,7 @@ extern int netcfg_get_domain(struct debconfclient *client, char **domain);
extern int netcfg_get_dhcp(struct debconfclient *client);

extern int netcfg_get_static(struct debconfclient *client);
extern int do_hostname_jig (struct debconfclient *client);

extern int netcfg_activate_dhcp(struct debconfclient *client);

@@ -104,6 +105,6 @@ extern void ifconfig_up (char*);
extern void ifconfig_down (char*);

extern void loop_setup(void);
extern void seed_hostname_from_dns(struct debconfclient *client);
extern void seed_hostname_from_dns(struct debconfclient *client, struct in_addr * ipaddress);

#endif /* _NETCFG_H_ */

Loading…
Cancel
Save