]> www.infradead.org Git - users/rw/armboot.git/commitdiff
There were still some endianess issues (with tftp) -- fixed them
authorrobertkaiser <robertkaiser>
Wed, 2 Oct 2002 23:53:53 +0000 (23:53 +0000)
committerrobertkaiser <robertkaiser>
Wed, 2 Oct 2002 23:53:53 +0000 (23:53 +0000)
common/cmd_nvedit.c
include/net.h
net/net.c

index 542e29522dd496c31f1602a0451f0329c67f1eed..567a81aca378149120ac1d4092b7a3befb38c87a 100644 (file)
@@ -386,14 +386,7 @@ int _do_setenv (bd_t *bd, int flag, int argc, char *argv[])
 
     if (strcmp(argv[1],"ipaddr") == 0) {
        char *s = argv[2];      /* always use only one arg */
-       char *e;
-       bd->bi_ip_addr = 0;
-       for (i=0; i<4; ++i) {
-           ulong val = s ? simple_strtoul(s, &e, 10) : 0;
-           bd->bi_ip_addr <<= 8;
-           bd->bi_ip_addr  |= (val & 0xFF);
-           if (s) s = (*e) ? e+1 : e;
-       }
+       bd->bi_ip_addr = string_to_ip(s);
        return 0;
     }
 
index e87e93a6c515ec08fba3caa60d5e7a09da8b13e4..78297ca99111ce258ae75a64c331a4158458e445 100644 (file)
@@ -310,9 +310,12 @@ extern void        NetReceive(volatile uchar *, int);
 /* Print an IP address on the console */
 extern void    print_IPaddr (IPaddr_t);
 
-/* Convert a IP address to a string */
+/* Convert a IP address to a string .. */
 extern void    ip_to_string (IPaddr_t x, char *s);
 
+/* ... and vice versa */
+IPaddr_t string_to_ip (const char *s);
+
 /* copy a filename (allow for "..." notation, limit length) */
 extern void    copy_filename (uchar *dst, uchar *src, int size);
 
index 4eac1d6c01bad9c35e0654958f652076423f26f4..2ab1c9b829db816048b43bb0ec703b2eccb553c2 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -130,8 +130,7 @@ void                NetPrintEther(volatile uchar * addr);
 int
 NetLoop(bd_t *bis, proto_t protocol)
 {
-       char    *s, *e;
-       ulong   reg;
+       char    *s;
 
        Net_bd = bis;
        if (!NetTxPacket) {
@@ -163,14 +162,8 @@ restart:
 
        if (protocol == TFTP) {                 /* TFTP */
                NetCopyIP(&NetOurIP, (IPaddr_t*)&bis->bi_ip_addr);
-               NetServerIP = 0;
                s = getenv (bis, "serverip");
-               for (reg=0; reg<4; ++reg) {
-                       ulong val = s ? simple_strtoul(s, &e, 10) : 0;
-                       NetServerIP <<= 8;
-                       NetServerIP |= (val & 0xFF);
-                       if (s) s = (*e) ? e+1 : e;
-               }
+               NetServerIP = string_to_ip(s);
 
                if (net_check_prereq (protocol) != 0) {
                        return 0;
@@ -692,6 +685,22 @@ void print_IPaddr (IPaddr_t x)
 }
 
 
+IPaddr_t string_to_ip (const char *s)
+{
+       IPaddr_t ip = 0;
+       char *e;
+       int i;
+
+       for (i = 0; i < sizeof(ip); ++i)
+       {
+               ulong val = s ? simple_strtoul(s, &e, 10) : 0;
+               ip <<= 8;
+               ip |= (val & 0xFF);
+               if (s) s = (*e) ? e+1 : e;
+       }
+       return(htonl(ip));
+}
+
 void
 NetPrintEther(volatile uchar * addr)
 {