不要Tip.RemoteMac,避免多个地方使用造成冲突

This commit is contained in:
nnhy 2015-06-22 04:38:50 +00:00
parent 50a93bfadd
commit 9a0f7bf94e
4 changed files with 16 additions and 13 deletions

View File

@ -83,6 +83,9 @@ bool ArpSocket::Process(Stream* ms)
// 仅处理ARP请求
if(arp->Option != 0x0100) return true;
// 目标Mac地址
MacAddress mac = arp->SrcMac.Value();
// 构造响应包
arp->Option = 0x0200;
// 来源IP和Mac作为目的地址
@ -97,7 +100,7 @@ bool ArpSocket::Process(Stream* ms)
debug_printf(" size=%d\r\n", sizeof(ARP_HEADER));
#endif
Tip->SendEthernet(ETH_ARP, (byte*)arp, sizeof(ARP_HEADER));
Tip->SendEthernet(ETH_ARP, mac, (byte*)arp, sizeof(ARP_HEADER));
return true;
}
@ -137,7 +140,7 @@ bool ArpSocket::Request(IPAddress& ip, MacAddress& mac, int timeout)
ARP_HEADER* arp = (ARP_HEADER*)eth->Next();
arp->Init();
Tip->RemoteMac = MacAddress::Empty;
//Tip->RemoteMac = MacAddress::Empty;
// 构造请求包
arp->Option = 0x0100;
@ -152,7 +155,7 @@ bool ArpSocket::Request(IPAddress& ip, MacAddress& mac, int timeout)
debug_printf(" size=%d\r\n", sizeof(ARP_HEADER));
#endif
Tip->SendEthernet(ETH_ARP, (byte*)arp, sizeof(ARP_HEADER));
Tip->SendEthernet(ETH_ARP, MacAddress::Empty, (byte*)arp, sizeof(ARP_HEADER));
// 如果没有超时时间,表示异步请求,不用等待结果
if(timeout <= 0) return false;

View File

@ -49,7 +49,7 @@ void Dhcp::SendDhcp(DHCP_HEADER* dhcp, uint len)
memcpy(dhcp->ClientMac, (byte*)&Tip->Mac.Value, 6);
Tip->RemoteMac = MacAddress::Full;
//Tip->RemoteMac = MacAddress::Full;
RemoteIP = IPAddress::Broadcast;
Send(dhcp->Prev(), sizeof(DHCP_HEADER) + len, false);

View File

@ -87,7 +87,7 @@ void TinyIP::Process(Stream& ms)
// 只处理发给本机MAC的数据包。此时不能进行目标Mac地址过滤因为可能是广播包
MacAddress mac = eth->SrcMac.Value();
RemoteMac = mac;
//RemoteMac = mac;
// 处理ARP
if(eth->Type == ETH_ARP)
@ -259,13 +259,13 @@ void TinyIP::ShowInfo()
#endif
}
void TinyIP::SendEthernet(ETH_TYPE type, const byte* buf, uint len)
void TinyIP::SendEthernet(ETH_TYPE type, MacAddress& mac, const byte* buf, uint len)
{
ETH_HEADER* eth = (ETH_HEADER*)(buf - sizeof(ETH_HEADER));
assert_param(IS_ETH_TYPE(type));
eth->Type = type;
eth->DestMac = RemoteMac;
eth->DestMac = mac;
eth->SrcMac = Mac;
len += sizeof(ETH_HEADER);
@ -279,9 +279,9 @@ void TinyIP::SendEthernet(ETH_TYPE type, const byte* buf, uint len)
case ETH_IPv6: { name = "IPv6"; break; }
}
debug_printf("SendEthernet: type=0x%04x %s, len=%d(0x%x) ", type, name, len, len);
ShowMac(Mac);
Mac.Show();
debug_printf(" => ");
ShowMac(RemoteMac);
mac.Show();
debug_printf("\r\n");*/
/*Sys.ShowHex((byte*)eth->Next(), len, '-');
debug_printf("\r\n");*/
@ -328,7 +328,7 @@ void TinyIP::SendIP(IP_TYPE type, const byte* buf, uint len)
#endif
return;
}
RemoteMac = mac;
//RemoteMac = mac;
/*string name = "Unkown";
switch(type)
@ -344,7 +344,7 @@ void TinyIP::SendIP(IP_TYPE type, const byte* buf, uint len)
ShowIP(RemoteIP);
debug_printf("\r\n");*/
SendEthernet(ETH_IP, (byte*)ip, sizeof(IP_HEADER) + len);
SendEthernet(ETH_IP, mac, (byte*)ip, sizeof(IP_HEADER) + len);
}
#define TinyIP_HELP

View File

@ -65,7 +65,7 @@ public:
IPAddress Mask; // 子网掩码
MacAddress Mac; // 本地Mac地址
MacAddress RemoteMac; // 远程Mac地址
//MacAddress RemoteMac; // 远程Mac地址
IPAddress RemoteIP; // 远程IP地址
IPAddress DHCPServer;
@ -86,7 +86,7 @@ public:
void ShowInfo();
ushort CheckSum(const byte* buf, uint len, byte type);
void SendEthernet(ETH_TYPE type, const byte* buf, uint len);
void SendEthernet(ETH_TYPE type, MacAddress& mac, const byte* buf, uint len);
void SendIP(IP_TYPE type, const byte* buf, uint len);
bool IsBroadcast(IPAddress& ip); // 是否广播地址
};