网口先用固定的IP启动,然后尝试使用下面的代码进行DHCP配置,每次运行后ifShow能看到设备ip地址等信息均发生了重配置,但是dhcpcParamsGet获取到的参数全部为0,请大家看看代码哪有问题?谢谢!
#include <vxWorks.h>
#include <taskLib.h>
#include <stdio.h>
#include <ifLib.h>
#include <dhcpcLib.h>
void * pLeaseCookie;
struct dhcp_param ParamList;
void dtmdhcpcEventHookRtn
(
int leaseEvent, /* new or expired parameters */
void * pCookie /* lease identifier from dhcpcInit() */
)
{
if (leaseEvent == DHCPC_LEASE_NEW)
{
dhcpcParamsGet(pCookie, &ParamList);
printf("ipaddr = %x \n",ParamList.yiaddr.s_addr);
}
}
int test()
{
struct ifnet *pIf;
STATUS result;
pIf = ifunit("motfcc0"); /* Access network device. */
/* Initialize lease variables for automatic configuration. */
pLeaseCookie = dhcpcInit (pIf, TRUE);
if (pLeaseCookie == NULL)
return(ERROR);
result = dhcpcEventHookAdd(pLeaseCookie,dtmdhcpcEventHookRtn);
if (result != OK)
return (ERROR);
result = dhcpcBind (pLeaseCookie, TRUE);
if (result != OK)
return (ERROR);
return OK;
}