From 0f33dfcce5112f2517af11db20065e95c55e109e Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Sun, 15 Mar 2020 16:46:09 +0100 Subject: [PATCH] openfirmware: fail if IP address can't be found Sending packets from 0.0.0.0 doesn't work quite right, so better admit we failed. Change-Id: Iddece4a7269abbdd8e93f0cbbc9a9e43fcbe8a69 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2358 Reviewed-by: waddlesplash --- .../boot/platform/openfirmware/network.cpp | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/system/boot/platform/openfirmware/network.cpp b/src/system/boot/platform/openfirmware/network.cpp index 8e95c42ed3..5b3d04de65 100644 --- a/src/system/boot/platform/openfirmware/network.cpp +++ b/src/system/boot/platform/openfirmware/network.cpp @@ -157,38 +157,41 @@ OFEthernetInterface::Init(const char *device, const char *parameters) // Note: This is a non-standardized way. On my Mac mini the response of the // DHCP server is stored as property of /chosen. We try to get it and use // the IP address we find in there. + // TODO Sun machines may use bootp-response instead? struct { uint8 irrelevant[16]; uint32 ip_address; // ... } dhcpResponse; - bytesRead = of_getprop(gChosen, "dhcp-response", &dhcpResponse, + int bytesRead = of_getprop(gChosen, "dhcp-response", &dhcpResponse, sizeof(dhcpResponse)); if (bytesRead != OF_FAILED && bytesRead == (int)sizeof(dhcpResponse)) { SetIPAddress(ntohl(dhcpResponse.ip_address)); - } else { - // try to read manual client IP from boot path - if (parameters != NULL) { - char *comma = strrchr(parameters, ','); - if (comma != NULL && comma != strchr(parameters, ',')) { - SetIPAddress(ip_parse_address(comma + 1)); - } - } - if (fIPAddress == 0) { - // try to read default-client-ip setting - char defaultClientIP[16]; - package = of_finddevice("/options"); - bytesRead = of_getprop(package, "default-client-ip", - defaultClientIP, sizeof(defaultClientIP) - 1); - if (bytesRead != OF_FAILED && bytesRead > 1) { - defaultClientIP[bytesRead] = '\0'; - ip_addr_t address = ip_parse_address(defaultClientIP); - SetIPAddress(address); - } + return B_OK; + } + + // try to read manual client IP from boot path + if (parameters != NULL) { + char *comma = strrchr(parameters, ','); + if (comma != NULL && comma != strchr(parameters, ',')) { + SetIPAddress(ip_parse_address(comma + 1)); + return B_OK; } } - return B_OK; + // try to read default-client-ip setting + char defaultClientIP[16]; + intptr_t package = of_finddevice("/options"); + bytesRead = of_getprop(package, "default-client-ip", + defaultClientIP, sizeof(defaultClientIP) - 1); + if (bytesRead != OF_FAILED && bytesRead > 1) { + defaultClientIP[bytesRead] = '\0'; + ip_addr_t address = ip_parse_address(defaultClientIP); + SetIPAddress(address); + return B_OK; + } + + return B_ERROR; }