
10 changed files with 411 additions and 79 deletions
@ -0,0 +1,18 @@ |
|||
PREFIX=$(DESTDIR)/usr/ |
|||
CFLAGS=-Wall -Os -fomit-frame-pointer |
|||
INSTALL=install |
|||
STRIPTOOL=strip |
|||
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment |
|||
|
|||
all: netcfg |
|||
$(STRIP) netcfg |
|||
size netcfg |
|||
|
|||
netcfg: netcfg.c debconf.o |
|||
|
|||
install: |
|||
mkdir -p $(PREFIX)/bin/ |
|||
$(INSTALL) netcfg $(PREFIX)/bin/ |
|||
|
|||
clean: |
|||
rm -f *.o netcfg |
@ -0,0 +1,8 @@ |
|||
* menutest : check for existance and size, of conf files (any other checks?) |
|||
* search for network interfaces and allow the user to choose which one they want to configure |
|||
* put in checks so the user can't enter data that is clearly invalid |
|||
* dhcp: either another module, or in here |
|||
* fall back to safe defaults if the user doesn't enter a particular value (ex. gateway) |
|||
* create config dirs if they don't exist |
|||
* use the the debconf library rather than our own debconf.[ch] |
|||
* do other sorts of network configurations (pcmcia) |
@ -0,0 +1,54 @@ |
|||
/*
|
|||
* Debconf communication routines. |
|||
*/ |
|||
|
|||
#include "debconf.h" |
|||
|
|||
#include <stdio.h> |
|||
#include <stdarg.h> |
|||
#include <string.h> |
|||
#include <stdlib.h> |
|||
|
|||
/* Holds the textual return code of the last command. */ |
|||
char *text; |
|||
|
|||
/* Returns the last command's textual return code. */ |
|||
char *debconf_ret (void) { |
|||
return text; |
|||
} |
|||
|
|||
/*
|
|||
* Talks to debconf and returns the numeric return code. |
|||
* Unfortunatly, you need to use a NULL - terminated list of commands. |
|||
*/ |
|||
int debconf_command (const char *command, ...) { |
|||
char buf[DEBCONF_BUFSIZE]; |
|||
va_list ap; |
|||
char *c; |
|||
|
|||
fputs(command, stdout); |
|||
va_start(ap, command); |
|||
while ((c = va_arg(ap, char *)) != NULL) { |
|||
fputs(" ", stdout); |
|||
fputs(c, stdout); |
|||
} |
|||
va_end(ap); |
|||
fputs("\n", stdout); |
|||
fflush(stdout); /* make sure debconf sees it to prevent deadlock */ |
|||
|
|||
fgets(buf, DEBCONF_BUFSIZE, stdin); |
|||
buf[strlen(buf)-1] = 0; |
|||
if (strlen(buf)) { |
|||
strtok(buf, " \t\n"); |
|||
text=strtok(NULL, "\n"); |
|||
return atoi(buf); |
|||
} |
|||
else { |
|||
/*
|
|||
* Nothing was entered; never really happens except during |
|||
* debugging. |
|||
*/ |
|||
text=buf; |
|||
return 0; |
|||
} |
|||
} |
@ -0,0 +1,5 @@ |
|||
int debconf_command (const char *, ...); |
|||
char *debconf_ret (void); |
|||
|
|||
#define DEBCONF_BUFSIZE 4096 |
|||
|
@ -0,0 +1,10 @@ |
|||
netcfg (0.1-1) unstable; urgency=low |
|||
|
|||
* Initial Release. |
|||
|
|||
-- David Whedon <dwhedon@gordian.com> Fri, 8 Dec 2000 22:19:20 -0800 |
|||
|
|||
Local variables: |
|||
mode: debian-changelog |
|||
add-log-mailing-address "dwhedon@gordian.com" |
|||
End: |
@ -0,0 +1,14 @@ |
|||
Source: netcfg |
|||
Section: debian-installer |
|||
Priority: optional |
|||
Maintainer: David Whedon <dwhedon@gordian.com> |
|||
Build-Depends: debhelper |
|||
Standards-Version: 3.1.1 |
|||
|
|||
Package: netcfg |
|||
Architecture: any |
|||
Depends: ${shlibs:Depends} |
|||
Provides: network-configuration |
|||
XBC-Installer-Menu-Item: 1 |
|||
Description: Configure the network |
|||
This package configures the network. |
@ -0,0 +1,7 @@ |
|||
This is a network configuration for Debian/GNU Linux installer. |
|||
|
|||
Author(s): David Whedon, Karl Hammar, Aspö Data |
|||
|
|||
Copyright 2000 David Whedon <dwhedon@gordian.com> |
|||
|
|||
The copyright of this package is GPL, version 2 or later. |
@ -0,0 +1,97 @@ |
|||
#!/usr/bin/make -f |
|||
# Sample debian/rules that uses debhelper. |
|||
# GNU copyright 1997 to 1999 by Joey Hess. |
|||
|
|||
# Uncomment this to turn on verbose mode. |
|||
#export DH_VERBOSE=1 |
|||
|
|||
|
|||
PACKAGES=$(shell dh_listpackages) |
|||
VERSION=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2) |
|||
ARCH=$(shell dpkg --print-architecture) |
|||
FILENAME=$(PACKAGE)_$(VERSION)_$(ARCH).udeb |
|||
PRIORITY=$(shell grep ^Priority: debian/control | cut -d ' ' -f 2) |
|||
|
|||
|
|||
# This is the debhelper compatability version to use. |
|||
export DH_COMPAT=2 |
|||
|
|||
configure: configure-stamp |
|||
configure-stamp: |
|||
dh_testdir |
|||
# Add here commands to configure the package. |
|||
|
|||
|
|||
touch configure-stamp |
|||
|
|||
build: configure-stamp build-stamp |
|||
build-stamp: |
|||
dh_testdir |
|||
|
|||
# Add here commands to compile the package. |
|||
$(MAKE) |
|||
#/usr/bin/docbook-to-man debian/ddetect.sgml > ddetect.1 |
|||
|
|||
touch build-stamp |
|||
|
|||
clean: |
|||
dh_testdir |
|||
dh_testroot |
|||
rm -f build-stamp configure-stamp |
|||
|
|||
# Add here commands to clean up after the build process. |
|||
-$(MAKE) clean |
|||
|
|||
dh_clean |
|||
|
|||
install: build |
|||
dh_testdir |
|||
dh_testroot |
|||
dh_clean -k |
|||
dh_installdirs |
|||
$(foreach PACKAGE, $(PACKAGES), \ |
|||
( $(MAKE) install PROGS=$(PACKAGE) DESTDIR=`pwd`/debian/$(PACKAGE)) ; ) |
|||
|
|||
|
|||
# Build architecture-independent files here. |
|||
binary-indep: build install |
|||
# We have nothing to do by default. |
|||
|
|||
# Build architecture-dependent files here. |
|||
binary-arch: build install |
|||
# dh_testversion |
|||
dh_testdir |
|||
dh_testroot |
|||
dh_installdebconf |
|||
# dh_installdocs |
|||
# dh_undocumented ddetect.1 |
|||
# dh_installchangelogs |
|||
# dh_link |
|||
dh_strip |
|||
dh_compress |
|||
dh_fixperms |
|||
# You may want to make some executables suid here. |
|||
# dh_suidregister |
|||
# dh_makeshlibs |
|||
dh_installdeb |
|||
# dh_perl |
|||
dh_shlibdeps |
|||
dh_gencontrol -- -fdebian/files~ # to make a .udeb |
|||
# dh_gencontrol |
|||
$(foreach PACKAGE, $(PACKAGES), \ |
|||
(dpkg-distaddfile $(PACKAGE)_$(VERSION)_$(ARCH).udeb \ |
|||
debian-installer $(PRIORITY) ) ; ) |
|||
dh_md5sums |
|||
# I think the following should work, but it doesn't, so I revert to manually |
|||
# calling dpkg-deb |
|||
# $(foreach PACKAGE, $(PACKAGES), \ |
|||
# (dh_builddeb --filename=$(PACKAGE)_$(VERSION)_$(ARCH).udeb -- $(PACKAGE) \ |
|||
# ); ) # to make a .udeb |
|||
$(foreach PACKAGE, $(PACKAGES), \ |
|||
(cd debian ; \ |
|||
dpkg-deb -b $(PACKAGE) ../../$(PACKAGE)_$(VERSION)_$(ARCH).udeb \ |
|||
); ) # make a .udeb |
|||
# dh_builddeb |
|||
|
|||
binary: binary-indep binary-arch |
|||
.PHONY: build clean binary-indep binary-arch binary install configure |
@ -1,120 +1,215 @@ |
|||
/*
|
|||
netcfg.c : Configures the network |
|||
|
|||
*/ |
|||
|
|||
#include <string.h> |
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <unistd.h> |
|||
#include <sys/types.h> |
|||
#include <sys/stat.h> |
|||
#include "debconf.h" |
|||
|
|||
#define IP4_ADDR_SZ (4) |
|||
struct ip4_addr |
|||
{ |
|||
int i[IP4_ADDR_SZ]; |
|||
} |
|||
ip4_addr_t; |
|||
char *host = NULL; |
|||
char *hostname = NULL; |
|||
char *domain = NULL; |
|||
u_int32_t ipaddress = 0; |
|||
u_int32_t network_address = 0; |
|||
u_int32_t netmask = 0; |
|||
u_int32_t gateway = 0; |
|||
|
|||
ip4_addr_t ipaddr = { {192, 168, 1, 1} }; |
|||
ip4_addr_t netmask = { {255, 255, 255, 0} }; |
|||
ip4_addr_t network = { {192, 168, 1, 0} }; |
|||
ip4_addr_t broadcast = { {192, 168, 1, 255} }; |
|||
ip4_addr_t gateway = { {0, 0, 0, 0} }; |
|||
//#define INTERFACES_FILE "/etc/network/interfaces"
|
|||
#define INTERFACES_FILE "etc/network/interfaces" |
|||
|
|||
|
|||
/*
|
|||
* Checks a string with an IPv4-address for validity and converts it into an |
|||
* ip4_addr_t type; |
|||
*/ |
|||
int |
|||
atoIP4 (char *addr, ip4_addr_t * iaddr) |
|||
|
|||
/**
|
|||
* dot2num and num2dot |
|||
* Copyright: Karl Hammar, Aspö Data |
|||
*/ |
|||
char * |
|||
dot2num (u_int32_t * num, char *dot) |
|||
{ |
|||
char *end; |
|||
char *tmp_a; |
|||
char *current = strdup (addr); |
|||
char *next = NULL; |
|||
int ix = 0; |
|||
int tmp; |
|||
|
|||
tmp_a = current; |
|||
end = current + strlen (current) + 1; |
|||
while (next != end) |
|||
char *p = dot - 1; |
|||
char *e; |
|||
int ix; |
|||
unsigned long val; |
|||
|
|||
if (!dot) |
|||
return NULL; |
|||
*num = 0; |
|||
for (ix = 0; ix < 4; ix++) |
|||
{ |
|||
next = strchr (current, '.'); |
|||
if (next == NULL) |
|||
next = end; |
|||
else |
|||
{ |
|||
*next = '\0'; |
|||
next++; |
|||
} |
|||
*num <<= 8; |
|||
p++; |
|||
val = strtoul (p, &e, 10); |
|||
if (e == p) |
|||
val = 0; |
|||
else if (val > 255) |
|||
return NULL; |
|||
*num += val; |
|||
/*printf("%#8x, %#2x\n", *num, val); */ |
|||
if (ix < 3 && *e != '.') |
|||
return NULL; |
|||
p = e; |
|||
} |
|||
|
|||
if (ix == IP4_ADDR_SZ) |
|||
{ |
|||
free (tmp_a); |
|||
return 255; |
|||
} |
|||
else |
|||
{ |
|||
tmp = atoi (current); |
|||
if ((tmp < 0) || (tmp > 255)) |
|||
{ |
|||
free (tmp_a); |
|||
return 255; |
|||
} |
|||
iaddr->i[ix++] = tmp; |
|||
current = next; |
|||
} |
|||
return p; |
|||
} |
|||
|
|||
|
|||
void |
|||
num2dot (u_int32_t num, char *dot) |
|||
{ |
|||
/* dot MUST point to an char arr[16] or longer area */ |
|||
int byte[4]; |
|||
int ix; |
|||
|
|||
if (!dot) |
|||
return; |
|||
for (ix = 3; ix >= 0; ix--) |
|||
{ |
|||
byte[ix] = num & 0xff; |
|||
num >>= 8; |
|||
} |
|||
free (tmp_a); |
|||
if (ix != IP4_ADDR_SZ) |
|||
return 255; |
|||
return 0; |
|||
sprintf (dot, "%d.%d.%d.%d", byte[0], byte[1], byte[2], byte[3]); |
|||
} |
|||
|
|||
|
|||
|
|||
static_network_cfg () |
|||
|
|||
void |
|||
get_static_cfg (void) |
|||
{ |
|||
int ix; |
|||
int finished = 0; |
|||
char *ptr; |
|||
|
|||
|
|||
debconf_command ("INPUT", "high", "netcfg/get_hostname", NULL); |
|||
do |
|||
{ |
|||
|
|||
|
|||
debconf_command ("INPUT", "critical", "netcfg/get_hostname", NULL); |
|||
debconf_command ("GO", NULL); |
|||
debconf_command ("GET", "netcfg/get_hostname", NULL); |
|||
hostname = debconf_ret (); |
|||
debconf_command ("subst", "netcfg/confirm_static_cfg", "hostname", |
|||
hostname, NULL); |
|||
|
|||
debconf_command ("INPUT", "critical", "netcfg/get_domain", NULL); |
|||
debconf_command ("GO", NULL); |
|||
debconf_command ("GET", "netcfg/get_domain", NULL); |
|||
domain = debconf_ret (); |
|||
debconf_command ("subst", "netcfg/confirm_static_cfg", "domain", domain, |
|||
NULL); |
|||
|
|||
do { |
|||
debconf_command ("INPUT", "critical", "netcfg/get_ipaddress", NULL); |
|||
debconf_command ("GO", NULL); |
|||
} while ( atoIP4(debconf_command ("GET", "netcfg/get_ipaddress", NULL), &ipaddress)) ; |
|||
debconf_command ("GET", "netcfg/get_ipaddress", NULL); |
|||
ptr = debconf_ret (); |
|||
debconf_command ("subst", "netcfg/confirm_static_cfg", "ipaddress", ptr, |
|||
NULL); |
|||
dot2num (&ipaddress, ptr); |
|||
|
|||
do { |
|||
debconf_command ("INPUT", "critical", "netcfg/get_netmask", NULL); |
|||
debconf_command ("GO", NULL); |
|||
} while ( atoIP4(debconf_command ("GET", "netcfg/get_netmask", NULL), &netmask)) ; |
|||
debconf_command ("GET", "netcfg/get_netmask", NULL); |
|||
ptr = debconf_ret (); |
|||
debconf_command ("subst", "netcfg/confirm_static_cfg", "netmask", ptr, |
|||
NULL); |
|||
dot2num (&netmask, debconf_ret ()); |
|||
|
|||
debconf_command ("INPUT", "critical", "netcfg/get_gateway", NULL); |
|||
debconf_command ("GO", NULL); |
|||
debconf_command ("GET", "netcfg/get_gateway", NULL); |
|||
ptr = debconf_ret (); |
|||
debconf_command ("subst", "netcfg/confirm_static_cfg", "gateway", ptr, |
|||
NULL); |
|||
dot2num (&gateway, ptr); |
|||
|
|||
|
|||
debconf_command ("INPUT", "high", "netcfg/confirm_static_cfg", NULL); |
|||
debconf_command ("GO", NULL); |
|||
debconf_command ("GET", "netcfg/confirm_static_cfg", NULL); |
|||
ptr = debconf_ret (); |
|||
|
|||
if (strstr (ptr, "true")) |
|||
finished = 1; |
|||
else |
|||
{ |
|||
debconf_command ("fset", "netcfg/get_hostname", "seen", "false", |
|||
NULL); |
|||
debconf_command ("fset", "netcfg/get_domain", "seen", "false", |
|||
NULL); |
|||
debconf_command ("fset", "netcfg/get_ipaddress", "seen", "false", |
|||
NULL); |
|||
debconf_command ("fset", "netcfg/get_netmask", "seen", "false", |
|||
NULL); |
|||
debconf_command ("fset", "netcfg/get_gateway", "seen", "false", |
|||
NULL); |
|||
debconf_command ("fset", "netcfg/confirm_static_cfg", "seen", |
|||
"false", NULL); |
|||
} |
|||
|
|||
/*
|
|||
* Generate the network, broadcast and default gateway address |
|||
* Default gateway address is network with last number set to "1", |
|||
* or "2" if "1" is the local address. |
|||
*/ |
|||
for (ix = 0; ix < IP4_ADDR_SZ; ix++) |
|||
{ |
|||
gateway.i[ix] = network.i[ix] = ipaddr.i[ix] & netmask.i[ix]; |
|||
broadcast.i[ix] = (~netmask.i[ix] & 255) | ipaddr.i[ix]; |
|||
} |
|||
gateway.i[IP4_ADDR_SZ - 1] |= |
|||
(ipaddr.i[IP4_ADDR_SZ - 1] == (network.i[IP4_ADDR_SZ - 1] | 1)) ? 2 : 1; |
|||
while (!finished); |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
void |
|||
write_static_cfg (void) |
|||
{ |
|||
FILE *fp; |
|||
char buf[16]; |
|||
|
|||
int main(int argc, char *argv[]){ |
|||
|
|||
if ((fp = fopen (INTERFACES_FILE, "w"))) |
|||
{ |
|||
fprintf (fp, |
|||
"\n# The first network card - this entry was created during the Debian installation\n"); |
|||
fprintf (fp, "# (network, broadcast and gateway are optional)\n"); |
|||
fprintf (fp, "iface eth0 inet static\n"); |
|||
|
|||
debconf_command ("TITLE", "Network Configuration", NULL); |
|||
num2dot (ipaddress, buf); |
|||
fprintf (fp, "\taddress %s\n", buf); |
|||
|
|||
static_netork_cfg(); |
|||
num2dot (netmask, buf); |
|||
fprintf (fp, "\tnetmask %s\n", buf); |
|||
|
|||
num2dot (ipaddress, buf); |
|||
fprintf (fp, "\tnetwork %s\n", buf); |
|||
|
|||
num2dot (ipaddress, buf); |
|||
fprintf (fp, "\tbroadcast %s\n", buf); |
|||
|
|||
num2dot (ipaddress, buf); |
|||
fprintf (fp, "\tgateway %s\n", buf); |
|||
|
|||
fclose (fp); |
|||
} |
|||
else |
|||
{ |
|||
perror ("fopen"); |
|||
fprintf (stderr, "Unable to write to '%s'\n", INTERFACES_FILE); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
int |
|||
main (int argc, char *argv[]) |
|||
{ |
|||
|
|||
|
|||
debconf_command ("TITLE", "Network Configuration", NULL); |
|||
|
|||
get_static_cfg (); |
|||
|
|||
write_static_cfg (); |
|||
|
|||
return 0; |
|||
} |
|||
|
Loading…
Reference in new issue