Patch by Andreas Faerber:
* Fixed coding style issues pointed out by Axel. * Fixed potential buffer overflow and fault in default-client-up code path (OF counts terminating zero char, too). * Added an intermediate fallback to parsing the boot path * Added himself to the copyright holders Thanks a lot! Fixes ticket #5189. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34918 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005, Ingo Weinhold <[email protected]>.
|
* Copyright 2005, Ingo Weinhold <[email protected]>.
|
||||||
|
* Copyright 2010, Andreas Faerber <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ public:
|
|||||||
OFEthernetInterface();
|
OFEthernetInterface();
|
||||||
virtual ~OFEthernetInterface();
|
virtual ~OFEthernetInterface();
|
||||||
|
|
||||||
status_t Init(const char *device);
|
status_t Init(const char *device, const char *parameters);
|
||||||
|
|
||||||
virtual mac_addr_t MACAddress() const;
|
virtual mac_addr_t MACAddress() const;
|
||||||
|
|
||||||
@@ -117,7 +118,7 @@ OFEthernetInterface::~OFEthernetInterface()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
OFEthernetInterface::Init(const char *device)
|
OFEthernetInterface::Init(const char *device, const char *parameters)
|
||||||
{
|
{
|
||||||
if (!device)
|
if (!device)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@@ -160,16 +161,24 @@ OFEthernetInterface::Init(const char *device)
|
|||||||
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 {
|
} else {
|
||||||
char saddr[16];
|
// try to read manual client IP from boot path
|
||||||
package = of_finddevice("/options");
|
if (parameters != NULL) {
|
||||||
bytesRead = of_getprop(package, "default-client-ip", saddr,
|
char *comma = strrchr(parameters, ',');
|
||||||
sizeof(saddr));
|
if (comma != NULL && comma != strchr(parameters, ',')) {
|
||||||
if (bytesRead != OF_FAILED) {
|
SetIPAddress(parse_ip_address(comma + 1));
|
||||||
saddr[bytesRead] = '\0';
|
}
|
||||||
printf("default-client-ip: %s\n", saddr);
|
}
|
||||||
ip_addr_t addr = parse_ip_address(saddr);
|
if (fIPAddress == 0) {
|
||||||
printf("addr = %x\n", (unsigned int)addr);
|
// try to read default-client-ip setting
|
||||||
SetIPAddress(addr);
|
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 = parse_ip_address(defaultClientIP);
|
||||||
|
SetIPAddress(address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +287,7 @@ platform_net_stack_init()
|
|||||||
if (!interface)
|
if (!interface)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
status_t error = interface->Init(bootPath);
|
status_t error = interface->Init(bootPath, parameters + 1);
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
delete interface;
|
delete interface;
|
||||||
return error;
|
return error;
|
||||||
|
|||||||
Reference in New Issue
Block a user