diff --git a/src/system/boot/platform/openfirmware/network.cpp b/src/system/boot/platform/openfirmware/network.cpp
index f5b23c6..4c236cf 100644
a
|
b
|
hex_dump(const void *_data, int length)
|
49 | 49 | |
50 | 50 | #define hex_dump(data, length) |
51 | 51 | |
52 | | #endif // !TRACE_NETWORK |
| 52 | #endif // !TRACE_NETWORK |
| 53 | |
| 54 | |
| 55 | static int |
| 56 | parse_ip_address_component(const char* sz, int len) |
| 57 | { |
| 58 | const int base = 10; // only decimal numbers for now |
| 59 | int r = 0; |
| 60 | for (int i = 0; i < len; i++) { |
| 61 | int x = sz[i] - '0'; |
| 62 | for (int j = 1; j < len - i; j++) |
| 63 | x *= base; |
| 64 | r += x; |
| 65 | } |
| 66 | return r; |
| 67 | } |
| 68 | |
| 69 | static ip_addr_t |
| 70 | parse_ip_address(const char* sz) |
| 71 | { |
| 72 | ip_addr_t addr = 0; |
| 73 | int i = 0; |
| 74 | const char *psz = sz; |
| 75 | // handles only IPv4 addresses for now |
| 76 | char *p = strchr(psz, '.'); |
| 77 | while (p != NULL && i < 4) { |
| 78 | int len = p - psz; |
| 79 | addr |= parse_ip_address_component(psz, len) << ((4 - i - 1) * 8); |
| 80 | p = strchr(psz = p + 1, '.'); |
| 81 | i++; |
| 82 | } |
| 83 | addr |= parse_ip_address_component(psz, sz + strlen(sz) - psz); |
| 84 | return addr; |
| 85 | } |
53 | 86 | |
54 | 87 | |
55 | 88 | class OFEthernetInterface : public EthernetInterface { |
… |
… |
OFEthernetInterface::Init(const char *device)
|
128 | 161 | } dhcpResponse; |
129 | 162 | bytesRead = of_getprop(gChosen, "dhcp-response", &dhcpResponse, |
130 | 163 | sizeof(dhcpResponse)); |
131 | | if (bytesRead != OF_FAILED && bytesRead == (int)sizeof(dhcpResponse)) |
132 | | SetIPAddress(ntohl(dhcpResponse.ip_address)); |
| 164 | if (bytesRead != OF_FAILED && bytesRead == (int)sizeof(dhcpResponse)) { |
| 165 | SetIPAddress(ntohl(dhcpResponse.ip_address)); |
| 166 | } else { |
| 167 | char saddr[16]; |
| 168 | package = of_finddevice("/options"); |
| 169 | bytesRead = of_getprop(package, "default-client-ip", saddr, sizeof(saddr)); |
| 170 | if (bytesRead != OF_FAILED) { |
| 171 | saddr[bytesRead] = '\0'; |
| 172 | printf("default-client-ip: %s\n", saddr); |
| 173 | ip_addr_t addr = parse_ip_address(saddr); |
| 174 | printf("addr = %x\n", (unsigned int)addr); |
| 175 | SetIPAddress(addr); |
| 176 | } |
| 177 | } |
133 | 178 | |
134 | 179 | return B_OK; |
135 | 180 | } |