阅读:1860回复:3
在线等高手解答啊~ 关于MPSendPackets里获取目标ip问题~
MPSendPackets(
IN NDIS_HANDLEMiniportAdapterContext, IN PPNDIS_PACKET PacketArray, IN UINT NumberOfPackets ) { struct ip IPHeader; ULONGNumberOfBytesRead; USHORT IPHeaderLen; USHORT IpCkSum,IpCkSum1; //略 FltReadOnPacket( Packet, &IPHeader, sizeof( IPHeader ), sizeof( struct ether_header ), &NumberOfBytesRead );//读取IP包头 DbgPrint("IP包头长度=%d",IPHeader.ip_hl); DbgPrint("版本=%d",IPHeader.ip_v); DbgPrint("IP包长度=%d",IPHeader.ip_len); DbgPrint("生存时间=%d",IPHeader.ip_ttl); DbgPrint("协议=%d",IPHeader.ip_p); DbgPrint("头部校验和=%d",IPHeader.ip_sum); DbgPrint("源IP地址=%d",IPHeader.ip_src); DbgPrint("目的IP地址=%d",IPHeader.ip_dst); IpCkSum=IPHeader.ip_sum;//先暂存一下校验和 IPHeaderLen=(IPHeader.ip_hl)*4; IPHeader.ip_sum = 0; // Clear old IP checksum value. IpCkSum1=GetIPChecksum((PUSHORT)(&IPHeader), IPHeaderLen); DbgPrint("头部校验和=%d",IPHeader.ip_sum);//这时=0 DbgPrint("头部校验和=%d",IpCkSum); IPHeader.ip_sum = IpCkSum1; //我用DbgPrint看到 IpCkSum1和IpCkSum是相等的,但如果用IpCkSum就可以,用 IpCkSum1就不行,奇怪不? DbgPrint("头部校验和1=%d",IpCkSum1); DbgPrint("重新计算后头部校验和=%d",IPHeader.ip_sum); FltWriteOnPacket( Packet, &IPHeader, sizeof( IPHeader ), sizeof( struct ether_header ), &NumberOfBytesRead );//写回原来的数据包中 DbgPrint("写入字节数=%d",NumberOfBytesRead); //略 } 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; } 这个代码里头的struct ip IPHeader; 结构怎么定义呀?? |
|
沙发#
发布于:2010-04-10 13:49
我想MPSendPackets里面 打印出 目标ip地址啊。 哪位高手贴出代码,小生感激不尽!
|
|
板凳#
发布于:2010-04-12 10:13
ip头结构都不知道,怎么做这个东东?
找本介绍tcp/ip的书,都有ip头结构,最简单就是找rfc里面有详细的ip头结构 |
|
|
地板#
发布于:2010-04-12 22:00
typedef struct _TESTPROV_IP4_HEADER { UCHAR VersionHdrLen; UCHAR TOS; UCHAR TotalLength[2]; UCHAR Identifier[2]; UCHAR FlagsFragmentOffset[2]; UCHAR TTL; UCHAR Protocol; UCHAR HeaderChecksum[2]; UCHAR SourceIP[4]; UCHAR DestinationIP[4]; } TESTPROV_IP4_HEADER, *PTESTPROV_IP4_HEADER; |
|