diff options
Diffstat (limited to 'mdk-stage1/network.c')
| -rw-r--r-- | mdk-stage1/network.c | 89 | 
1 files changed, 65 insertions, 24 deletions
| diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index 6959fcbc8..ab512399a 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -1,7 +1,7 @@  /* - * Guillaume Cottenceau (gc@mandrakesoft.com) + * Guillaume Cottenceau (gc)   * - * Copyright 2000 Mandrakesoft + * Copyright 2000 Mandriva   *   * This software may be freely redistributed under the terms of the GNU   * public license. @@ -19,9 +19,9 @@   *   */ +#include "stage1.h" +  #include <stdlib.h> -/* define _GNU_SOURCE so strndup is available */ -#define _GNU_SOURCE  #include <string.h>  #include <unistd.h>  #include <sys/socket.h> @@ -31,11 +31,11 @@  #include <sys/ioctl.h>  #include <sys/mount.h>  #include <stdio.h> +#include <fcntl.h>  #include <netdb.h>  #include <resolv.h>  #include <sys/utsname.h> -#include "stage1.h"  #include "frontend.h"  #include "modules.h"  #include "probing.h" @@ -291,7 +291,7 @@ static int save_netinfo(struct interface_info * intf)  	fprintf(f, "NETWORKING=yes\n");  	fprintf(f, "FORWARD_IPV4=false\n"); -	if (hostname && !intf->boot_proto == BOOTPROTO_DHCP) +	if (hostname && !(intf->boot_proto == BOOTPROTO_DHCP))  		fprintf(f, "HOSTNAME=%s\n", hostname);  	if (gateway.s_addr != 0)  		fprintf(f, "GATEWAY=%s\n", inet_ntoa(gateway)); @@ -401,8 +401,8 @@ static void static_ip_callback(char ** strings)  static enum return_type setup_network_interface(struct interface_info * intf)  {  	enum return_type results; -	char * bootprotos[] = { "Static", "DHCP", "ADSL", NULL }; -	char * bootprotos_auto[] = { "static", "dhcp", "adsl" }; +	char * bootprotos[] = { "DHCP", "Static", "ADSL", NULL }; +	char * bootprotos_auto[] = { "dhcp", "static", "adsl" };  	char * choice;  	results = ask_from_list_auto("Please select your network connection type.", bootprotos, &choice, "network", bootprotos_auto); @@ -538,12 +538,12 @@ static enum return_type configure_network(struct interface_info * intf)  		char * boulet;  		if (dhcp_hostname || dhcp_domain) { -		    answers = (char **) malloc(sizeof(questions)); +		    answers = (char **) calloc(1, sizeof(questions));  		    answers[0] = strdup(dhcp_hostname);  		    answers[1] = strdup(dhcp_domain);  		} -		if (!dhcp_hostname || !dhcp_hostname) { +		if (!dhcp_hostname || !dhcp_domain) {  		    results = ask_from_entries_auto("I could not guess hostname and domain name; please fill in this information. "  						    "Valid answers are for example: `mybox' for hostname and `mynetwork.com' for "  						    "domain name, for a machine called `mybox.mynetwork.com' on the Internet.", @@ -569,8 +569,15 @@ static enum return_type bringup_networking(struct interface_info * intf)  {  	static struct interface_info loopback;  	enum return_type results; -	 -	my_insmod("af_packet", ANY_DRIVER_TYPE, NULL, 1); +	int fd; + +	/* try to find if module already loaded or built-in to avoid failing */ +	/* badly */ +	fd = open("/proc/net/packet", O_RDONLY); +	if (fd < 0) +		my_modprobe("af_packet", ANY_DRIVER_TYPE, NULL); +	else +		close(fd);  	do {  		results = configure_wireless(intf->device); @@ -684,8 +691,7 @@ static char * interface_select(void)  	}  	if (count == 0) { -		stg1_error_message("No NET device found.\n" -				   "Hint: if you're using a Laptop, note that PCMCIA Network adapters are now supported either with `pcmcia.img' or `network.img', please try both these bootdisks."); +		stg1_error_message("No NET device found.");  		i = ask_insmod(NETWORK_DEVICES);  		if (i == RETURN_BACK)  			return NULL; @@ -797,8 +803,8 @@ static enum return_type get_mirrorlist(mirrorlist_t mirrorlist, int start, char  			line[line_pos] = '\0';  			line_pos = 0; -			/* skip medium if it looks like an updates one */ -			if (strstr(line, ",type=updates,")) +			/* skip medium if it does not look like a distrib path */ +			if (!strstr(line, ",type=distrib,"))  				continue;  			url = strstr(line, ",url="); @@ -854,8 +860,8 @@ static int choose_mirror_from_host_list(mirrorlist_t mirrorlist, char **selected  static int choose_mirror_from_list(char *http_proxy_host, char *http_proxy_port, const char *protocol, char **selected_host, char **filepath)  {  	enum return_type results; -	char *versions[] = { "Specify the mirror manually", DISTRIB_VERSION, "cooker", NULL }; -	char *version = DISTRIB_VERSION; +	char *versions[] = { "Specify the mirror manually", DISTRIB_NAME " " DISTRIB_VERSION, NULL }; +	char *version = DISTRIB_NAME " " DISTRIB_VERSION;  	do {  		results = ask_from_list("Please select a medium from the list below.", versions, &version); @@ -872,7 +878,7 @@ static int choose_mirror_from_list(char *http_proxy_host, char *http_proxy_port,  				mirrorlist[0][0] = "Specify the mirror manually";  				mirrorlist[1][0] = NULL; -				results = get_mirrorlist(mirrorlist, 1, version, protocol, http_proxy_host, http_proxy_port); +				results = get_mirrorlist(mirrorlist, 1, DISTRIB_VERSION, protocol, http_proxy_host, http_proxy_port);  				if (results == RETURN_ERROR)  					return RETURN_ERROR; @@ -995,11 +1001,12 @@ enum return_type ftp_prepare(void)  		char location_full[500];  		int ftp_serv_response = -1;  		int fd, size; +		int need_arch = 0;  		char ftp_hostname[500];  		if (!IS_AUTOMATIC) {  			if (answers == NULL) -				answers = (char **) malloc(sizeof(questions)); +				answers = (char **) calloc(1, sizeof(questions));  			results = choose_mirror_from_list(http_proxy_host, http_proxy_port, "ftp", &answers[0], &answers[1]); @@ -1065,6 +1072,21 @@ enum return_type ftp_prepare(void)  		        fd = ftp_start_download(ftp_serv_response, location_full, &size);  		} +		/* Try arched directory */ +		if (fd < 0) { +                     log_message("%s failed.", location_full); +                     char *with_arch = asprintf_("%s%s/%s/%s", answers[1][0] == '/' ? "" : "/", answers[1], ARCH, COMPRESSED_FILE_REL("/")); +                     log_message("trying %s...", with_arch); +                     if (use_http_proxy) +                          fd = http_download_file(answers[0], with_arch, &size, use_http_proxy ? "http" : NULL, http_proxy_host, http_proxy_port); +                     else +                          fd = ftp_start_download(ftp_serv_response, with_arch, &size); +                     if (0 < fd) { +                          strcpy(location_full, with_arch); +                          need_arch = 1; +                     } +                } +  		if (fd < 0) {  			char *msg = str_ftp_error(fd);  			log_message("FTP: error get %d for remote file %s", fd, location_full); @@ -1086,13 +1108,17 @@ enum return_type ftp_prepare(void)  		if (use_http_proxy) {                          add_to_env("METHOD", "http"); -		        sprintf(location_full, "ftp://%s%s", ftp_hostname, answers[1]); +		        snprintf(location_full, sizeof(location_full), "ftp://%s%s", ftp_hostname, answers[1]); +                        if (need_arch) +                             strcat(location_full, "/" ARCH);  		        add_to_env("URLPREFIX", location_full);  			add_to_env("PROXY", http_proxy_host);  			add_to_env("PROXYPORT", http_proxy_port);  		} else {                          add_to_env("METHOD", "ftp");  		        add_to_env("HOST", answers[0]); +                        if (need_arch) +                             strcat(answers[1], "/" ARCH);  			add_to_env("PREFIX", answers[1]);  			if (!streq(answers[2], "")) {  			        add_to_env("LOGIN", answers[2]); @@ -1128,17 +1154,17 @@ enum return_type http_prepare(void)  	do {  		char location_full[500]; -		int fd, size; +		int fd, size, need_arch = 0;  		int use_http_proxy;  		if (!IS_AUTOMATIC) {  			if (answers == NULL) -				answers = (char **) malloc(sizeof(questions)); +				answers = (char **) calloc(1, sizeof(questions));  			results = choose_mirror_from_list(http_proxy_host, http_proxy_port, "http", &answers[0], &answers[1]);  			if (results == RETURN_BACK) -				return ftp_prepare(); +				return http_prepare();  		}  		results = ask_from_entries_auto("Please enter the name or IP address of the HTTP server, " @@ -1158,6 +1184,19 @@ enum return_type http_prepare(void)  		use_http_proxy = http_proxy_host && http_proxy_port && !streq(http_proxy_host, "") && !streq(http_proxy_port, "");  		fd = http_download_file(answers[0], location_full, &size, use_http_proxy ? "http" : NULL, http_proxy_host, http_proxy_port); + +		/* Try arched directory */ +		if (fd < 0) { +                     log_message("%s failed.", location_full); +                     char *with_arch = asprintf_("%s%s/%s/%s", answers[1][0] == '/' ? "" : "/", answers[1], ARCH, COMPRESSED_FILE_REL("/")); +                     log_message("trying %s...", with_arch); +                     fd = http_download_file(answers[0], with_arch, &size, use_http_proxy ? "http" : NULL, http_proxy_host, http_proxy_port); +                     if (0 < fd) { +                          strcpy(location_full, with_arch); +                          need_arch = 1; +                     } +                } +  		if (fd < 0) {  			log_message("HTTP: error %d", fd);  			if (fd == FTPERR_FAILED_CONNECT) @@ -1177,6 +1216,8 @@ enum return_type http_prepare(void)                  add_to_env("METHOD", "http");  		sprintf(location_full, "http://%s%s%s", answers[0], answers[1][0] == '/' ? "" : "/", answers[1]); +                if (need_arch) +                     strcat(location_full, "/" ARCH);  		add_to_env("URLPREFIX", location_full);                  if (!streq(http_proxy_host, ""))  			add_to_env("PROXY", http_proxy_host); | 
