Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bdaaec1b authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Use DHCP server as gateway when it is absent

Some routers can return 0.0.0.0 as gateway address,
use DHCP server as gateway in such instances

Change-Id: I7e8db8e619475efce53ce391f77f2c13c3b7268c
parent 112445b8
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -79,6 +79,15 @@ static int fill_ip_info(const char *interface,
    snprintf(prop_name, sizeof(prop_name), "%s.%s.gateway", DHCP_PROP_NAME_PREFIX, interface);
    property_get(prop_name, gateway, NULL);

    snprintf(prop_name, sizeof(prop_name), "%s.%s.server", DHCP_PROP_NAME_PREFIX, interface);
    property_get(prop_name, server, NULL);

    //TODO: Handle IPv6 when we change system property usage
    if (strcmp(gateway, "0.0.0.0") == 0) {
        //DHCP server is our best bet as gateway
        strncpy(gateway, server, PROPERTY_VALUE_MAX);
    }

    snprintf(prop_name, sizeof(prop_name), "%s.%s.mask", DHCP_PROP_NAME_PREFIX, interface);
    if (property_get(prop_name, prop_value, NULL)) {
        int p;
@@ -107,9 +116,6 @@ static int fill_ip_info(const char *interface,
    snprintf(prop_name, sizeof(prop_name), "%s.%s.dns2", DHCP_PROP_NAME_PREFIX, interface);
    property_get(prop_name, dns2, NULL);

    snprintf(prop_name, sizeof(prop_name), "%s.%s.server", DHCP_PROP_NAME_PREFIX, interface);
    property_get(prop_name, server, NULL);

    snprintf(prop_name, sizeof(prop_name), "%s.%s.leasetime", DHCP_PROP_NAME_PREFIX, interface);
    if (property_get(prop_name, prop_value, NULL)) {
        *lease = atol(prop_value);