@Override public void nextPacket(JPacket packet, StringBuilder errbuf) { String source = ""; String destination = ""; String printResult = ""; try { packet.getHeader(ipv4); if (!(ipv4.source()).equals(null)) { source = FormatUtils.ip(ipv4.source()); } if (!(ipv4.destination()).equals(null)) { destination = FormatUtils.ip(ipv4.destination()); } // textPane1.setText(textPane1.getText() + "> Source ip = " + source + "; Destination ip = " // + destination + "\n"); printResult = "> Source ip = " + source + "; Destination ip = " + destination + "\n"; } catch (Exception e) { printResult = printResult + "!!! Exception ip IP Addr > " + e.getCause() + "\n"; textPane1.append(printResult); // textPane1.setCaretPosition(textPane1.getDocument().getLength()); } if (packet.hasHeader(Sip.ID)) { packet.getHeader(sip1); printResult = printResult + "> sip1.getMethod().name() = " + sip1.getMethod().name() + "\n"; } if (packet.hasHeader(Rtp.ID)) { packet.getHeader(rtp1); printResult = printResult + "> rtp1.csrcLength() = " + rtp1.csrcLength() + "; rtp1.csrc() = " + rtp1.csrc() + "; rtp1.ssrc()" + rtp1.ssrc() + "\n"; } /* if (packet.hasHeader(Tcp.ID)) { packet.getHeader(tcp); printResult = printResult + "> tcp.dst_port = " + tcp.destination() + "; tcp.src_port = " + tcp.source() + "; tcp.ack = " + tcp.ack() + "\n"; } if (packet.hasHeader(Udp.ID)) { packet.getHeader(udp1); printResult = printResult + "> udp.dst_port = " + udp1.destination() + "; udp.src_port = " + udp1.source() + "\n"; } */ textPane1.append(printResult + "Frame " + packet.getFrameNumber() + " \n"); // textPane1.setCaretPosition(textPane1.getDocument().getLength()); }
/** * Test sub header access. * * @throws IOException Signals that an I/O exception has occurred. */ public void testSubHeaderAccess() throws IOException { Ip4 ip = new Ip4(); Ip4.Timestamp ts = new Ip4.Timestamp(); Ip4.LooseSourceRoute lsroute = new Ip4.LooseSourceRoute(); Ip4.StrictSourceRoute ssroute = new Ip4.StrictSourceRoute(); Ip4.RecordRoute record = new Ip4.RecordRoute(); JPacket packet = TestUtils.getPcapPacket("tests/test-icmp-recordroute-opt.pcap", 0); JFormatter out = new TextFormatter(); out.format(packet); assertNotNull(packet); assertTrue(packet.hasHeader(ip)); assertTrue(ip.hasSubHeaders()); assertFalse(ip.hasSubHeader(lsroute)); assertFalse(ip.hasSubHeader(ssroute)); assertFalse(ip.hasSubHeader(ts)); assertTrue(ip.hasSubHeader(record)); assertEquals(9, record.addressCount()); byte[] b = record.address(0); assertNotNull(b); assertEquals(4, b.length); assertEquals(-64, b[0]); // 192 in unsinged int assertEquals(-88, b[1]); // 168 in unsigned int assertEquals(1, b[2]); // 1 assertEquals(13, b[3]); // 13 assertNotNull(packet); assertTrue(packet.hasHeader(ip)); assertTrue(ip.hasSubHeaders()); assertFalse(ip.hasSubHeader(lsroute)); assertFalse(ip.hasSubHeader(ssroute)); assertFalse(ip.hasSubHeader(ts)); assertTrue(ip.hasSubHeader(record)); assertEquals(9, record.addressCount()); /* * Now do it a second time without resetting the packet */ b = record.address(0); assertNotNull(b); assertEquals(4, b.length); assertEquals(-64, b[0]); // 192 in unsinged int assertEquals(-88, b[1]); // 168 in unsigned int assertEquals(1, b[2]); // 1 assertEquals(13, b[3]); // 13 }
/** Test syntax text. */ public void testSyntaxText() { Ip4 ip = new Ip4(); Ip4.Timestamp ts = new Ip4.Timestamp(); Ip4.LooseSourceRoute lsroute = new Ip4.LooseSourceRoute(); Ip4.StrictSourceRoute ssroute = new Ip4.StrictSourceRoute(); Ip4.RecordRoute record = new Ip4.RecordRoute(); JPacket packet = TestUtils.getPcapPacket("tests/test-icmp-recordroute-opt.pcap", 0); if (packet.hasHeader(ip) && ip.hasSubHeaders()) { if (ip.hasSubHeader(lsroute)) { System.out.println("LooseSource"); } if (ip.hasSubHeader(ssroute)) { System.out.println("StrictSource"); } if (ip.hasSubHeader(ts)) { System.out.println("Timestamp"); } if (ip.hasSubHeader(record)) { System.out.println("RecordRoute"); } } }
/** * Handles the packet specified, and forward packet to the responsible chained handler once done. * In this case, the handler parses the packet and creates a <code>GOOSEMessage</code> * * @param packet the packet to parse to create the <code>GOOSEMessage</code> */ @Override public void handlePacket(JPacket packet) { Ethernet ethernetHeader = new Ethernet(); if (packet.hasHeader(ethernetHeader)) { // If it's not a 61850 message then don't handle the packet if (ethernetHeader.type() != GOOSEMessage.GOOSE_MSG) { return; } try { if (gooseMessage == null) { gooseMessage = new GOOSEMessage(); } gooseMessage.init(); // set destination and source mac gooseMessage.setDst(ethernetHeader.destination()); gooseMessage.setSrc(ethernetHeader.source()); // set ethernet type switch (ethernetHeader.type()) { case GOOSEMessage.GOOSE_MSG: // GOOSE gooseMessage.setMessageType(GOOSEMessage.GOOSE_MESSAGE); // set goose payload byte[] payload = ethernetHeader.getPayload(); GOOSEMessageGoosePDU goosePDU = GOOSEMessageGoosePDU.getInstance(payload, 8); // GOOSEMessageGoosePDU goosePDU = GOOSEMessageGoosePDU.getInstance( // payload, 7 ); gooseMessage.setAPDU(goosePDU); break; case GOOSEMessage.GSE_MGMT_MSG: // GSE gooseMessage.setMessageType(GOOSEMessage.GSE_MANAGEMENT_MESSAGE); // TODO: handle GSE management message break; case GOOSEMessage.SVM_MSG: // SVM gooseMessage.setMessageType(GOOSEMessage.SV_MESSAGE); // TODO: handle SVM message break; default: // not GOOSE traffic so ignore the frame gooseMessage = null; return; } } catch (MessageException me) { // TODO - write error message return; } } // chain to next handler if (this._handler != null) { this._handler.handlePacket(packet); } return; }