阅读:2594回复:33
斑竹们请进来...
原问题:
封包packet定义为PNDIS_PACKET结构。 我现在想从此包中得到源IP地址和目标IP地址,能实现吗?怎样实现? 小弟急用,请那位大侠帮帮忙!! ////////////////////////////// (新问题: 偶把它放到自已的程序里进行编译时,ExAllocatePool()函数编译时提示没定义,后来偶把\"ntddk.h\"头文件包含进来也不行,小弟查了DDK看了一下,但问题还是没办法解决,因fracker版主不在线,小弟急死了!还请各老大指点一二.) fracker版主的贴子如下: 把Packet里面的数据Dump出来: //////////////////////////// UINT CopyPacketData( PNDIS_PACKET pPacket, PCHAR pData, UINT iSize ) { UINT iLength; UINT iPos; PNDIS_BUFFER pNextBuffer; PCHAR pBuffer; iPos = 0; NdisQueryPacket( pPacket, NULL, NULL, &pNextBuffer, &iLength ); if( iLength > iSize ) return iPos; while( pNextBuffer ) { NdisQueryBuffer( pNextBuffer, &pBuffer, &iLength ); if( iLength > iSize - iPos || !pBuffer ) break; NdisMoveMemory( pData + iPos, pBuffer, iLength ); NdisGetNextBuffer( pNextBuffer, &pNextBuffer ); iPos += iLength; } return iPos; } ///////////////////////////////////////////////// typedef struct _EthHead { EthAddr DestAddr; EthAddr SourAddr; unsigned short SrvType; } EthHead, * PEthHead; typedef struct _IpHead { unsigned char HeaderLength_Version; unsigned char TypeOfService; // Type of service unsigned short TotalLength; // total length of the packet unsigned short Identification; // unique identifier unsigned short FragmentationFlags; // flags unsigned char TTL; // Time To Live unsigned char Protocol; // protocol (TCP, UDP etc) unsigned short CheckSum; // IP Header checksum unsigned int sourceIPAddress; // Source address unsigned int destIPAddress; // Destination Address } IpHead, *PIpHead; u_long GetSrcIpFromPacket( PNDIS_PACKET pPacket ) { PCHAR pData; UINT iTotal; PEthHead pEthHdr; PIpHead pIpHdr; NdisQueryPacket( pPacket, NULL, NULL, NULL, &iTotal ); pData = ExAllocatePool( NonPagedPool, iTotal ); CopyPacketData( pPacket, pData, iTotal ); pEthHdr = ( PEthHead )pData; pIpHdr = ( PIpHead )( pData + sizeof( EthHead ) ); return pIpHdr->sourceIPAddress; } [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] |
|
沙发#
发布于:2002-11-06 17:07
好不容易才编译通过,但我在自已的程序里
DbgPrint(\"destIPAddress结果为:%u\",GetSrcIpFromPacket(packet)); 的时候,怎么结果都是一串长数呢?能不能将其显示为IP地址的格式呢? 高手们出手相救呀!!!! :( 搞掂了 [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] |
|
板凳#
发布于:2002-11-06 14:43
吃完了饭回来,帮你编译通过,想上来告诉你的,没想到你已经解决了,那就行了。 谢谢!! |
|
地板#
发布于:2002-11-06 13:19
吃完了饭回来,帮你编译通过,想上来告诉你的,没想到你已经解决了,那就行了。
|
|
地下室#
发布于:2002-11-06 11:41
非常感谢!!!
[编辑 - 11/6/02 by bhjinhou] [编辑 - 11/6/02 by bhjinhou] |
|
5楼#
发布于:2002-11-06 11:39
[quote]在调用ndis里调用ExAllocatePool()函数不用包含\"ntddk.h\"或\"wdm.h\",你只需在文件的顶部加上一句: 没错,偶是犯了一个大错误,搞定了,非常感谢各位!!! [/quote] 如果你想在ndis里包含\"ntddk.h\"来完成,累死你都不能编译成功! [编辑 - 11/6/02 by dazzy] |
|
6楼#
发布于:2002-11-06 11:32
改成:
#include \"ntddk.h\" #include \"ndis.h\" #include \"xpassthru.h\" #include \"minihook.h\" #include \"prothook.h\" #include \"packet.h\" |
|
|
7楼#
发布于:2002-11-06 11:31
在调用ndis里调用ExAllocatePool()函数不用包含\"ntddk.h\"或\"wdm.h\",你只需在文件的顶部加上一句: 没错,偶是犯了一个大错误,搞定了,非常感谢各位!!! |
|
8楼#
发布于:2002-11-06 11:19
在调用ndis里调用ExAllocatePool()函数不用包含\"ntddk.h\"或\"wdm.h\",你只需在文件的顶部加上一句:
#define NDIS_WDM 1 即可. |
|
9楼#
发布于:2002-11-06 11:09
[quote]最好将ntddk.h放在靠前的位置! 我将位置调换如下,但还是那一句提示。 #include \"ndis.h\" #include <ntddk.h> #include \"xpassthru.h\" #include \"minihook.h\" #include \"prothook.h\" #include \"packet.h\" //#include \"recv.h\" //#include \"send.h\" [编辑 - 11/6/02 by bhjinhou] [/quote] 你可能犯了一个错误,不能同时包含ntis.h和TNDDK.h头文件,这会造成重复声明。 |
|
|
10楼#
发布于:2002-11-06 11:02
太没道理! 这些我早就试过了,我还把ntddk.h文件考到同一目录呢!! |
|
11楼#
发布于:2002-11-06 11:01
太没道理!
改为 include \"ntddk.h\"? |
|
|
12楼#
发布于:2002-11-06 10:54
我真拿它没办法,这个函数本来就是w2kddk 里的<ntddk.h>调用,怎么会出错呢!!!!唉!!!唉!!!
我本来的程序(如没有加上前面那两段的话)编译是没问题的。 [编辑 - 11/6/02 by bhjinhou] |
|
13楼#
发布于:2002-11-06 10:50
最好将ntddk.h放在靠前的位置! 我将位置调换如下,但还是那一句提示。 #include \"ndis.h\" #include <ntddk.h> #include \"xpassthru.h\" #include \"minihook.h\" #include \"prothook.h\" #include \"packet.h\" //#include \"recv.h\" //#include \"send.h\" [编辑 - 11/6/02 by bhjinhou] |
|
14楼#
发布于:2002-11-06 10:44
最好将ntddk.h放在靠前的位置!
|
|
|
15楼#
发布于:2002-11-06 10:41
你应该将packet.h放在ntddk.h后面!!
|
|
|
16楼#
发布于:2002-11-06 10:35
sorry,我写错了。用不着再加! 没关系的,我的那些头文件: #include \"ndis.h\" #include \"xpassthru.h\" #include \"minihook.h\" #include \"prothook.h\" #include \"packet.h\" #include <ntddk.h> #include \"recv.h\" #include \"send.h\" 统一放到 prexsim.h 预编译头文件里会不会有问题。 程序入口是从xpassthru.c开始。 编译提示还是: packet.c<151>:error c4013:\'ExAllocatePoolWithTag\' undefined;assuming extern returning int 就这一两句了。 [编辑 - 11/6/02 by bhjinhou] |
|
17楼#
发布于:2002-11-06 10:31
sorry,我写错了。用不着再加!
|
|
|
18楼#
发布于:2002-11-06 10:28
再加两句试一下:
#undef ExAllocatePool #undef ExAllocatePoolWithTag #define ExAllocatePoolWithQuota(a,b) xAllocatePoolWithQuotaTag(a,b,\' kdD\') #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a, b, \'kcaP\') |
|
|
19楼#
发布于:2002-11-06 10:16
那你在DOS下用BUILD编译试以下。 我现在用的是Windows2000高级服务器版,不能换到DOS下。 ________________________________________________ 做程序真烦人... |
|
上一页
下一页