Browse Source

loadkernel renamed to download_url, substantially restructured, and moved

to nic.c
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
56825df041
1 changed files with 62 additions and 2 deletions
  1. 62
    2
      src/core/nic.c

+ 62
- 2
src/core/nic.c View File

16
 **************************************************************************/
16
 **************************************************************************/
17
 #include "etherboot.h"
17
 #include "etherboot.h"
18
 #include "console.h"
18
 #include "console.h"
19
+#include "url.h"
20
+#include "proto.h"
21
+#include "resolv.h"
19
 #include "dev.h"
22
 #include "dev.h"
20
 #include "nic.h"
23
 #include "nic.h"
21
 #include "elf.h" /* FOR EM_CURRENT */
24
 #include "elf.h" /* FOR EM_CURRENT */
293
 }
296
 }
294
 
297
 
295
 
298
 
299
+/*
300
+ * Download a file from the specified URL and process it with the
301
+ * specified function
302
+ *
303
+ */
304
+int download_url ( char *url,
305
+		   int ( * process ) ( unsigned char *data,
306
+				       unsigned int blocknum,
307
+				       unsigned int len, int eof ) ) {
308
+	struct url_info url_info;
309
+	struct protocol *proto;
310
+	struct sockaddr_in server;
311
+	
312
+	DBG ( "Loading %s\n", url );
313
+
314
+	/* Parse URL */
315
+	parse_url ( &url_info, url );
316
+	
317
+	/* Identify protocol */
318
+	proto = identify_protocol ( url_info.protocol );
319
+	if ( ! proto ) {
320
+		if ( url_info.protocol ) {
321
+			printf ( "Unknown protocol %s\n", url_info.protocol );
322
+		} else {
323
+			printf ( "No default protocols\n" );
324
+		}
325
+		goto error_out;
326
+	}
327
+
328
+	/* Resolve hostname */
329
+	server.sin_addr = arptable[ARP_SERVER].ipaddr;
330
+	if ( url_info.host ) {
331
+		if ( ! resolv ( &server.sin_addr, url_info.host ) ) {
332
+			printf ( "Cannot resolve host %s\n", url_info.host );
333
+			goto error_out;
334
+		}
335
+	}
336
+
337
+	/* Resolve port number */
338
+	server.sin_port = url_info.port ?
339
+		strtoul ( url_info.port, NULL, 10 ) : 0;
340
+
341
+	/* Restore URL */
342
+	unparse_url ( &url_info );
343
+
344
+	/* Call protocol's method to download the file */
345
+	return proto->load ( url, &server, process );
346
+
347
+ error_out:
348
+	unparse_url ( &url_info );
349
+	return 0;
350
+}
351
+
352
+
353
+
354
+
296
 /**************************************************************************
355
 /**************************************************************************
297
 LOAD - Try to get booted
356
 LOAD - Try to get booted
298
 **************************************************************************/
357
 **************************************************************************/
300
 		      int ( * process ) ( unsigned char *data,
359
 		      int ( * process ) ( unsigned char *data,
301
 					  unsigned int blocknum,
360
 					  unsigned int blocknum,
302
 					  unsigned int size, int eof ) ) {
361
 					  unsigned int size, int eof ) ) {
303
-	const char	*kernel;
362
+	char	*kernel;
304
 
363
 
305
 	/* Now use TFTP to load file */
364
 	/* Now use TFTP to load file */
306
 #ifdef	DOWNLOAD_PROTO_NFS
365
 #ifdef	DOWNLOAD_PROTO_NFS
314
 #endif
373
 #endif
315
 		: KERNEL_BUF;
374
 		: KERNEL_BUF;
316
 	if ( kernel ) {
375
 	if ( kernel ) {
317
-		loadkernel(kernel,process); /* We don't return except on error */
376
+		download_url(kernel,process); /* We don't return except on error */
318
 		printf("Unable to load file.\n");
377
 		printf("Unable to load file.\n");
319
 	} else {	
378
 	} else {	
320
 		printf("No filename\n");
379
 		printf("No filename\n");
1757
 	return tmo;
1816
 	return tmo;
1758
 }
1817
 }
1759
 #endif /* MULTICAST_LEVEL_2 */
1818
 #endif /* MULTICAST_LEVEL_2 */
1819
+

Loading…
Cancel
Save