📄 utilrtns.c
字号:
{
INT cbLine;
while (cb)
{
cbLine = (cb < DUMP_BytesPerLine) ? cb : DUMP_BytesPerLine;
DumpLine( p, cbLine, bPrependWAddr, ulGroup );
cb -= cbLine;
p += cbLine;
}
}
/**************************************************************************************************/
/* */
/* Derived from offload.c in DDK's \src\network\ndis\e100bex\. */
/* */
/**************************************************************************************************/
VOID
e100DumpPkt(IN PNDIS_PACKET pPacket)
{
PNDIS_BUFFER pPrevNdisBfr;
PNDIS_BUFFER pNdisBfr;
do
{
//
// Get first buffer of the packet
//
pNdisBfr = pPacket->Private.Head;
pPrevNdisBfr = NULL;
//
// Scan the buffer chain
//
while (pNdisBfr != NULL)
{
PVOID pVa = NULL;
ULONG BufLen = 0;
BufLen = NdisBufferLength(pNdisBfr);
pVa = NdisBufferVirtualAddress(pNdisBfr);
pPrevNdisBfr = pNdisBfr;
pNdisBfr = pNdisBfr->Next;
if (pVa == NULL)
{
continue;
}
DBGPRINT(("Mdl @ %p. Va = 0x%p. Len = 0x%08x.\n", pPrevNdisBfr, pVa, BufLen));
DumpMem( (CHAR* )pVa, BufLen, TRUE, 1 );
}
} while (FALSE);
}
//****************************************************************************//
//* //
//* Copyright (C) 2003, James Antognini, antognini@mindspring.com. //
//* //
//****************************************************************************//
/**************************************************************************************************/
/* */
/* Calculate TCP checksum, based on TCP datagram (TCP header + data) and pseudo-header. */
/* */
/* Derived in part from from RFC 1071, section 4.1, p 7, and in part from DDK \e100bex\offload.h. */
/* */
/* Notes: */
/* */
/* 1) This routine is written for a little-endian environment (eg, x86). It has been tested */
/* and used in WinXP user- and kernel-space environments. */
/* */
/* 2) This routine assumes the checksum field in the TCP header has been set to 0, in order */
/* to compute the checksum. */
/* */
/* 3) This routine, as is, cannot be used to check a checksum, because checking a checksum */
/* involves getting the one's complement sum over the TCP datagram, with the checksum */
/* included (see RFC 1071, p 1), but this routine does that summing and then returns the */
/* one's complement of that sum. That is, this routine will, if a checksum is correct, */
/* yield 0xffff in the folding statement below but then will return the one's complement */
/* of 0xffff, which is 0. */
/* */
/**************************************************************************************************/
USHORT
GetTCPChecksum(
PUSHORT pTCPFd, // Pointer to TCP datagram (header + data).
PUSHORT pSrcAddr, // Address of source IP address (in network format).
PUSHORT pDestAddr, // Address of destination IP address (in network format).
USHORT usTCPFd // Length of TCP datagram (header + data).
)
{
#define JADrvRtnsVer "1.01"
#define lnPseudoHdr 12 // Size of pseudo-header.
char PseudoHdrArr[lnPseudoHdr]; // Pseudo-header.
USHORT usPsHdr = lnPseudoHdr; // Length of pseudo-header.
PUSHORT pPseudoHdr = (PUSHORT)PseudoHdrArr; // Pointer to pseudo-header.
ULONG sum = 0;
// Note: The one's complement addition done for the TCP datagram and for the pseudo-header is effected
// with little-endian PUSHORT variables. Because of the associativity of addition, that produces
// a good result except that the bytes have to be swapped in the return statement. (The data
// being checked-summed are, as always, in network (big-endian) order; eg, if the length of the
// TCP datagram used in the pseudo-header is 0x95, the value is stored as 0x0095 in memory, not
// as 0x9500.)
// Build the pseudo-header field.
memcpy(PseudoHdrArr, pSrcAddr, 4); // Copy source IP address.
memcpy(PseudoHdrArr+4, pDestAddr, 4); // Copy destination IP address.
PseudoHdrArr[8] = 0; // Set to 0.
PseudoHdrArr[9] = IPPROTO_TCP; // Set to TCP protocol constant.
pPseudoHdr[5] = // Put length of entire TCP datagram into pseudo-header.
(USHORT)(((usTCPFd&0xFF00)>>8) + ((usTCPFd&0x00FF)<<8));
// Do one's complement addition of pseudo-header.
while(usPsHdr > 0)
{
sum += *pPseudoHdr++;
usPsHdr -= 2;
}
// Do one's complement addition of TCP field, except for the last byte if the field length is odd.
while(usTCPFd > 1)
{
sum += *pTCPFd++;
usTCPFd -= 2;
}
// Add left-over byte, if any.
if(usTCPFd > 0)
sum += *(PUCHAR)pTCPFd;
// Fold 32-bit sum to 16 bits (form per offload.h in DDK \e100bex).
sum = (((sum >> 16) | (sum << 16)) + sum) >> 16;
// Return one's complement (in little-endian form, by the way).
return (USHORT)~sum;
} // End GetTCPChecksum().
//****************************************************************************//
//* //
//* Derived from Ping.cpp in SDK Samples\netds\WinSock\Ping. //
//* //
//****************************************************************************//
USHORT
GetIPChecksum(PUSHORT pIPH, USHORT usIPHdr)
{
ULONG cksum = 0;
while (usIPHdr > 1)
{
cksum += *pIPH++;
usIPHdr -= sizeof(USHORT);
}
cksum = (((cksum >> 16) | (cksum << 16)) + cksum) >> 16;
return (USHORT)~cksum;
} // End GetIPChecksum().
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -