2010-01-03 07:33:58 +00:00
|
|
|
/*
|
|
|
|
* Generic network code. Moved from net.c
|
|
|
|
*
|
|
|
|
* Copyright 1994 - 2000 Neil Russell.
|
|
|
|
* Copyright 2000 Roland Borde
|
|
|
|
* Copyright 2000 Paolo Scaffardi
|
|
|
|
* Copyright 2000-2002 Wolfgang Denk, wd@denx.de
|
|
|
|
* Copyright 2009 Dirk Behme, dirk.behme@googlemail.com
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2010-01-03 07:33:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
|
2015-04-08 06:41:01 +00:00
|
|
|
struct in_addr string_to_ip(const char *s)
|
2010-01-03 07:33:58 +00:00
|
|
|
{
|
2015-04-08 06:41:01 +00:00
|
|
|
struct in_addr addr;
|
2010-01-03 07:33:58 +00:00
|
|
|
char *e;
|
|
|
|
int i;
|
|
|
|
|
2015-04-08 06:41:01 +00:00
|
|
|
addr.s_addr = 0;
|
2010-01-03 07:33:58 +00:00
|
|
|
if (s == NULL)
|
2015-04-08 06:41:01 +00:00
|
|
|
return addr;
|
2010-01-03 07:33:58 +00:00
|
|
|
|
2015-04-08 06:41:01 +00:00
|
|
|
for (addr.s_addr = 0, i = 0; i < 4; ++i) {
|
2010-01-03 07:33:58 +00:00
|
|
|
ulong val = s ? simple_strtoul(s, &e, 10) : 0;
|
2015-04-08 06:41:01 +00:00
|
|
|
addr.s_addr <<= 8;
|
|
|
|
addr.s_addr |= (val & 0xFF);
|
2010-01-03 07:33:58 +00:00
|
|
|
if (s) {
|
|
|
|
s = (*e) ? e+1 : e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 06:41:01 +00:00
|
|
|
addr.s_addr = htonl(addr.s_addr);
|
|
|
|
return addr;
|
2010-01-03 07:33:58 +00:00
|
|
|
}
|