Browse Source

Refactor dhcp.c code to use an argument list instead of an string.

r59449
tags/1.50
Otavio Salvador 12 years ago
parent
commit
6634a94856
2 changed files with 40 additions and 10 deletions
  1. +4
    -0
      debian/changelog
  2. +36
    -10
      dhcp.c

+ 4
- 0
debian/changelog View File

@@ -1,5 +1,6 @@
netcfg (1.50) UNRELEASED; urgency=low

[ Christian Perrier ]
* No longer add ff02::3 to /etc/hosts
Thanks to Marco d'Itri for the proposed change
Closes: #533384
@@ -14,6 +15,9 @@ netcfg (1.50) UNRELEASED; urgency=low
* check_kill_switch is Linux-specific; provide a stub implementation for
non-Linux systems.

[ Otavio Salvador ]
* Refactor dhcp.c code to use an argument list instead of an string.

-- Christian Perrier <bubulle@debian.org> Thu, 18 Jun 2009 06:11:33 +0200

netcfg (1.49) unstable; urgency=low


+ 36
- 10
dhcp.c View File

@@ -23,10 +23,16 @@

#define DHCP_OPTION_LEN 1236 /* pump 0.8.24 defines a max option size of 57,
dhcp 2.0pl5 uses 1222, dhcp3 3.0.6 uses 1236 */
#define DHCLIENT_REQUEST_DEFAULTS \
"subnet-mask, broadcast-address, time-offset, routers, domain-name, \
domain-name-servers, host-name"
#define DHCLIENT_REQUEST_EXTRAS "ntp-servers"

const char* dhclient_request_options[] = { "subnet-mask",
"broadcast-address",
"time-offset",
"routers",
"domain-name",
"domain-name-servers",
"host-name",
"ntp-servers", /* extra */
NULL };

static int dhcp_exit_status = 1;
static pid_t dhcp_pid = -1;
@@ -115,6 +121,7 @@ static void dhcp_client_sigchld(int sig __attribute__ ((unused)))
int start_dhcp_client (struct debconfclient *client, char* dhostname)
{
FILE *dc = NULL;
const char **ptr;
enum { DHCLIENT, DHCLIENT3, PUMP } dhcp_client;
if (access("/var/lib/dhcp3", F_OK) == 0)
@@ -145,11 +152,20 @@ int start_dhcp_client (struct debconfclient *client, char* dhostname)
case DHCLIENT:
/* First, set up dhclient.conf */
if ((dc = file_open(DHCLIENT_CONF, "w"))) {
fprintf(dc, "send dhcp-class-identifier \"d-i\";\n" );
fprintf(dc, "request " DHCLIENT_REQUEST_DEFAULTS", " \
DHCLIENT_REQUEST_EXTRAS";\n" );
fprintf(dc, "send dhcp-class-identifier \"d-i\";\n");
fprintf(dc, "request ");

for (ptr = dhclient_request_options; *ptr; ptr++) {
fprintf(dc, *ptr);

/* look ahead to see if it is the last entry */
if (*(ptr + 1))
fprintf(dc, ", ");
else
fprintf(dc, ";\n");
}

if (dhostname) {
fprintf(dc, "send host-name \"%s\";\n", dhostname);
}
@@ -164,8 +180,18 @@ int start_dhcp_client (struct debconfclient *client, char* dhostname)
if ((dc = file_open(DHCLIENT3_CONF, "w"))) {
fprintf(dc, "send vendor-class-identifier \"d-i\";\n" );
fprintf(dc, "request " DHCLIENT_REQUEST_DEFAULTS", " \
DHCLIENT_REQUEST_EXTRAS";\n" );
fprintf(dc, "request ");

for (ptr = dhclient_request_options; *ptr; ptr++) {
fprintf(dc, *ptr);

/* look ahead to see if it is the last entry */
if (*(ptr + 1))
fprintf(dc, ", ");
else
fprintf(dc, ";\n");
}

if (dhostname) {
fprintf(dc, "send host-name \"%s\";\n", dhostname);
}


Loading…
Cancel
Save