[haiku-commits] Change in haiku[master]: openfirmware: fail if IP address can't be found

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 15 Mar 2020 16:22:26 +0000

From Adrien Destugues <pulkomandy@xxxxxxxxx>:

Adrien Destugues has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2358 ;)


Change subject: openfirmware: fail if IP address can't be found
......................................................................

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.
---
M src/system/boot/platform/openfirmware/network.cpp
1 file changed, 24 insertions(+), 21 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/58/2358/1

diff --git a/src/system/boot/platform/openfirmware/network.cpp 
b/src/system/boot/platform/openfirmware/network.cpp
index 8e95c42..5b3d04d 100644
--- a/src/system/boot/platform/openfirmware/network.cpp
+++ b/src/system/boot/platform/openfirmware/network.cpp
@@ -157,38 +157,41 @@
        // 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;
 }
 


--
To view, visit https://review.haiku-os.org/c/haiku/+/2358
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Iddece4a7269abbdd8e93f0cbbc9a9e43fcbe8a69
Gerrit-Change-Number: 2358
Gerrit-PatchSet: 1
Gerrit-Owner: Adrien Destugues <pulkomandy@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: openfirmware: fail if IP address can't be found - Gerrit