aboutsummaryrefslogtreecommitdiffstats
path: root/libnetutils
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2009-12-14 15:41:54 -0800
committerDmitry Shmidt <dimitrysh@google.com>2009-12-14 16:05:34 -0800
commit9363b7d5da7e17842432251384f8dc46902ac323 (patch)
tree1d3dd1058f2683647bc5e96d1ca216b6b9328b35 /libnetutils
parent021529fe63d931815fe7aad09578caf130c28670 (diff)
downloadsystem_core-9363b7d5da7e17842432251384f8dc46902ac323.tar.gz
system_core-9363b7d5da7e17842432251384f8dc46902ac323.tar.bz2
system_core-9363b7d5da7e17842432251384f8dc46902ac323.zip
dhcp: Add hostname support
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Diffstat (limited to 'libnetutils')
-rw-r--r--libnetutils/dhcp_utils.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libnetutils/dhcp_utils.c b/libnetutils/dhcp_utils.c
index bad2e2ff..0f8a6c43 100644
--- a/libnetutils/dhcp_utils.c
+++ b/libnetutils/dhcp_utils.c
@@ -24,8 +24,9 @@
#include <cutils/properties.h>
-static const char DAEMON_NAME[] = "dhcpcd";
-static const char DAEMON_PROP_NAME[] = "init.svc.dhcpcd";
+static const char DAEMON_NAME[] = "dhcpcd";
+static const char DAEMON_PROP_NAME[] = "init.svc.dhcpcd";
+static const char HOSTNAME_PROP_NAME[] = "net.hostname";
static const char DHCP_PROP_NAME_PREFIX[] = "dhcp";
static const int NAP_TIME = 1; /* wait for 1 second at a time */
/* when polling for property values */
@@ -129,6 +130,7 @@ int dhcp_do_request(const char *interface,
{
char result_prop_name[PROPERTY_KEY_MAX];
char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
+ char daemon_cmd[PROPERTY_VALUE_MAX * 2];
const char *ctrl_prop = "ctl.start";
const char *desired_status = "running";
@@ -139,7 +141,13 @@ int dhcp_do_request(const char *interface,
property_set(result_prop_name, "");
/* Start the daemon and wait until it's ready */
- property_set(ctrl_prop, DAEMON_NAME);
+ if (property_get(HOSTNAME_PROP_NAME, prop_value, NULL) && (prop_value[0] != '\0'))
+ snprintf(daemon_cmd, sizeof(daemon_cmd), "%s:-h %s %s", DAEMON_NAME,
+ prop_value, interface);
+ else
+ snprintf(daemon_cmd, sizeof(daemon_cmd), "%s:%s", DAEMON_NAME, interface);
+ memset(prop_value, '\0', PROPERTY_VALUE_MAX);
+ property_set(ctrl_prop, daemon_cmd);
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;