udhcp源码剖析(五)——DHCP客户端重要的数据结构和初始化配置

数据结构

和服务器类似,客户端也维护着一个全局的数据结构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[
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值