使用DHCP之前最好清空本地IP地址,KWF等软路由要求非常严格。

网关B测试通过
This commit is contained in:
nnhy 2015-11-23 21:06:10 +00:00
parent f8c01c285a
commit 780f9f3569
2 changed files with 7 additions and 4 deletions

View File

@ -51,10 +51,9 @@ void Dhcp::SendDhcp(byte* buf, uint len)
name.Append(Sys.ID[0]); name.Append(Sys.ID[0]);
opt = opt->Next()->SetData(DHCP_OPT_HostName, name); opt = opt->Next()->SetData(DHCP_OPT_HostName, name);
String vendor = "http://www.NewLifeX.com"; String vendor = "www.NewLifeX.com";
opt = opt->Next()->SetData(DHCP_OPT_Vendor, vendor); opt = opt->Next()->SetData(DHCP_OPT_Vendor, vendor);
byte ps[] = { 0x01, 0x06, 0x03, 0x2b}; // 需要参数 Mask/DNS/Router/Vendor byte ps[] = { 0x01, 0x06, 0x03, 0x2b}; // 需要参数 Mask/DNS/Router/Vendor
//ByteArray bs(ps, ArrayLength(ps));
opt = opt->Next()->SetData(DHCP_OPT_ParameterList, CArray(ps)); opt = opt->Next()->SetData(DHCP_OPT_ParameterList, CArray(ps));
opt = opt->Next()->End(); opt = opt->Next()->End();
@ -76,6 +75,7 @@ void Dhcp::Discover()
DHCP_HEADER* dhcp = (DHCP_HEADER*)buf; DHCP_HEADER* dhcp = (DHCP_HEADER*)buf;
debug_printf("DHCP::Discover...\r\n"); debug_printf("DHCP::Discover...\r\n");
dhcpid = Sys.Ms();
dhcp->Init(dhcpid, false); dhcp->Init(dhcpid, false);
byte* p = dhcp->Next(); byte* p = dhcp->Next();
@ -114,6 +114,9 @@ void Dhcp::Start()
ITransport* port = dynamic_cast<ITransport*>(Socket); ITransport* port = dynamic_cast<ITransport*>(Socket);
if(port) port->Open(); if(port) port->Open();
// 使用DHCP之前最好清空本地IP地址KWF等软路由要求非常严格
Host->IP = IPAddress::Any();
// 创建任务每秒发送一次Discover // 创建任务每秒发送一次Discover
if(!taskID) if(!taskID)
taskID = Sys.AddTask(SendDiscover, this, 0, 1000, "DHCP获取"); taskID = Sys.AddTask(SendDiscover, this, 0, 1000, "DHCP获取");

View File

@ -296,7 +296,7 @@ typedef struct _DHCP_HEADER
HardLength = 6; HardLength = 6;
Hops = 0; Hops = 0;
TransID = __REV(dhcpid); TransID = __REV(dhcpid);
Flags = 0x80; // 从0-15bits最左一bit为1时表示server将以广播方式传送封包给 client其余尚未使用 //Flags = 0x80; // 从0-15bits最左一bit为1时表示server将以广播方式传送封包给 client其余尚未使用
SetMagic(); SetMagic();
if(recursion) Prev()->Init(recursion); if(recursion) Prev()->Init(recursion);