libnetutils/dhcp_utils.c
int dhcp_do_request(const char *interface,
                    in_addr_t *ipaddr,
                    in_addr_t *gateway,
                    in_addr_t *mask,
                    in_addr_t *dns1,
                    in_addr_t *dns2,
                    in_addr_t *server,
                    uint32_t  *lease)
{
    char result_prop_name[PROPERTY_KEY_MAX];
    char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
    const char *ctrl_prop = "ctl.start";
    const char *desired_status = "running";

    snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result",
            DHCP_PROP_NAME_PREFIX,
            interface);
    /* Erase any previous setting of the dhcp result property */
    property_set(result_prop_name, "");

    /* Start the daemon and wait until it's ready */
    property_set(ctrl_prop, DAEMON_NAME);
    if (wait_for_property(DAEMON_PROP_NAME, desired_status, 10) < 0) {
        snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for dhcpcd to start");
        return -1;
    }

    /* Wait for the daemon to return a result */
    if (wait_for_property(result_prop_name, NULL, 30) < 0) {
        snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP to finish");
        return -1;
    }

    if (!property_get(result_prop_name, prop_value, NULL)) {
        /* shouldn't ever happen, given the success of wait_for_property() */
        snprintf(errmsg, sizeof(errmsg), "%s", "DHCP result property was not set");
        return -1;
    }
    if (strcmp(prop_value, "ok") == 0) {
        fill_ip_info(interface, ipaddr, gateway, mask, dns1, dns2, server, lease);
        return 0;
    } else {
        snprintf(errmsg, sizeof(errmsg), "DHCP result was %s", prop_value);
        return -1;
    }
}
/*
 * Start the dhcp client daemon, and wait for it to finish
 * configuring the interface.
 */
Start the dhcp client daemon, and wait for it to finish
configuring the interface.
Start the dhcp client daemon and wait for it to finish configuring the interface .
int dhcp_do_request(const char *interface,
                    in_addr_t *ipaddr,
                    in_addr_t *gateway,
                    in_addr_t *mask,
                    in_addr_t *dns1,
                    in_addr_t *dns2,
                    in_addr_t *server,
                    uint32_t  *lease)
{
    char result_prop_name[PROPERTY_KEY_MAX];
    char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
    const char *ctrl_prop = "ctl.start";
    const char *desired_status = "running";
    snprintf(result_prop_name, sizeof(result_prop_name), "%s.%s.result",
            DHCP_PROP_NAME_PREFIX,
            interface);
    property_set(result_prop_name, "");
    property_set(ctrl_prop, DAEMON_NAME);
    if (wait_for_property(DAEMON_PROP_NAME, desired_status, 10) < 0) {
        snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for dhcpcd to start");
        return -1;
    }
    if (wait_for_property(result_prop_name, NULL, 30) < 0) {
        snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for DHCP to finish");
        return -1;
    }
    if (!property_get(result_prop_name, prop_value, NULL)) {
        snprintf(errmsg, sizeof(errmsg), "%s", "DHCP result property was not set");
        return -1;
    }
    if (strcmp(prop_value, "ok") == 0) {
        fill_ip_info(interface, ipaddr, gateway, mask, dns1, dns2, server, lease);
        return 0;
    } else {
        snprintf(errmsg, sizeof(errmsg), "DHCP result was %s", prop_value);
        return -1;
    }
}
int dhcp_do_request ( const char * interface , in_addr_t * ipaddr , in_addr_t * gateway , in_addr_t * mask , in_addr_t * dns1 , in_addr_t * dns2 , in_addr_t * server , uint32_t * lease ) { char result_prop_name [ PROPERTY_KEY_MAX ] ; char prop_value [ PROPERTY_VALUE_MAX ] = { ' \0 ' } ; const char * ctrl_prop = " " ; const char * desired_status = " " ; snprintf ( result_prop_name , sizeof ( result_prop_name ) , " " , DHCP_PROP_NAME_PREFIX , interface ) ; property_set ( result_prop_name , " " ) ; property_set ( ctrl_prop , DAEMON_NAME ) ; if ( wait_for_property ( DAEMON_PROP_NAME , desired_status , 10 ) < 0 ) { snprintf ( errmsg , sizeof ( errmsg ) , " " , " " ) ; return -1 ; } if ( wait_for_property ( result_prop_name , NULL , 30 ) < 0 ) { snprintf ( errmsg , sizeof ( errmsg ) , " " , " " ) ; return -1 ; } if ( ! property_get ( result_prop_name , prop_value , NULL ) ) { snprintf ( errmsg , sizeof ( errmsg ) , " " , " " ) ; return -1 ; } if ( strcmp ( prop_value , " " ) == 0 ) { fill_ip_info ( interface , ipaddr , gateway , mask , dns1 , dns2 , server , lease ) ; return 0 ; } else { snprintf ( errmsg , sizeof ( errmsg ) , " " , prop_value ) ; return -1 ; } }
Start the dhcp client daemon, and wait for it to finish
 configuring the interface.
Start the dhcp client daemon and wait for it to finish configuring the interface .
/* Erase any previous setting of the dhcp result property */ /* Start the daemon and wait until it's ready */ /* Wait for the daemon to return a result */ /* shouldn't ever happen, given the success of wait_for_property() */