[IP]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 11 Feb 2017 23:13:45 +0000 (23:13 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 11 Feb 2017 23:13:45 +0000 (23:13 +0000)
- Handle chained pbuf structures in TCPSendDataCallback
CORE-10715

svn path=/trunk/; revision=73779

reactos/sdk/lib/drivers/ip/transport/tcp/if.c

index 83e124f..ba697a3 100644 (file)
@@ -15,6 +15,8 @@ TCPSendDataCallback(struct netif *netif, struct pbuf *p, struct ip_addr *dest)
     IP_PACKET Packet;
     IP_ADDRESS RemoteAddress, LocalAddress;
     PIPv4_HEADER Header;
+    ULONG Length;
+    ULONG TotalLength;
 
     /* The caller frees the pbuf struct */
 
@@ -39,7 +41,7 @@ TCPSendDataCallback(struct netif *netif, struct pbuf *p, struct ip_addr *dest)
     {
         return ERR_RTE;
     }
-    
+
     NdisStatus = AllocatePacketWithBuffer(&Packet.NdisPacket, NULL, p->tot_len);
     if (NdisStatus != NDIS_STATUS_SUCCESS)
     {
@@ -49,19 +51,22 @@ TCPSendDataCallback(struct netif *netif, struct pbuf *p, struct ip_addr *dest)
     GetDataPtr(Packet.NdisPacket, 0, (PCHAR*)&Packet.Header, &Packet.TotalSize);
     Packet.MappedHeader = TRUE;
 
-    if (p->tot_len != p->len ||
-        Packet.TotalSize != p->len)
+    ASSERT(Packet.TotalSize == p->tot_len);
+
+    TotalLength = p->tot_len;
+    Length = 0;
+    while (Length < TotalLength)
     {
-        DbgPrint("TCPSendDataCallback: tot_len = %u, len = %u, TotalSize = %u\n",
-                 p->tot_len, p->len, Packet.TotalSize);
-        ASSERT(p->tot_len == p->len);
-        ASSERT(Packet.TotalSize == p->len);
+        ASSERT(p->len <= TotalLength - Length);
+        ASSERT(p->tot_len == TotalLength - Length);
+        RtlCopyMemory((PCHAR)Packet.Header + Length, p->payload, p->len);
+        Length += p->len;
+        p = p->next;
     }
-
-    RtlCopyMemory(Packet.Header, p->payload, p->len);
+    ASSERT(Length == TotalLength);
 
     Packet.HeaderSize = sizeof(IPv4_HEADER);
-    Packet.TotalSize = p->tot_len;
+    Packet.TotalSize = TotalLength;
     Packet.SrcAddr = LocalAddress;
     Packet.DstAddr = RemoteAddress;
 
@@ -77,9 +82,9 @@ TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF)
 {
 #if 0
     ULONG OperationalStatus;
-    
+
     GetInterfaceConnectionStatus(IF, &OperationalStatus);
-    
+
     if (OperationalStatus == MIB_IF_OPER_STATUS_OPERATIONAL)
         netif_set_link_up(IF->TCPContext);
     else