]>
Commit | Line | Data |
---|---|---|
6a45e384 DB |
1 | /* |
2 | * Generic network code. Moved from net.c | |
3 | * | |
4 | * Copyright 1994 - 2000 Neil Russell. | |
5 | * Copyright 2000 Roland Borde | |
6 | * Copyright 2000 Paolo Scaffardi | |
7 | * Copyright 2000-2002 Wolfgang Denk, [email protected] | |
8 | * Copyright 2009 Dirk Behme, [email protected] | |
9 | * | |
1a459660 | 10 | * SPDX-License-Identifier: GPL-2.0+ |
6a45e384 DB |
11 | */ |
12 | ||
13 | #include <common.h> | |
14 | ||
049a95a7 | 15 | struct in_addr string_to_ip(const char *s) |
6a45e384 | 16 | { |
049a95a7 | 17 | struct in_addr addr; |
6a45e384 DB |
18 | char *e; |
19 | int i; | |
20 | ||
049a95a7 | 21 | addr.s_addr = 0; |
6a45e384 | 22 | if (s == NULL) |
049a95a7 | 23 | return addr; |
6a45e384 | 24 | |
049a95a7 | 25 | for (addr.s_addr = 0, i = 0; i < 4; ++i) { |
6a45e384 | 26 | ulong val = s ? simple_strtoul(s, &e, 10) : 0; |
049a95a7 JH |
27 | addr.s_addr <<= 8; |
28 | addr.s_addr |= (val & 0xFF); | |
6a45e384 DB |
29 | if (s) { |
30 | s = (*e) ? e+1 : e; | |
31 | } | |
32 | } | |
33 | ||
049a95a7 JH |
34 | addr.s_addr = htonl(addr.s_addr); |
35 | return addr; | |
6a45e384 | 36 | } |