diff options
Diffstat (limited to 'mdk-stage1/network.c')
-rw-r--r-- | mdk-stage1/network.c | 74 |
1 files changed, 58 insertions, 16 deletions
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index 163bafe5c..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. @@ -31,6 +31,7 @@ #include <sys/ioctl.h> #include <sys/mount.h> #include <stdio.h> +#include <fcntl.h> #include <netdb.h> #include <resolv.h> #include <sys/utsname.h> @@ -290,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)); @@ -537,7 +538,7 @@ 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); } @@ -568,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); @@ -683,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; @@ -853,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, 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); @@ -871,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; @@ -994,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]); @@ -1064,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); @@ -1085,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]); @@ -1127,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, " @@ -1157,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) @@ -1176,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); |