headers/private/kernel/boot/net/IP.h | 1 +
src/system/boot/loader/net/IP.cpp | 22 +++++++++++++++++
src/system/boot/platform/openfirmware/network.cpp | 27 ++------------------
3 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/headers/private/kernel/boot/net/IP.h b/headers/private/kernel/boot/net/IP.h
index cc6a38e..46d5ae6 100644
a
|
b
|
private:
|
59 | 59 | }; |
60 | 60 | |
61 | 61 | uint16 ip_checksum(ChainBuffer *buffer); |
| 62 | ip_addr_t ip_parse_address(const char* address); |
62 | 63 | |
63 | 64 | |
64 | 65 | #endif // _BOOT_IP_H |
diff --git a/src/system/boot/loader/net/IP.cpp b/src/system/boot/loader/net/IP.cpp
index 807fb34..0c43f4b 100644
a
|
b
|
ip_checksum(ChainBuffer *buffer)
|
266 | 266 | |
267 | 267 | return ~checksum; |
268 | 268 | } |
| 269 | |
| 270 | |
| 271 | ip_addr_t |
| 272 | ip_parse_address(const char *string) |
| 273 | { |
| 274 | ip_addr_t address = 0; |
| 275 | int components = 0; |
| 276 | |
| 277 | // TODO: Handles only IPv4 addresses for now. |
| 278 | while (components < 4) { |
| 279 | address |= strtol(string, NULL, 0) << ((4 - components - 1) * 8); |
| 280 | |
| 281 | const char *dot = strchr(string, '.'); |
| 282 | if (dot == NULL) |
| 283 | break; |
| 284 | |
| 285 | string = dot + 1; |
| 286 | components++; |
| 287 | } |
| 288 | |
| 289 | return address; |
| 290 | } |
diff --git a/src/system/boot/platform/openfirmware/network.cpp b/src/system/boot/platform/openfirmware/network.cpp
index 4702bae..4320963 100644
a
|
b
|
|
15 | 15 | |
16 | 16 | #include <boot/platform.h> |
17 | 17 | #include <boot/net/Ethernet.h> |
| 18 | #include <boot/net/IP.h> |
18 | 19 | #include <boot/net/NetStack.h> |
19 | 20 | #include <platform/openfirmware/openfirmware.h> |
20 | 21 | |
… |
… |
hex_dump(const void *_data, int length)
|
76 | 77 | #endif // !TRACE_NETWORK |
77 | 78 | |
78 | 79 | |
79 | | static ip_addr_t |
80 | | parse_ip_address(const char *string) |
81 | | { |
82 | | ip_addr_t address = 0; |
83 | | int components = 0; |
84 | | |
85 | | // TODO: Handles only IPv4 addresses for now. |
86 | | while (components < 4) { |
87 | | address |= strtol(string, NULL, 0) << ((4 - components - 1) * 8); |
88 | | |
89 | | const char *dot = strchr(string, '.'); |
90 | | if (dot == NULL) |
91 | | break; |
92 | | |
93 | | string = dot + 1; |
94 | | components++; |
95 | | } |
96 | | |
97 | | return address; |
98 | | } |
99 | | |
100 | | |
101 | 80 | // #pragma mark - |
102 | 81 | |
103 | 82 | |
… |
… |
OFEthernetInterface::Init(const char *device, const char *parameters)
|
165 | 144 | if (parameters != NULL) { |
166 | 145 | char *comma = strrchr(parameters, ','); |
167 | 146 | if (comma != NULL && comma != strchr(parameters, ',')) { |
168 | | SetIPAddress(parse_ip_address(comma + 1)); |
| 147 | SetIPAddress(ip_parse_address(comma + 1)); |
169 | 148 | } |
170 | 149 | } |
171 | 150 | if (fIPAddress == 0) { |
… |
… |
OFEthernetInterface::Init(const char *device, const char *parameters)
|
176 | 155 | defaultClientIP, sizeof(defaultClientIP) - 1); |
177 | 156 | if (bytesRead != OF_FAILED && bytesRead > 1) { |
178 | 157 | defaultClientIP[bytesRead] = '\0'; |
179 | | ip_addr_t address = parse_ip_address(defaultClientIP); |
| 158 | ip_addr_t address = ip_parse_address(defaultClientIP); |
180 | 159 | SetIPAddress(address); |
181 | 160 | } |
182 | 161 | } |