|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jnetstream.packet.templates.TcpNic0Template
public class TcpNic0Template
A packet template which initializes the packet with Ethernet, IPv4 and TCP headers. Each header is then further initialized to hold the source addresses of network interface #0 found on this system.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.jnetstream.packet.Packet |
|---|
Packet.Property |
| Constructor Summary | |
|---|---|
TcpNic0Template()
|
|
| Method Summary | ||
|---|---|---|
java.nio.ByteBuffer |
add(byte[] buffer)
|
|
java.nio.ByteBuffer |
add(byte[] buffer,
java.lang.Class<? extends Header> c)
|
|
java.nio.ByteBuffer |
add(java.nio.ByteBuffer buffer)
|
|
java.nio.ByteBuffer |
add(java.nio.ByteBuffer buffer,
java.lang.Class<? extends Header> c)
|
|
void |
add(java.lang.Class<? extends Header> c1)
|
|
|
add(java.lang.Class<T> c)
|
|
|
add(T t)
|
|
void |
addAll(java.lang.Class<? extends Header> c1,
java.lang.Class<?>... c3)
|
|
void |
addAll(java.util.List<java.lang.Class<? extends Header>> c)
|
|
void |
clearAll()
|
|
java.nio.ByteBuffer |
compact()
|
|
java.nio.ByteBuffer |
copy(byte[] buffer)
|
|
java.nio.ByteBuffer |
copy(java.nio.ByteBuffer buffer)
|
|
void |
format()
Formats content of this packet into human readable format using the default formatter and sends the output to the default output device. |
|
void |
free()
|
|
Header[] |
getAllHeaders()
|
|
com.slytechs.utils.memory.BitBuffer |
getBuffer()
Gets a buffer that contains the packet's data. |
|
com.slytechs.utils.memory.BitBuffer |
getData()
Returns the undecoded portion of the packet. |
|
|
getHeader(java.lang.Class<T> c)
Returns the specified header from this packet. |
|
|
getHeader(Protocol p)
Same as the alternative version of Packet.getHeader(Class) method, but
faster. |
|
int |
getHeaderCount()
Returns the number of decoded headers within this packet. |
|
long |
getIncludedLength()
Gets the length of the packet content from the current buffer. |
|
int |
getOffset(ProtocolInfo<? extends Header> protocol)
|
|
long |
getOriginalLength()
Gets the length of the packet as it was seen on the wire while originally captured. |
|
java.lang.Object |
getProperty(Packet.Property property)
|
|
long |
getTimestampNanos()
Gets the timestamp as recorded at the time of the packet capture in fraction of a second, in nanoseconds. |
|
long |
getTimestampSeconds()
Gets the timestamp as recorded at the time of the packet capture in number of seconds since 1.1.1970. |
|
|
hasCompleteHeader(java.lang.Class<T> c)
Checks if a complete, untruncated, header exists in this packet. |
|
|
hasCompleteHeader(ProtocolInfo<T> p)
|
|
|
hasHeader(java.lang.Class<T> c)
Checks for presence of the specified header within this particular packet. |
|
|
hasHeader(ProtocolEntry p)
|
|
void |
init()
Initialization method for the template. |
|
void |
init(PacketInitializer initializer)
|
|
|
insert(java.lang.Class<T> c,
java.lang.Class<? extends Header> afterHeader)
|
|
|
insert(java.lang.Class<T> c,
int afterIndex)
|
|
boolean |
isTruncated()
Checks if the packet has been truncated from the original length as seen on the network wire. |
|
java.util.Iterator<Header> |
iterator()
Allows all the headers to be iterated through using the foreach() syntax. |
|
|
remove(java.lang.Class<T> c)
|
|
Header |
remove(int index)
|
|
Header[] |
removeAll()
|
|
java.nio.ByteBuffer |
replace(byte[] buffer)
|
|
java.nio.ByteBuffer |
replace(java.nio.ByteBuffer buffer)
|
|
void |
resize(int size)
|
|
void |
setTimestamp(long seconds,
int nanos)
|
|
void |
update()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TcpNic0Template()
| Method Detail |
|---|
public void format()
throws java.io.IOException
Packet
format in interface Packetjava.io.IOException - any IO errors while sending outputpublic Header[] getAllHeaders()
getAllHeaders in interface Packetpublic com.slytechs.utils.memory.BitBuffer getBuffer()
Packet
getBuffer in interface Packet
public <T extends Header> T getHeader(java.lang.Class<T> c)
throws java.lang.IllegalStateException
Packet
Returns the specified header from this packet. Before calling this method
the Packet.hasHeader(java.lang.Class or Packet.hasCompleteHeader(java.lang.Class calls must be called
atleast once for each header being requested. If the check is not made,
even though the header exists in the packet, an IllegalStateException will
be thrown. This is simlar to standard Iterator's hasNext requirement. The
reason for this requirement is that it is the structure of a packet is so
dynamic and changing from packet to packet, that this check has been made
mandatory and a requirement to prevent unexpected errors. Also note that
the same checks have to be done again after a call to #update on a
packet. This is because the packet structure may have changed enough that
all previously returned headers are no longer valid or exist in the packet.
Only the first header of the specified type encountered is returned.
Example:
for (Packet packet : Captures.openLive(10)) { // Capture 10 packets
if (packet.hasHeader(Ethernet.class)) {
Ethernet ethernet = packet.getHeader(Ethernet.class);
EUI48 destination = ethernet.destination();
EUI48 source = ethernet.source();
short type = ethernet.type();
}
if (packet.hasCompleteHeader(Ip.class)) {
Ip ip = packet.getHeader(Ip.class);
// And so forth
}
}
Captures.close(); // Closes last open capture
getHeader in interface PacketT - protocol class typec - protocol's static class file
java.lang.IllegalStateException - thrown if header was not foundPacket.getHeader(Protocol),
Packet.hasHeader(Class)public int getHeaderCount()
Packet
getHeaderCount in interface Packet
public long getIncludedLength()
throws java.io.IOException
Packet
getIncludedLength in interface Packetjava.io.IOException
public long getOriginalLength()
throws java.io.IOException
Packet
getOriginalLength in interface Packetjava.io.IOException
public long getTimestampNanos()
throws java.io.IOException
Packet#getCaptureDevice() and then
CaptureDevice.getTimestampResolution() which will return an enum
constant which describes if the resulution is in nanoseconds or
microseconds. In either case this information should only be required in
rare circuimstances as the timestamp is always converted and reported in
nanoseconds, no matter what the resolution actually is.
getTimestampNanos in interface Packetjava.io.IOException
public long getTimestampSeconds()
throws java.io.IOException
Packet
getTimestampSeconds in interface Packetjava.io.IOExceptionpublic com.slytechs.utils.memory.BitBuffer getData()
Packet
Returns the undecoded portion of the packet. This is typically the data
portion of the packet starting at the first octet past the end of the last
header decoded in the packet. The buffer returned has its "position",
"limit" and "capacity" properties initialized as follows, where position =
the start of the undecoded buffer within the main packet buffer. Undecoded
buffer position property is set to 0, the limit is set to
Packet.getIncludedLength() -
position which is the end of
the packet data. Capacity is set to
Packet.getBuffer().capacity() - position which corresponds
to all the underlying packet buffer capacity allocated for this packet.
Packets typically captured from a live network interface will not have any
extra capacity but packets read from a file or initialized by a user may.
Note that if you modify the contents of this buffer the underlying
packet buffer will also be modified and visa versa. Also note that unlike
modifying decoded headers it may or may not be neccessary to call update.
In the case where you do not want the new packet protocol structure to be
redecoded, you do not need to call the #update method. If you
append a new header by adding the neccessary byte data into this buffer and
you want the new protocol header to be discovered, then you need to call on
update method. Afterwards, if all goes well you should be able to call
Packet.getLastHeader(MyHeader.class) and get the newly added header. Lastly
note that if you do change the structure of the packet and do call update
method, you must also call the getUndecodedBuffer method again since the
buffer will change due to the new header that was added.
getData in interface Packetpublic <T extends Header> boolean hasCompleteHeader(java.lang.Class<T> c)
PacketChecks if a complete, untruncated, header exists in this packet. If the header exists, but is incomplete due to snaplen, this method will return false. Only the first header of the specified type encountered is returned.
Implementation Note: the check performed is very efficient and does not neccessarily mean that any back-end objects needed to be instantiated. The presence of a header is encoded using bit fields, and checked very efficiently. This method does require a scan of the packet the first time its called, inorder to determine which headers are present, but that is also done very efficiently using low level scanner. Once the single scan of a packet has been performed any subsequent header checks are typically a single bitwise operation.
hasCompleteHeader in interface PacketT - Stubfile's header class for the requested header.c - Class of the header to check for. Java classes for all headers are
generated as java stubfiles during NPL definition compile.
public <T extends Header> boolean hasHeader(java.lang.Class<T> c)
PacketChecks for presence of the specified header within this particular packet. The header may be either complete or truncated due to snaplen, but it does exist in this header. Only the first header of the specified type encountered is returned.
Implementation Note: the check performed is very efficient and does not neccessarily mean that any back-end objects needed to be instantiated. The presence of a header is encoded using bit fields, and checked very efficiently. This method does require a scan of the packet the first time its called, inorder to determine which headers are present, but that is also done very efficiently using low level scanner. Once the single scan of a packet has been performed any subsequent header checks are typically a single bitwise operation.
hasHeader in interface PacketT - Stubfile's header class for the requested header.c - Class of the header to check for. Java classes for all headers are
generated as java stubfiles during NPL definition compile.
public boolean isTruncated()
throws java.io.IOException
Packet
isTruncated in interface Packetjava.io.IOExceptionpublic java.util.Iterator<Header> iterator()
Packet
iterator in interface java.lang.Iterable<Header>iterator in interface Packetpublic java.nio.ByteBuffer add(java.nio.ByteBuffer buffer)
public java.nio.ByteBuffer add(byte[] buffer)
public java.nio.ByteBuffer add(java.nio.ByteBuffer buffer,
java.lang.Class<? extends Header> c)
public java.nio.ByteBuffer add(byte[] buffer,
java.lang.Class<? extends Header> c)
public void resize(int size)
public void setTimestamp(long seconds,
int nanos)
throws java.lang.IllegalArgumentException,
java.io.IOException
java.lang.IllegalArgumentException
java.io.IOExceptionpublic <T extends Header> T add(T t)
public <T extends Header> T add(java.lang.Class<T> c)
public void addAll(java.lang.Class<? extends Header> c1,
java.lang.Class<?>... c3)
public void addAll(java.util.List<java.lang.Class<? extends Header>> c)
public void clearAll()
public java.nio.ByteBuffer compact()
public java.nio.ByteBuffer copy(java.nio.ByteBuffer buffer)
public java.nio.ByteBuffer copy(byte[] buffer)
public <T extends Header> T insert(java.lang.Class<T> c,
java.lang.Class<? extends Header> afterHeader)
public <T extends Header> T insert(java.lang.Class<T> c,
int afterIndex)
public <T extends Header> T remove(java.lang.Class<T> c)
public Header remove(int index)
public Header[] removeAll()
public java.nio.ByteBuffer replace(java.nio.ByteBuffer buffer)
public java.nio.ByteBuffer replace(byte[] buffer)
public void update()
throws java.io.IOException,
UpdateException
java.io.IOException
UpdateExceptionpublic void init()
PacketTemplate
init in interface PacketTemplatepublic void init(PacketInitializer initializer)
public void free()
public void add(java.lang.Class<? extends Header> c1)
public <T extends Header> T getHeader(Protocol p)
throws java.lang.IllegalStateException
Packet
Same as the alternative version of Packet.getHeader(Class) method, but
faster. You can speed up retrieval of headers if you do the lookup of the
protocol yourself. The use of parameterized header retrieval ensures
compile time type safety of the retrieved header.
Here is an example:
final Protocol<Ethernet> ETHERNET = ProtocolRegistry.getProtocol(Ethernet.class);
final Protocol<Ip> IP = ProtocolRegistry.getProtocol(Ip.class);
for (Packet packet: Capture.openLive(10)) {
if (packet.hasHeader(ETHERNET) {
Ethernet ethernet = packet.getHeader(ETHERNET);
// And so forth
}
}
Captures.close(); // Closes last open capture
getHeader in interface PacketT - protocol class typep - instance of a protocol as retrieved from protocol registry
java.lang.IllegalStateException - thrown if header was not foundPacket.getHeader(Class),
Packet.hasHeader(ProtocolEntry),
ProtocolRegistry#getProtocol(Class)
public <T extends Header> boolean hasCompleteHeader(ProtocolInfo<T> p)
throws CodecCreateException,
java.io.IOException
hasCompleteHeader in interface PacketCodecCreateException
java.io.IOException
public <T extends Header> boolean hasHeader(ProtocolEntry p)
throws CodecCreateException,
java.io.IOException
hasHeader in interface PacketCodecCreateException
java.io.IOExceptionpublic int getOffset(ProtocolInfo<? extends Header> protocol)
public java.lang.Object getProperty(Packet.Property property)
getProperty in interface Packet
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||