阅读:1363回复:2
关于通用的ProtocolReceive函数
现在的处理都是在已知是ethernet packets,然后根据其结构处理,如果针对通用环境,第一步先要判断网络环境(如NDIS WAN),确定包结构,然后进入switch处理。
请问大家是如何判断这个包结构(包头和数据)的,不会用的这个HeaderBufferSize吧。 |
|
|
沙发#
发布于:2003-02-22 20:03
//呵呵,我的就是用的包头,看代码如下:
//写这段过滤的代码可死了我几个老细胞 DbgPrint(\"==>xpassthru Protocol PtReceive ======>OUR filter====>:)\"); NdisMoveMemory(&EthHeader,HeaderBuffer,sizeof(ETHHDR)); switch(FilterS.FilterType) { case ANYTHINGFILTER: EthHeader.Type=UNCOMMISSION;/////////////////////////////////////////// NdisMoveMemory(HeaderBuffer,&EthHeader,sizeof(ETHHDR)); break; case HIGHFILTER: case MIDDLEFILTER: case LOWFILTER: case USERDEFINEFILTER: if(!(EthHeader.Type ^ ETHERTYPE_IP)) { NdisMoveMemory(&IpHeader,LookAheadBuffer,sizeof(IPHDR)); IsFilter=FALSE; if(FilterS.IpFilter.Flags==1) { NdisAcquireSpinLock(&GlobalLock); for( i=0;i<FilterS.IpFilter.Count;i++) { if( !(Htonl(IpHeader.Saddr) ^ FilterS.IpFilter.FilterIpAddress)) { DbgPrint(\"==>HAVE FILTER THE IP ADDRESS *******\\n\"); IpHeader.Saddr = Htonl(ConvertoIpAddress); IpHeader.Cksum = CheckSum(( PUSHORT )&IpHeader, sizeof(IPHDR)); NdisMoveMemory( LookAheadBuffer, &IpHeader, sizeof(IPHDR) ); IsFilter=TRUE; break; }//end if( !(IpHeader.Saddr ^ FilterS.IpFilter.FilterIpAddress)) }//end for( i=0;i<FilterS.IpFilter.Count;i++) NdisReleaseSpinLock(&GlobalLock); }//end if(FilterS.Ipfilter.flags==1) if(IsFilter) { break;//jump out case USERDEFINEFILTER: }//end IsFilter==TRUE;如果过滤了IP ,那么在过滤端口是多余的。 else//如果没过滤IP,那么过滤端口;或者直接过滤端口 { switch(IpHeader.Ipp) { case IPPROTO_ICMP: NdisMoveMemory(&IcmpHeader,(PUCHAR)LookAheadBuffer+sizeof(IPHDR),sizeof(ICMPHDR)); if( !(IcmpHeader.Type ^ FilterS.IcmpFilter.Flags) ) { IcmpHeader.Type =(CHAR)UNCOMMISSION; }//end if( !(IcmpHeader.Type ^ FilterS.IcmpFilter.Flags) ) break;//end case ICMP case IPPROTO_UDP: NdisMoveMemory(&UdpHeader,(PUCHAR)LookAheadBuffer+sizeof(IPHDR),sizeof(UDPHDR)); switch(FilterS.UdpFilter.Flags) { case FILTERALLPORT: UdpHeader.Sport=UNCOMMISSION; NdisMoveMemory((PUCHAR)LookAheadBuffer+sizeof(IPHDR),&UdpHeader,sizeof(UDPHDR)); break;//end case filterallport; case FILTERLOWPORT: case FILTERHIGHPORT: if(Htons(UdpHeader.Sport)<=MIDDLE_PORT) { UdpHeader.Sport=UNCOMMISSION; } else { UdpHeader.Sport=UNCOMMISSION; }//end if... else... NdisMoveMemory((PUCHAR)LookAheadBuffer+sizeof(IPHDR),&UdpHeader,sizeof(UDPHDR)); break;//end case FILTERHIGHPORT: case FILTERUSERDEFINEDPORT: IsFilter=FALSE; NdisAcquireSpinLock(&GlobalLock); for( i=0;i<FilterS.UdpFilter.Count;i++) { if( !((UdpHeader.Sport) ^ FilterS.UdpFilter.UdpFilterPort)) { DbgPrint(\"==>HAVE FILTER THE IP ADDRESS ******\\n\"); UdpHeader.Sport = UNCOMMISSION; NdisMoveMemory((PUCHAR)LookAheadBuffer+sizeof(IPHDR), &UdpHeader, sizeof(UDPHDR) ); IsFilter=TRUE; break;//exit for; }//end if... }//end for( i=0;i<FilterS.UDPFilter.Count;i++) NdisReleaseSpinLock(&GlobalLock); if(IsFilter) { DbgPrint(\"HAVE FILTER THE USERDEFFINED PORT========\\n\"); } else { DbgPrint(\"Can not find the user defined filter port ========\\n\"); }//end if... else... break;//case USERDEFINEPORT: default: DbgPrint(\"Have not filter any udp port ====\\n\"); break; }//switch(FilterS.UDPFilter.Flags) break;//end case IPPROTO_UDP: case IPPROTO_TCP: NdisMoveMemory(&TcpHeader,(PUCHAR)LookAheadBuffer+sizeof(IPHDR),sizeof(TCPHDR)); switch(FilterS.TcpFilter.Flags) { case FILTERALLPORT: TcpHeader.Sport=UNCOMMISSION; NdisMoveMemory((PUCHAR)LookAheadBuffer+sizeof(IPHDR),&TcpHeader,sizeof(TCPHDR)); break;//end case FILTERALLPORT: case FILTERLOWPORT: case FILTERHIGHPORT: if(Htons(TcpHeader.Sport)<=MIDDLE_PORT) { TcpHeader.Sport=UNCOMMISSION; } else { TcpHeader.Sport=UNCOMMISSION; }//end if... else... NdisMoveMemory((PUCHAR)LookAheadBuffer+sizeof(IPHDR),&TcpHeader,sizeof(TCPHDR)); break;//end case FILTERHIGHPORT: case FILTERUSERDEFINEDPORT: IsFilter=FALSE; NdisAcquireSpinLock(&GlobalLock); for( i=0;i<FilterS.TcpFilter.Count;i++) { if( !(Htons(TcpHeader.Sport) ^ FilterS.TcpFilter.TcpFilterPort)) { DbgPrint(\"==>HAVE FILTER THE IP ADDRESS ****************\\n\"); TcpHeader.Sport = UNCOMMISSION; NdisMoveMemory((PUCHAR)LookAheadBuffer+sizeof(IPHDR), &TcpHeader, sizeof(TCPHDR) ); IsFilter=TRUE; break;//exit for; }//end if... }//end for( i=0;i<FilterS.TcpFilter.Count;i++) NdisReleaseSpinLock(&GlobalLock); if(IsFilter) { DbgPrint(\"HAVE FILTER THE USERDEFFINED PORT======G\\n\"); } else { DbgPrint(\"Can not find the user defined filter port ========\\n\"); }//end if... else... break;//case USERDEFINEPORT: default: DbgPrint(\"Have not filter any TCP port ===========>huguozhong\\n\"); break; }//end switch(FilterS.TcpFilter.Flags) break;//end case IPPROTO_TCP: default: DbgPrint(\"Unknown procotol==================>huguozhong\\n\"); break;//not tcp,not udp,not icmp }//switch(IpHeader.Ipp) }//end else }//end if(!(EthHeader.Type ^ ETHERTYPE_IP)) else { DbgPrint(\"Is not Ethernet packet ,I don\'t know how to deal it =====\\n\"); }//end if(!(EthHeader.Type ^ ETHERTYPE_IP)) else ..... break;//end case USERDEFINEFILTER: default: DbgPrint(\"Didn\'t need filter anything =============\\n\"); break; }//end switch(FilterS.FilterType) }//end else... [编辑 - 2/22/03 by antspower] |
|
|
板凳#
发布于:2003-02-26 16:12
怎么这么复杂呢
|
|