阅读:1158回复:2
怎样在两个tcp头之间插入数据
我要修改包,原来在一个TCP头前加了一个TCP头,现在要进行改进,还要在两个TCP头之间加入一个4字节的数字,请问如何修改。PNDIS_BUFFER pMyBuffer = NULL;
PNDIS_PACKET pMyPacket = NULL; PVOID pBufferToSend = NULL; // Point to the data. memory new allocated. NDIS_STATUS Status; PRSVD Rsvd; UINT BytesCopied,BytesToCopy; PHEADER_DATA8023 pHeader8023; PHEADER_DATA8022 pHeader8022; PIP_HEADER pIpHeader = NULL; // for the new allocated memory. PTCP_HEADER pTcpHeader = NULL; // for the new allocated memory. PUDP_HEADER pUdpHeader = NULL; // for the new allocated memory. UINT IpHeaderLength; pHeader8023 = (PHEADER_DATA8023)pEtherHeader; pHeader8022 = (PHEADER_DATA8022)pEtherHeader; if(((NetToHostS(pHeader8023->Type)==TYPE_IP) &&(pHeader8023->ipProtocol==IP_TCP)) ||((NetToHostS(pHeader8022->Type)<ETHER_TYPE_MINIMUM) &&(pHeader8022->ipProtocol==IP_TCP))) { TotalPacketLength += sizeof(TCP_HEADER); // We'll copy the TCP header. Status = NdisAllocateMemory(&pBufferToSend, TotalPacketLength, 0, HighestAcceptableMax); } else { TotalPacketLength += sizeof(UDP_HEADER); // We'll copy the UDP header. Status = NdisAllocateMemory(&pBufferToSend, TotalPacketLength, 0, HighestAcceptableMax); } if(NDIS_STATUS_SUCCESS != Status) { NdisMSendComplete( pAdapter->pPrimaryAdapt->MiniportHandle, Packet, Status); return Status; } NdisAllocateBuffer(&Status, &pMyBuffer, pAdapter->SendBufferPoolHandle, pBufferToSend, TotalPacketLength); if(NDIS_STATUS_SUCCESS == Status) { NdisAllocatePacket(&Status, &pMyPacket, pAdapter->SendPacketPoolHandle); if(NDIS_STATUS_SUCCESS == Status) { Rsvd = (PRSVD)(pMyPacket->ProtocolReserved); Rsvd->IsOurs = TRUE; Rsvd->OriginalPkt = Packet; // Rsvd->pBufferToSend = pBufferToSend; pMyPacket->Private.Flags = NdisGetPacketFlags(Packet); NdisSetPacketFlags(pMyPacket, NDIS_FLAGS_DONT_LOOPBACK); pMyPacket->Private.Head = pMyBuffer; pMyPacket->Private.Tail = pMyBuffer; // // Copy the OOB Offset from the original packet to the new // packet. // NdisMoveMemory(NDIS_OOB_DATA_FROM_PACKET(pMyPacket), NDIS_OOB_DATA_FROM_PACKET(Packet), sizeof(NDIS_PACKET_OOB_DATA)); // // Copy the per packet info into the new packet // This includes ClassificationHandle, etc. // Make sure other stuff is not copied !!! // NdisIMCopySendPerPacketInfo(pMyPacket, Packet); if(NetToHostS(pHeader8023->Type) == TYPE_IP) { pIpHeader = (PIP_HEADER)((PUCHAR)pBufferToSend+14); IpHeaderLength = ((pHeader8023->ipVerLen)&0X0F)<<2; if(pHeader8023->ipProtocol == IP_TCP) { BytesToCopy = 14 + IpHeaderLength + sizeof(TCP_HEADER); NdisCopyFromPacketToPacket(pMyPacket, 0, BytesToCopy, Packet, 0, &BytesCopied); BytesToCopy = TotalPacketLength - BytesToCopy; NdisCopyFromPacketToPacket(pMyPacket, BytesCopied, BytesToCopy, Packet, 14 + IpHeaderLength, &BytesCopied); // pIpHeader = (PIP_HEADER)((PUCHAR)pBufferToSend + 14); pIpHeader->ipLength = HostToNetS( (USHORT)((UINT)NetToHostS(pIpHeader->ipLength)+sizeof(TCP_HEADER))); pIpHeader->ipChecksum = 0; pIpHeader->ipChecksum = CheckSum(0, (PUSHORT)pIpHeader, IpHeaderLength); pTcpHeader = (PTCP_HEADER)((PUCHAR)pIpHeader + IpHeaderLength); DbgPrint("Our H323App sending TCP packet, Dest Port:%d\n", NetToHostS(pTcpHeader->destPort)); pTcpHeader->destPort = HostToNetS(WEB_PORT); // Translate the port to 80. pTcpHeader->dataOffset = (pTcpHeader->dataOffset &0X0F)|0x50; pTcpHeader->urgentPointer = 0; pTcpHeader->checkSum = 0; pTcpHeader->checkSum = CheckSumTcp( pIpHeader, pTcpHeader); } |
|
沙发#
发布于:2004-09-10 16:16
楼主的原来在一个TCP头前加了一个TCP头是什么意思?还有两个TCP头之间加入一个4字节的数字?
呵呵,也不太明白,如果你是指在二个tcp包之间在增加一个TCP包呢,还是在原来的包里面增加4个字节 |
|
|
板凳#
发布于:2004-09-12 13:03
一样的修改,注意校验正确
|
|
|