Browse Source

Clean up code, especially the use of empty_str().

Handle the case where there is no network interface: Ask for the hostname
and write basic /etc/hostname, /etc/hosts and /etc/network/interfaces files.

r17194
tags/0.71
Thomas Hood 17 years ago
parent
commit
0d45297bd4
6 changed files with 81 additions and 36 deletions
  1. +12
    -3
      debian/changelog
  2. +12
    -3
      netcfg-common.c
  3. +13
    -4
      netcfg-dhcp.c
  4. +13
    -4
      netcfg-static.c
  5. +13
    -4
      netcfg.c
  6. +18
    -18
      static.c

+ 12
- 3
debian/changelog View File

@@ -8,6 +8,17 @@ netcfg (0.71) UNRELEASED; urgency=low
* Thomas Hood
- Change interfaces options that use underscore to hyphens. No loss
of functionality. (Closes: #255185)
- *.c:
+ Test for NULL pointers before using empty_str()
- netcfg.c, netcfg-dhcp.c, netcfg-static.c
+ Handle the case where there are no interfaces. Just ask for a
hostname and write basic /etc/network/interfaces and /etc/hosts
files. (Closes: #243543)
- netcfg-common.c:
+ netcfg_get_interface(): Don't exit if there are no interfaces.
Instead just return with variables set to 0.
+ netcfg_write_common(): write basic /etc/network/interfaces and
/etc/hosts files even if the ipaddress is 0.
- static.c:
+ Add resolvconf support (Closes: #255187)
+ Add comments to /e/n/i about which packages implement which options
@@ -32,9 +43,7 @@ netcfg (0.71) UNRELEASED; urgency=low
. Always use spaces for indentation
. Improve comments
. Reorder state machine states
. Move kill_dhcp_client() to top of file
- prebaseconfig
+ Don't cp /etc/dhclient.conf and /etc/dhcp3/dhclient.conf to target
. Move some functions around

-- Joshua Kwan <joshk@triplehelix.org> Fri, 18 Jun 2004 23:26:15 -0700



+ 12
- 3
netcfg-common.c View File

@@ -524,15 +524,25 @@ void netcfg_write_loopback (void)
}
}

/*
* ipaddress.s_addr may be 0
* domain may be null
* interface may be null
* hostname may _not_ be null
*/
void netcfg_write_common(struct in_addr ipaddress, char *hostname, char *domain)
{
FILE *fp;

if (!hostname)
return;

if ((fp = file_open(INTERFACES_FILE, "w"))) {
fprintf(fp, HELPFUL_COMMENT);
fprintf(fp, "\n# The loopback network interface\n");
fprintf(fp, "auto lo\n");
fprintf(fp, "iface lo inet loopback\n");
if (iface_is_hotpluggable(interface)) {
if (interface && iface_is_hotpluggable(interface)) {
fprintf(fp, "\n");
fprintf(fp, "# This is a list of hotpluggable network interfaces.\n");
fprintf(fp, "# They will be activated automatically by the "
@@ -541,7 +551,6 @@ void netcfg_write_common(struct in_addr ipaddress, char *hostname, char *domain)
fprintf(fp, "\tscript grep\n");
fprintf(fp, "\tmap %s\n", interface);
}

fclose(fp);
}

@@ -561,7 +570,7 @@ void netcfg_write_common(struct in_addr ipaddress, char *hostname, char *domain)
if (ipaddress.s_addr)
{
inet_ntop (AF_INET, &ipaddress, ptr1, sizeof(ptr1));
if (!empty_str(domain))
if (domain && !empty_str(domain))
fprintf(fp, "\n%s\t%s.%s\t%s\n", ptr1, hostname, domain, hostname);
else
fprintf(fp, "\n%s\t%s\n", ptr1, hostname);


+ 13
- 4
netcfg-dhcp.c View File

@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
static struct debconfclient *client;
static int requested_wireless_tools = 0;

enum { BACKUP, GET_INTERFACE, WCONFIG, WCONFIG_WEP, WCONFIG_ESSID, QUIT } state = GET_INTERFACE;
enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, WCONFIG, WCONFIG_WEP, WCONFIG_ESSID, QUIT } state = GET_INTERFACE;

/* initialize libd-i */
di_system_init("netcfg-dhcp");
@@ -56,9 +56,7 @@ int main(int argc, char *argv[])
if (netcfg_get_interface(client, &interface, &num_interfaces))
state = BACKUP;
else if (! interface || ! num_interfaces)
{
state = BACKUP;
}
state = GET_HOSTNAME_ONLY;
else
{
if (is_wireless_iface(interface))
@@ -67,6 +65,17 @@ int main(int argc, char *argv[])
state = QUIT;
}
break;
case GET_HOSTNAME_ONLY:
if(netcfg_get_hostname(client, "netcfg/get_hostname", &hostname, 0))
state = BACKUP;
else
{
struct in_addr null_ipaddress;
null_ipaddress.s_addr = 0;
netcfg_write_common(null_ipaddress, hostname, NULL);
return 0;
}
break;
case WCONFIG:
if (requested_wireless_tools == 0)
{


+ 13
- 4
netcfg-static.c View File

@@ -33,7 +33,7 @@ int main(int argc, char** argv)
static struct debconfclient *client;
static int requested_wireless_tools = 0;

enum { BACKUP, GET_INTERFACE, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT} state = GET_INTERFACE;
enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT} state = GET_INTERFACE;
/* initialize libd-i */
di_system_init("netcfg-static");
@@ -54,9 +54,7 @@ int main(int argc, char** argv)
if (netcfg_get_interface(client, &interface, &num_interfaces))
state = BACKUP;
else if (! interface || ! num_interfaces)
{
state = BACKUP;
}
state = GET_HOSTNAME_ONLY;
else
{
if (is_wireless_iface(interface))
@@ -65,6 +63,17 @@ int main(int argc, char** argv)
state = GET_STATIC;
}
break;
case GET_HOSTNAME_ONLY:
if(netcfg_get_hostname(client, "netcfg/get_hostname", &hostname, 0))
state = BACKUP;
else
{
struct in_addr null_ipaddress;
null_ipaddress.s_addr = 0;
netcfg_write_common(null_ipaddress, hostname, NULL);
return 0;
}
break;
case GET_STATIC:
if (netcfg_get_static(client))
state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE;


+ 13
- 4
netcfg.c View File

@@ -58,7 +58,7 @@ response_t netcfg_get_method(struct debconfclient *client)
int main(int argc, char *argv[])
{
int num_interfaces = 0;
enum { BACKUP, GET_INTERFACE, GET_METHOD, GET_DHCP, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT } state = GET_INTERFACE;
enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_METHOD, GET_DHCP, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT } state = GET_INTERFACE;
static struct debconfclient *client;
static int requested_wireless_tools = 0;
response_t res;
@@ -93,9 +93,7 @@ int main(int argc, char *argv[])
if(netcfg_get_interface(client, &interface, &num_interfaces))
state = BACKUP;
else if (! interface || ! num_interfaces)
{
state = BACKUP;
}
state = GET_HOSTNAME_ONLY;
else
{
if (is_wireless_iface (interface))
@@ -104,6 +102,17 @@ int main(int argc, char *argv[])
state = GET_METHOD;
}
break;
case GET_HOSTNAME_ONLY:
if(netcfg_get_hostname(client, "netcfg/get_hostname", &hostname, 0))
state = BACKUP;
else
{
struct in_addr null_ipaddress;
null_ipaddress.s_addr = 0;
netcfg_write_common(null_ipaddress, hostname, NULL);
return 0;
}
break;
case GET_METHOD:
if ((res = netcfg_get_method(client)) == GO_BACK)
state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE;


+ 18
- 18
static.c View File

@@ -317,6 +317,24 @@ static int netcfg_write_static(char *domain, struct in_addr nameservers[])
return -1;
}

void netcfg_rewrite_resolv (char* domain, struct in_addr* nameservers)
{
FILE* fp = NULL;
char ptr1[INET_ADDRSTRLEN];

if ((fp = file_open(RESOLV_FILE, "w"))) {
int i = 0;
if (domain && !empty_str(domain))
fprintf(fp, "search %s\n", domain);

while (nameservers[i].s_addr)
fprintf(fp, "nameserver %s\n",
inet_ntop (AF_INET, &nameservers[i++], ptr1, sizeof (ptr1)));

fclose(fp);
}
}

int netcfg_activate_static(struct debconfclient *client)
{
int rv = 0, masksize;
@@ -512,21 +530,3 @@ int netcfg_get_static(struct debconfclient *client)
}
return 0;
}

void netcfg_rewrite_resolv (char* domain, struct in_addr* nameservers)
{
FILE* fp = NULL;
char ptr1[INET_ADDRSTRLEN];

if ((fp = file_open(RESOLV_FILE, "w"))) {
int i = 0;
if (!empty_str(domain))
fprintf(fp, "search %s\n", domain);

while (nameservers[i].s_addr)
fprintf(fp, "nameserver %s\n",
inet_ntop (AF_INET, &nameservers[i++], ptr1, sizeof (ptr1)));

fclose(fp);
}
}

Loading…
Cancel
Save