数据结构
和服务器类似,客户端也维护着一个全局的数据结构client_config,用于所有的DHCP服务。
struct client_config_t client_config = {
/* Default options. */
abort_if_no_lease: 0,
foreground: 0,
quit_after_lease: 0,
background_if_no_lease: 0,
interface: "eth0",
pidfile: NULL,
script: DEFAULT_SCRIPT,
clientid: NULL,
hostname: NULL,
ifindex: 0,
arp: "\0\0\0\0\0\0", /* appease gcc-3.0 */
};
该结构在dhcpc.h中定义,并在dhcpc.c中设置默认值
struct client_config_t client_config = {
/* Default options. */
abort_if_no_lease: 0,
foreground: 0,
quit_after_lease: 0,
background_if_no_lease: 0,
interface: "eth0",
pidfile: NULL,
script: DEFAULT_SCRIPT,
clientid: NULL,
hostname: NULL,
ifindex: 0,
arp: "\0\0\0\0\0\0", /* appease gcc-3.0 */
};
其它全局变量
其余所需要的重要的全局变量都以简单数据结构给出,并没有专门设计复杂结构。
static int state;
static unsigned long requested_ip; /* = 0,请求的IP */
static unsigned long server_addr; //服务器地址
static unsigned long timeout; //租约超时时刻
static int packet_num; /* = 0 */ //可认为是连续重复发送数据包的次数
static int fd; //本地socket监听的fd
static int signal_pipe[