From: robertkaiser Date: Wed, 2 Oct 2002 23:53:53 +0000 (+0000) Subject: There were still some endianess issues (with tftp) -- fixed them X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c3d14b309391b7dafd3fe47aee84951398798e33;p=users%2Frw%2Farmboot.git There were still some endianess issues (with tftp) -- fixed them --- diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 542e295..567a81a 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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; } diff --git a/include/net.h b/include/net.h index e87e93a..78297ca 100644 --- a/include/net.h +++ b/include/net.h @@ -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); diff --git a/net/net.c b/net/net.c index 4eac1d6..2ab1c9b 100644 --- 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) {