ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/rzahhcommtraceexample.htm

125 lines
4.9 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Using the commtrace classes" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzahhcommtraceexample" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Using the commtrace classes</title>
</head>
<body id="rzahhcommtraceexample"><a name="rzahhcommtraceexample"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using the commtrace classes</h1>
<div><p></p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
example disclaimer</a> for important legal information. </div>
<pre>//////////////////////////////////////////////////////////////////////
//
// Example using the commtrace classes to print communications trace
// data to a monitor by using a communications trace binary file as
// the source for the data.
//
// Command syntax:
// java CommTraceExample
//
//////////////////////////////////////////////////////////////////////
import com.ibm.as400.util.commtrace.*;
public class CommTraceExample {
public CommTraceExample() {
// Create a FormatProperties. By default display everything.
FormatProperties fmtprop = new FormatProperties();
Format fmt = new Format("/path/to/file");
// Sets the filtering properties for this format
fmt.setFilterProperties(fmtprop);
fmt.formatProlog(); // Format the prolog
Prolog pro = fmt.getProlog();
System.out.println(pro.toString());
// If this is not a valid trace
if (!pro.invalidData()) {
Frame rec;
// Get the records
while ((rec = fmt.getNextRecord()) != null) {
// Print out the Frame Number
System.out.print("Record:" + rec.getRecNum());
// Print out the time
System.out.println(" Time:" + rec.getTime());
// Get this records packet
IPPacket p = rec.getPacket();
// Get the first header
Header h = p.getHeader();
// If IP6 IPPacket
if (p.getType() == IPPacket.IP6) {
// If IP6 Header
if (h.getType() == Header.IP6) {
// Cast to IP6 so we can access methods
IP6Header ip6 = (IP6Header) h;
System.out.println(h.getName() + " src:" + ip6.getSrcAddr() + " dst:" + ip6.getDstAddr());
// Print the header as hex
System.out.println(ip6.printHexHeader());
// Print a string representation of the header.
System.out.println("Complete " + h.getName() + ":\n" + ip6.toString(fmtprop));
// Get the rest of the headers
while ((h = h.getNextHeader()) != null) {
// If it is a TCP header
if (h.getType() == Header.TCP) {
// Cast so we can access methods
TCPHeader tcp = (TCPHeader) h;
System.out.println(h.getName() +" src:" + tcp.getSrcPort() +" dst:" + tcp.getDstPort());
System.out.println("Complete " + h.getName() + ":\n" + tcp.toString(fmtprop));
// If it is a UDP header
} else if (h.getType() == Header.UDP) {
// Cast so we can access methods
UDPHeader udp = (UDPHeader) h;
System.out.println(h.getName() +" src:" + udp.getSrcPort() + " dst:" + udp.getDstPort());
System.out.println("Complete " + h.getName() + ":\n" + udp.toString(fmtprop));
}
}
}
}
}
}
}
public static void main(String[] args) {
CommTraceExample e = new CommTraceExample();
}
}</pre>
</div>
</div>
</body>
</html>