[VxWorks] vxworks的DHCP客户端问题

kfchu   2009-9-23 15:31 楼主
我现在有两个网卡,分别在不同的网络里,IP地址的分别是通过DHCP服务器自动分配,设计了一套DHCP客户端申请程序,单个网口可以实现IP地址的动态分配,串行方式两个网口都可动态获得IP地址,能不能实现两个网口同时动态申请IP地址哪?这样可以节约时间,因为一个DHCP申请需要大约8s左右,望高手不吝赐教。谢谢!!!!


STATUS DhcpClient(char * ipName)
{
    unsigned long duration;
    struct ifnet *pIf;
    STATUS result;
    void *pLeaseCookie;
    extern struct ifnet *ifunit ();
    struct dhcp_param paramList;
    pIf = ifunit (ipName); /* Access network device. */
    /* Initialize lease variables for automatic configuration. */
    pLeaseCookie = dhcpcInit (pIf, TRUE);
    if (pLeaseCookie == NULL)
    {
        printf("dhcpcInit error\n");
        return (ERROR);
    }

    /* Set any lease options here. */
    duration = htonl(DHCP_PORT);
    dhcpcOptionAdd (pLeaseCookie, _DHCP_LEASE_TIME_TAG, 4, (UCHAR*)&duration);
    dhcpcOptionSet (pLeaseCookie, _DHCP_ROUTER_TAG);
    dhcpcOptionSet (pLeaseCookie, _DHCP_DNS_SERVER_TAG);
    dhcpcOptionSet (pLeaseCookie, _DHCP_DNS_DOMAIN_TAG);
    dhcpcOptionSet (pLeaseCookie, _DHCP_ROUTER_DISCOVER_TAG);
    dhcpcOptionSet (pLeaseCookie, _DHCP_STATIC_ROUTE_TAG);
    dhcpcOptionSet (pLeaseCookie, _DHCP_VENDOR_SPEC_TAG);
    dhcpcOptionSet (pLeaseCookie, _DHCP_NBN_SERVER_TAG);
    dhcpcOptionSet (pLeaseCookie, _DHCP_NB_NODETYPE_TAG);
    dhcpcOptionSet (pLeaseCookie, _DHCP_NB_SCOPE_TAG);

    result = dhcpcBind (pLeaseCookie, TRUE); // Synchronous execution.
    if (result != OK)
    {
        printf("dhcpcBind error\n");
        return (ERROR);
    }


    /****************************************************************/
    /**************** Using dhcpcParamsGet() ***********************/
    /* prepare to use dhcpcParamsGet() */
    memset((char *)¶mList, 0x00, sizeof(paramList));
    paramList.subnet_mask = (struct in_addr *)malloc(sizeof(struct
                             in_addr));
    memset((char *)paramList.subnet_mask, 0x00,
    sizeof(paramList.subnet_mask));
    paramList.sname = (char *)malloc(256);
    memset((char *)paramList.sname, 0x00, sizeof(paramList.sname));
    paramList.dns_server = (struct in_addrs *)malloc(sizeof(struct in_addrs));
    memset((char *)paramList.dns_server, 0x00,
    sizeof(paramList.dns_server));
    paramList.dns_domain = (char *)malloc(256);
    if (dhcpcParamsGet(pLeaseCookie, ¶mList) == ERROR)
      logMsg("Can not get parameter list. % x \n", errno,0,0,0,0,0);
    else
    {
       logMsg("DHCP server host name is: %s. \n", paramList.sname,0,0,0,0,0);
       logMsg("DHCP dns domain name is: %s. \n",
       paramList.dns_domain,0,0,0,0,0);
       logMsg("DHCP server's IP address is: %s.\n",
       inet_ntoa(paramList.server_id),0,0,0,0,0);
       logMsg("This client's pre-dhcp assigned address is: %s.\n",
       inet_ntoa(paramList.ciaddr),0,0,0,0,0);
       logMsg("This client's assigned address is: %s.\n",
        inet_ntoa(paramList.yiaddr),0,0,0,0,0);
         logMsg("This client's subnet mask is:%s.\n",
       inet_ntoa(*(paramList.subnet_mask)),0,0,0,0,0);
/* next log msg was commented out by sjk since it doesn't work */
//logMsg("DNS server IP address is: %s. \n",
//inet_ntoa(*(paramList.dns_server)),0,0,0,0,0);
/* dhcpcParamsShow() gives the dns IP addresses */
}

    //dhcpcServerShow(pLeaseCookie);
   
    return OK;
}

回复评论 (2)

可能是发贴地方不对,呵
点赞  2009-9-23 16:48
是讲关于dhcp客户端IP地址申请的问题,与操作系统无关,不知道大家遇到过这种情况没有??
点赞  2009-9-24 10:33
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复