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;
}
/* 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);
int
NetLoop(bd_t *bis, proto_t protocol)
{
- char *s, *e;
- ulong reg;
+ char *s;
Net_bd = bis;
if (!NetTxPacket) {
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;
}
+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)
{