Browse Source
This is currently incomplete, just some ideas and bare bones of code (haven't even tried to compile it.) r224master

commit
99a8525d12
2 changed files with 182 additions and 0 deletions
@ -0,0 +1,62 @@ |
|||
Template: netcfg/dhcp_option |
|||
Type: boolean |
|||
Default: true |
|||
Description: Automatic Network Configuration |
|||
Configuration for (FIXME) Do you want to use DHCP or BOOTP to automatically |
|||
configure this interface? You'll need a DHCP or BOOTP server in the local |
|||
network for this to work. |
|||
|
|||
Template: netcfg/get_hostname |
|||
Type: string |
|||
Default: debian |
|||
Description: Choose the hostname. |
|||
Every Debian system has a name - even if it is not on a network. This name is |
|||
called its "hostname". You should now specify a hostname for your new |
|||
system. If your system is going to be on a network, you should talk to the |
|||
administrator of the network before you choose a hostname. If not, you may |
|||
choose any name you like. The hostname must not contain dots or underscores, |
|||
and you must not append the domain name here. If you can't think of a |
|||
hostname for your new system, you may press <ENTER> to use the default hostname |
|||
of "debian". |
|||
|
|||
Template: netcfg/get_ipaddress |
|||
Type: string |
|||
Description: What is the IP address of this system? |
|||
The ipaddress identifies you system to other computer on the network. |
|||
|
|||
Template: netcfg/get_netmask |
|||
Type: string |
|||
Description: What is your netmask? |
|||
The ipaddress identifies you system to other computer on the network. |
|||
|
|||
Template: netcfg/get_gateway |
|||
Type: string |
|||
Description: What is your IP gateway address? |
|||
A gateway system is one that connects your network to other networks such as |
|||
your company wide-area net or the Internet. If there is no gateway in your |
|||
subnet just leave this field blank. |
|||
|
|||
Template: netcfg/get_domain |
|||
Type: string |
|||
Description: Choose the Domain name. |
|||
As with individual systems, every network has a name. This name is called the |
|||
domain name. Please enter your domain name or leave this field empty if you |
|||
don't have a domain. |
|||
|
|||
Template: netcfg/get_nameservers |
|||
Type: string |
|||
Description: Choose the DNS Server Addresses |
|||
Please enter the IP addresses (not host names) of up to 3 name servers, |
|||
separated by spaces. Do not use commas. The servers will be queried in the |
|||
order in which you enter them. If you don't want to use any name servers just |
|||
leave this field blank. |
|||
|
|||
Template: netcfg/get_pcmcia_tranceiver |
|||
Type: string |
|||
Description: PCMCIA Transceiver |
|||
Some PCMCIA Cards can detect the transceiver type although this might take |
|||
some time. Others cannot detect it at all. Possible values for this parameter |
|||
are "auto", "10baseT", "10base2", "aui", and "100baseT", or a blank for cards |
|||
that don't support transceiver selection. Please specify what transceiver type |
|||
you would like to use. If you aren't sure, just use the default value of |
|||
"auto". |
@ -0,0 +1,120 @@ |
|||
/*
|
|||
netcfg.c : Configures the network |
|||
*/ |
|||
|
|||
|
|||
#define IP4_ADDR_SZ (4) |
|||
struct ip4_addr |
|||
{ |
|||
int i[IP4_ADDR_SZ]; |
|||
} |
|||
ip4_addr_t; |
|||
char *host = NULL; |
|||
char *domain = NULL; |
|||
|
|||
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} }; |
|||
|
|||
|
|||
/*
|
|||
* 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) |
|||
{ |
|||
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) |
|||
{ |
|||
next = strchr (current, '.'); |
|||
if (next == NULL) |
|||
next = end; |
|||
else |
|||
{ |
|||
*next = '\0'; |
|||
next++; |
|||
} |
|||
|
|||
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; |
|||
} |
|||
} |
|||
free (tmp_a); |
|||
if (ix != IP4_ADDR_SZ) |
|||
return 255; |
|||
return 0; |
|||
} |
|||
|
|||
|
|||
|
|||
static_network_cfg () |
|||
{ |
|||
int ix; |
|||
|
|||
debconf_command ("INPUT", "high", "netcfg/get_hostname", NULL); |
|||
|
|||
do { |
|||
debconf_command ("INPUT", "critical", "netcfg/get_ipaddress", NULL); |
|||
debconf_command ("GO", NULL); |
|||
} while ( atoIP4(debconf_command ("GET", "netcfg/get_ipaddress", NULL), &ipaddress)) ; |
|||
|
|||
do { |
|||
debconf_command ("INPUT", "critical", "netcfg/get_netmask", NULL); |
|||
debconf_command ("GO", NULL); |
|||
} while ( atoIP4(debconf_command ("GET", "netcfg/get_netmask", NULL), &netmask)) ; |
|||
|
|||
|
|||
/*
|
|||
* 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; |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
int main(int argc, char *argv[]){ |
|||
|
|||
|
|||
debconf_command ("TITLE", "Network Configuration", NULL); |
|||
|
|||
static_netork_cfg(); |
|||
|
|||
|
|||
|
|||
|
|||
} |
Loading…
Reference in new issue