Ticket #5319: ip_parse_address.diff

File ip_parse_address.diff, 2.9 KB (added by andreasf, 15 years ago)

patch

  • headers/private/kernel/boot/net/IP.h

     headers/private/kernel/boot/net/IP.h              |    1 +
     src/system/boot/loader/net/IP.cpp                 |   22 +++++++++++++++++
     src/system/boot/platform/openfirmware/network.cpp |   27 ++------------------
     3 files changed, 26 insertions(+), 24 deletions(-)
    
    diff --git a/headers/private/kernel/boot/net/IP.h b/headers/private/kernel/boot/net/IP.h
    index cc6a38e..46d5ae6 100644
    a b private:  
    5959};
    6060
    6161uint16 ip_checksum(ChainBuffer *buffer);
     62ip_addr_t ip_parse_address(const char* address);
    6263
    6364
    6465#endif  // _BOOT_IP_H
  • src/system/boot/loader/net/IP.cpp

    diff --git a/src/system/boot/loader/net/IP.cpp b/src/system/boot/loader/net/IP.cpp
    index 807fb34..0c43f4b 100644
    a b ip_checksum(ChainBuffer *buffer)  
    266266
    267267    return ~checksum;
    268268}
     269
     270
     271ip_addr_t
     272ip_parse_address(const char *string)
     273{
     274    ip_addr_t address = 0;
     275    int components = 0;
     276
     277    // TODO: Handles only IPv4 addresses for now.
     278    while (components < 4) {
     279        address |= strtol(string, NULL, 0) << ((4 - components - 1) * 8);
     280
     281        const char *dot = strchr(string, '.');
     282        if (dot == NULL)
     283            break;
     284
     285        string = dot + 1;
     286        components++;
     287    }
     288
     289    return address;
     290}
  • 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 4702bae..4320963 100644
    a b  
    1515
    1616#include <boot/platform.h>
    1717#include <boot/net/Ethernet.h>
     18#include <boot/net/IP.h>
    1819#include <boot/net/NetStack.h>
    1920#include <platform/openfirmware/openfirmware.h>
    2021
    hex_dump(const void *_data, int length)  
    7677#endif  // !TRACE_NETWORK
    7778
    7879
    79 static ip_addr_t
    80 parse_ip_address(const char *string)
    81 {
    82     ip_addr_t address = 0;
    83     int components = 0;
    84 
    85     // TODO: Handles only IPv4 addresses for now.
    86     while (components < 4) {
    87         address |= strtol(string, NULL, 0) << ((4 - components - 1) * 8);
    88 
    89         const char *dot = strchr(string, '.');
    90         if (dot == NULL)
    91             break;
    92 
    93         string = dot + 1;
    94         components++;
    95     }
    96 
    97     return address;
    98 }
    99 
    100 
    10180// #pragma mark -
    10281
    10382
    OFEthernetInterface::Init(const char *device, const char *parameters)  
    165144        if (parameters != NULL) {
    166145            char *comma = strrchr(parameters, ',');
    167146            if (comma != NULL && comma != strchr(parameters, ',')) {
    168                 SetIPAddress(parse_ip_address(comma + 1));
     147                SetIPAddress(ip_parse_address(comma + 1));
    169148            }
    170149        }
    171150        if (fIPAddress == 0) {
    OFEthernetInterface::Init(const char *device, const char *parameters)  
    176155                defaultClientIP, sizeof(defaultClientIP) - 1);
    177156            if (bytesRead != OF_FAILED && bytesRead > 1) {
    178157                defaultClientIP[bytesRead] = '\0';
    179                 ip_addr_t address = parse_ip_address(defaultClientIP);
     158                ip_addr_t address = ip_parse_address(defaultClientIP);
    180159                SetIPAddress(address);
    181160            }
    182161        }