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 <[email protected]>
This commit is contained in:
@@ -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
|
// 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
|
// DHCP server is stored as property of /chosen. We try to get it and use
|
||||||
// the IP address we find in there.
|
// the IP address we find in there.
|
||||||
|
// TODO Sun machines may use bootp-response instead?
|
||||||
struct {
|
struct {
|
||||||
uint8 irrelevant[16];
|
uint8 irrelevant[16];
|
||||||
uint32 ip_address;
|
uint32 ip_address;
|
||||||
// ...
|
// ...
|
||||||
} dhcpResponse;
|
} dhcpResponse;
|
||||||
bytesRead = of_getprop(gChosen, "dhcp-response", &dhcpResponse,
|
int bytesRead = of_getprop(gChosen, "dhcp-response", &dhcpResponse,
|
||||||
sizeof(dhcpResponse));
|
sizeof(dhcpResponse));
|
||||||
if (bytesRead != OF_FAILED && bytesRead == (int)sizeof(dhcpResponse)) {
|
if (bytesRead != OF_FAILED && bytesRead == (int)sizeof(dhcpResponse)) {
|
||||||
SetIPAddress(ntohl(dhcpResponse.ip_address));
|
SetIPAddress(ntohl(dhcpResponse.ip_address));
|
||||||
} else {
|
return B_OK;
|
||||||
// try to read manual client IP from boot path
|
}
|
||||||
if (parameters != NULL) {
|
|
||||||
char *comma = strrchr(parameters, ',');
|
// try to read manual client IP from boot path
|
||||||
if (comma != NULL && comma != strchr(parameters, ',')) {
|
if (parameters != NULL) {
|
||||||
SetIPAddress(ip_parse_address(comma + 1));
|
char *comma = strrchr(parameters, ',');
|
||||||
}
|
if (comma != NULL && comma != strchr(parameters, ',')) {
|
||||||
}
|
SetIPAddress(ip_parse_address(comma + 1));
|
||||||
if (fIPAddress == 0) {
|
return B_OK;
|
||||||
// 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 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user