根据IP头修正数据长度,测试没有什么变化

This commit is contained in:
Stone 2014-12-05 12:10:56 +00:00
parent c197f8951e
commit 93d17c1373
4 changed files with 19 additions and 9 deletions

View File

@ -71,7 +71,7 @@ bool OnTcpReceived(TcpSocket* socket, TCP_HEADER* tcp, byte* buf, uint len)
bool HttpReceived(TcpSocket* socket, TCP_HEADER* tcp, byte* buf, uint len)
{
debug_printf("Http::Received From ");
debug_printf("Http:Received From ");
TinyIP::ShowIP(socket->RemoteIP);
debug_printf(":%d with Payload=%d ", socket->RemotePort, len);
Sys.ShowString(buf, len);
@ -90,6 +90,7 @@ void HttpSend(void* param)
// 连接
byte ip[] = {192, 168, 0, 84};
tcp.Connect(*(uint*)ip, 80);
debug_printf("\r\n");
// 发送数据
byte str[] = "GET / HTTP/1.1\r\nHost: 192.168.0.84\r\n\r\n\r\n";

View File

@ -96,10 +96,10 @@ void TcpSocket::OnProcess(TCP_HEADER* tcp, MemoryStream& ms)
uint len = ms.Remain();
#if NET_DEBUG
debug_printf("Tcp::Process Flags=0x%02x From ", tcp->Flags);
/*debug_printf("Tcp::Process Flags=0x%02x From ", tcp->Flags);
TinyIP::ShowIP(RemoteIP);
debug_printf(":%d", RemotePort);
debug_printf("\r\n");
debug_printf("\r\n");*/
#endif
// 下次主动发数据时用该序列号因为对方Ack确认期望下次得到这个序列号
@ -449,6 +449,7 @@ bool Callback(TinyIP* tip, void* param, MemoryStream& ms)
// 处理。如果对方回发第二次握手包,或者终止握手
//MemoryStream ms(tip->Buffer, tip->BufferSize);
tip->FixPayloadLength(_ip, &ms);
socket->Process(&ms);
return true;

View File

@ -134,12 +134,7 @@ void TinyIP::Process(MemoryStream* ms)
//if(Arp && Arp->Enable) Arp->Process(NULL);
if(Arp) Arp->Process(NULL);
// 前面的len不准确必须以这个为准
uint size = __REV16(ip->TotalLength) - (ip->Length << 2);
ms->Length = ms->Position() + size;
//len = size;
//buf += (ip->Length << 2);
ms->Seek((ip->Length << 2) - sizeof(IP_HEADER));
FixPayloadLength(ip, ms);
// 各处理器有可能改变数据流游标,这里备份一下
uint p = ms->Position();
@ -170,6 +165,17 @@ void TinyIP::Process(MemoryStream* ms)
#endif
}
// 修正IP包负载数据的长度。物理层送来的长度可能有误一般超长
void TinyIP::FixPayloadLength(IP_HEADER* ip, MemoryStream* ms)
{
// 前面的len不准确必须以这个为准
uint size = __REV16(ip->TotalLength) - (ip->Length << 2);
ms->Length = ms->Position() + size;
//len = size;
//buf += (ip->Length << 2);
ms->Seek((ip->Length << 2) - sizeof(IP_HEADER));
}
// 任务函数
void TinyIP::Work(void* param)
{

View File

@ -57,6 +57,8 @@ public:
bool LoopWait(LoopFilter filter, void* param, uint msTimeout);
// 处理数据包
void Process(MemoryStream* ms);
// 修正IP包负载数据的长度。物理层送来的长度可能有误一般超长
void FixPayloadLength(IP_HEADER* ip, MemoryStream* ms);
public:
IPAddress IP; // 本地IP地址