看看我写的DSL(2)-数据包匹配
fineqtbull
2009-11-16
刚把数据包匹配部分写好,贴上来晒晒。数据包包创建部分请看别贴(1)。
//数据包创建,请看别贴(1) ... //打印 ValueDumper.dump(pingRequest) //匹配数据包 pingRequest match { case ^^^(Name("EtherProtocol"), ^^(Name("EtherProtocol"), ^("dstAddress", AS.MAC("11:22:33:44:55:66")), ^("srcAddress", AS.MAC("22:22:33:44:55:66")), ^("etherType", VI(0x0800)), ^("payload", ^("ipv4", ^("header", ^("version", VI(4)), ^("headerLength", VI(0)), ^("typeOfService", BS("00000000")), ^("totalLength", VI(0)), ^("identification", VI(1)), ^("reserved", VI(0)), ^("doNotFrag", VB(false)), ^("moreFrags", VB(false)), ^("fragmentOffset", VI(0)), ^("timeToLive", VI(255)), ^("protocol", VI(1)), ^("hcs", _), ^("sourceAddress", AS.IPV4("192.168.1.1")), ^("destinationAddress", AS.IPV4("192.168.1.2")), ^("options", ^(_, ^("security", ^("optionType", VI(130)), _* ) ), ^(_, ^("lssr", ^("optionType", VI(131)), _* ) ) ) ), ^("payload", ^("icmpv4", ^("echoRequest", ^("icmpType", VI(8)), ^("icmpCode", VI(0)), ^("checksum", _), ^("identifier", VI(100)), ^("sequenceNumber", VI(1000)), ^("data", _) ) ) ) ) ), ^("fcs", _)))=> println("matching OK" ) } 执行结果: 0:66 EtherProtocol.EtherProtocol 0:6 dstAddress 11:22:33:44:55:66 6:6 srcAddress 22:22:33:44:55:66 12:2 etherType 2048 IPv4 14:48 payload 14:48 ipv4 Ipv4Protocol.Ipv4Protocol 14:48 Ipv4Protocol.Ipv4Protocol 14:36 header 14:1 0000---- 4 version 0xF0 14:1 ----0000 0 headerLength 0x0F 15:1 typeOfService '00000000'B 16:2 totalLength 0 18:2 identification 1 20:1 0--------------- 0 reserved 0x8000 20:1 -0-------------- false doNotFrag 0x4000 20:1 --0------------- false moreFrags 0x2000 20:2 ---0000000000000 0 fragmentOffset 0x1FFF 22:1 timeToLive 255 23:1 protocol 1 ICMP: Internet Control Message Protocol 24:2 hcs '0000'O 26:4 sourceAddress 192.168.1.1 30:4 destinationAddress 192.168.1.2 34:16 options 34:12 [0] 34:12 security 34:1 optionType 130 35:1 optionLength 0 36:2 security 30874 EFTO 38:2 compartments 0 40:2 handling 0 42:3 tcc 0 45:1 nop 1 46:4 [1] 46:4 lssr 46:1 optionType 131 47:1 optionLength 0 48:1 pointer 100 49:0 routeData 49:1 nop 1 50:12 payload 50:12 icmpv4 Icmpv4Protocol.Icmpv4Protocol 50:12 Icmpv4Protocol.Icmpv4Protocol 50:12 echoRequest 50:1 icmpType 8 51:1 icmpCode 0 52:2 checksum '0000'O 54:2 identifier 100 56:2 sequenceNumber 1000 58:4 data '01020304'O 62:4 fcs '00000000'O matching OK |