Ticket #5189: network-ipaddress-v2.diff

File network-ipaddress-v2.diff, 2.5 KB (added by andreasf, 14 years ago)

patch

  • src/system/boot/platform/openfirmware/network.cpp

    diff --git a/src/system/boot/platform/openfirmware/network.cpp b/src/system/boot/platform/openfirmware/network.cpp
    index 0323546..5ae82d2 100644
    a b  
    11/*
    22 * Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
     3 * Copyright 2010, Andreas Faerber <andreas.faerber@web.de>
    34 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56
    public:  
    3132    OFEthernetInterface();
    3233    virtual ~OFEthernetInterface();
    3334
    34     status_t Init(const char *device);
     35    status_t Init(const char *device, const char *parameters);
    3536
    3637    virtual mac_addr_t MACAddress() const;
    3738
    OFEthernetInterface::~OFEthernetInterface()  
    117118
    118119
    119120status_t
    120 OFEthernetInterface::Init(const char *device)
     121OFEthernetInterface::Init(const char *device, const char *parameters)
    121122{
    122123    if (!device)
    123124        return B_BAD_VALUE;
    OFEthernetInterface::Init(const char *device)  
    160161    if (bytesRead != OF_FAILED && bytesRead == (int)sizeof(dhcpResponse)) {
    161162        SetIPAddress(ntohl(dhcpResponse.ip_address));
    162163    } else {
    163         char saddr[16];
    164         package = of_finddevice("/options");
    165         bytesRead = of_getprop(package, "default-client-ip", saddr,
    166             sizeof(saddr));
    167         if (bytesRead != OF_FAILED) {
    168             saddr[bytesRead] = '\0';
    169             printf("default-client-ip: %s\n", saddr);
    170             ip_addr_t addr = parse_ip_address(saddr);
    171             printf("addr = %x\n", (unsigned int)addr);
    172             SetIPAddress(addr);
     164        // try to read manual client IP from boot path
     165        if (parameters != NULL) {
     166            char *comma = strrchr(parameters, ',');
     167            if (comma != NULL && comma != strchr(parameters, ',')) {
     168                SetIPAddress(parse_ip_address(comma + 1));
     169            }
     170        }
     171        if (fIPAddress == 0) {
     172            // try to read default-client-ip setting
     173            char defaultClientIP[16];
     174            package = of_finddevice("/options");
     175            bytesRead = of_getprop(package, "default-client-ip",
     176                defaultClientIP, sizeof(defaultClientIP) - 1);
     177            if (bytesRead != OF_FAILED && bytesRead > 1) {
     178                defaultClientIP[bytesRead] = '\0';
     179                ip_addr_t address = parse_ip_address(defaultClientIP);
     180                SetIPAddress(address);
     181            }
    173182        }
    174183    }
    175184
    platform_net_stack_init()  
    278287    if (!interface)
    279288        return B_NO_MEMORY;
    280289
    281     status_t error = interface->Init(bootPath);
     290    status_t error = interface->Init(bootPath, parameters + 1);
    282291    if (error != B_OK) {
    283292        delete interface;
    284293        return error;