一、DHCP client 和 dhcpcd server直接的信息交互:
Client 和server 通过property_get/set 共享内存来共享信息。
property_get/set(key,value),保存在共享内存中,系统中的各个进程可以通过property_service访问。
二、DHCP 客户端:
源码:Gingerbread/System/core/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
{
wait_for_property(“init.svc.dhcpcd_eth0”,” running”, 10);
wait_for_property(“dhcp_eth0.result”, NULL, 30);
property_get(“dhcp_eth0.result”, prop_value, NULL));
}
static void fill_ip_info(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
{
property_get(“dhcp.eth0. ipaddress”, prop_value,NULL);
property_get(“dhcp.eth0. gateway”, prop_value,NULL);
property_get(“dhcp.eth0. mask”, prop_value,NULL);
property_get(“dhcp.eth0. dns1”, prop_value,NULL);
property_get(“dhcp.eth0. dns2”, prop_value,NULL);
property_get(“dhcp.eth0. server”, prop_value,NULL);
property_get(“dhcp.eth0. leasetime”, prop_value,NULL);
}
三、Dchpcd 服务端进程:
源码:Gingerbread/external/dhcpcd/dhcpcd.c
Main()
{
dhcp_run(options, &pid_fd);
}
dhcp_run()
{
client_setup(state, options);
}
handle_timeout(struct if_state *state, const struct options *options)
{
}
handle_dhcp_packet()àhandle_dhcp()àbind_dhcp()àconfigure()àrun_script()
执行脚本文件/system/etc/dhcpcd/dhcpcd-run-hooks,脚本文件调用setprop命令设置dhcp相关参数,并设置dhcp result.
case "${reason}" in
BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
EXPIRE|FAIL|IPV4LL|STOP)
RELEASE)