com.voytechs.jnetstream.codec
Interface Field

All Superinterfaces:
Identity
All Known Implementing Classes:
FieldImpl

public interface Field
extends Identity

Field contains data read from the capture file or stream. Fields are defined within NPL protocol definitions and are added to Header objects according to the definition in the order they were defined and encountered.

So combination of headers and their fields break down the structure of protocols and their headers within packets.


Example:

 import com.voytechs.jnetstream.codec.Packet;
 import com.voytechs.jnetstream.codec.Header;
 import com.voytechs.jnetstream.codec.Field;
 import com.voytechs.jnetstream.codec.Decoder;
 import com.voytechs.jnetstream.io.StreamFormatException;
 import com.voytechs.jnetstream.npl.SyntaxError;
 import java.io.IOException;

 public class Tutorial1 {
     public static void main(String[] args) {
       try {
           Decoder decoder = new Decoder("myCaptureFile.pcap");
           Packet packet = null;
           Header header = null;
           Field field = null;
           
           while ( (packet = decoder.nextPacket()) != null) {
               header = packet.getHeader(0);
           
               if (header.getName().equals("Ethernet") == true) {
                   field = header.getField("proto");
           
               } else {
                   field = header.getField(1);
               }
           
               System.out.println(field.toString());
           }
       } catch (StreamFormatException t) {
       } catch (IOException ie) {
       } catch (SyntaxError se) {
       }
     }
 }
               
 

Author:
Mark Bednarczyk

Field Summary
static java.lang.String COMMON
          Property contains common name for the field.
static java.lang.String DESCRIPTION
          Property contains full description of the field.
static java.lang.String FORMAT
          Property specifies primitive type specific format string which is used to reformat the output of the field.
static java.lang.String HIDENAME
          Property is a flag indicating the name of the field should not be displayed to the user.
static java.lang.String HIDEVALUE
          Property is a flag indicating the value of the field should not be displayed to the user.
static java.lang.String HTTP
          Property contains URL HTTP address which contains more information about the field and the header..
static java.lang.String MAX
          Property specifies the maximum value this field can have.
static java.lang.String MIN
          Property specifies the minimum value this field can have.
static java.lang.String MODIFIED
          Property specifies the last time the definition to the field has been modified.
static java.lang.String UNITS
          Property specifies the units name for the field value.
static java.lang.String UNITVALUE
          Property specifies new value for the field.
static java.lang.String VALUE_NAME
          Property is automatically assigned to the ENUM name of the value, if one is found.
 
Fields inherited from interface com.voytechs.jnetstream.codec.Identity
SHORT_NAME
 
Method Summary
 Field getField(int index)
          Return the requested sub-field by index from the field.
 Field getField(java.lang.String name)
          Return the requested sub-field by name from the parent field.
 int getFieldCount()
          Returns the number of sub-fields within this field.
 Primitive getPrimitive()
          Accessor method that returns the value object of this field.
 int getSize()
          Returns the size in bit of the field.
 java.lang.Object getValue()
          Conveniece method to retrieve a value of a field directly.
 java.lang.Object getValue(java.lang.String name)
          Conveniece method to retrieve a value of a property directly.
 boolean hasFields()
          Returns a flag indicating if this field is broken up into additional structure of subfields.
 
Methods inherited from interface com.voytechs.jnetstream.codec.Identity
getName, getProperty
 

Field Detail

COMMON

static final java.lang.String COMMON
Property contains common name for the field. This is a PERMANENT String property. Common name given to the field. Normally overrides what is output to the user, if the NAME property is too akward.

See Also:
Constant Field Values

HIDENAME

static final java.lang.String HIDENAME
Property is a flag indicating the name of the field should not be displayed to the user. This is PERMANENT or LOCAL Integer property.

See Also:
Constant Field Values

HIDEVALUE

static final java.lang.String HIDEVALUE
Property is a flag indicating the value of the field should not be displayed to the user. This is PERMANENT or LOCAL Integer property.

See Also:
Constant Field Values

DESCRIPTION

static final java.lang.String DESCRIPTION
Property contains full description of the field. This is a PERMANENT String property. This description is used by applications to display help information about the field.

See Also:
Constant Field Values

HTTP

static final java.lang.String HTTP
Property contains URL HTTP address which contains more information about the field and the header.. This is a PERMANENT String property.

See Also:
Constant Field Values

MODIFIED

static final java.lang.String MODIFIED
Property specifies the last time the definition to the field has been modified. This is a PERMANENT String property.

See Also:
Constant Field Values

MIN

static final java.lang.String MIN
Property specifies the minimum value this field can have. This is a PERMANENT or LOCAL Integer or Long property.

See Also:
Constant Field Values

MAX

static final java.lang.String MAX
Property specifies the maximum value this field can have. This is a PERMANENT or LOCAL Integer or Long property.

See Also:
Constant Field Values

FORMAT

static final java.lang.String FORMAT
Property specifies primitive type specific format string which is used to reformat the output of the field. This is a PERMANENT String property.

I.e. property format "XX-XX-XX-XX" This property if applied to ipaddress type would change the way that the IP address is displayed, using '-' instead of traditional '.' character.

See Also:
Constant Field Values

UNITS

static final java.lang.String UNITS
Property specifies the units name for the field value. This is a PERMANENT String property. Units could be the string "bytes" or "seconds" whatever is appropriate for the field.

See Also:
Constant Field Values

UNITVALUE

static final java.lang.String UNITVALUE
Property specifies new value for the field. This is a LOCAL Integer property. With this property you can recalculate the value of the field and have the field display the original value along with the unitvalue.

I.e. property local (hlen * 4); If this were applied to IPv4.hlen field would calculate the actual length of the IP header in bytes. This value would be displayed along with the actual field value. If hlen was 5 then calculated byte value would be 20 bytes.

See Also:
Constant Field Values

VALUE_NAME

static final java.lang.String VALUE_NAME
Property is automatically assigned to the ENUM name of the value, if one is found. This is a LOCAL String property. When field has an enum table defined, any matches are assigned and exported as a VALUE_NAME property which can be used in NPL and from java using the getProperty() method call.

See Also:
Constant Field Values
Method Detail

getPrimitive

Primitive getPrimitive()

Accessor method that returns the value object of this field. The reason for the value being an Object is that certain header fields are not nice primitives such as ints and Strings. There are numerous others such as "FLAGS", 32bit and 128bit IP addresses and so forth.

All of this is encapsulated in under the ProtocolPrimitive interface.

If there are subfields present for this field, the "value" is the primitive representation of the field value at this level. Subfields can be queried for additial substructure of this field.

i.e. FlagsBigEndian allows to define a standard set of subfield values for each of the bits in the in a protocol "flag" field of a header.

Returns:
ProtocolPrimitive such as IntergerBigEndian which implements the ProtocolPrimitive interface.

getSize

int getSize()
Returns the size in bit of the field. The field size is defined with the header definition and can be queried using getSize() method call.

Returns:
Size in bit of this field.

hasFields

boolean hasFields()

Returns a flag indicating if this field is broken up into additional structure of subfields. If yes, you can use the getSufieldsMethod to get an array of subfields.

Returns:
true means that there are subfields, false indicates that there are no subfields.

getField

Field getField(java.lang.String name)
Return the requested sub-field by name from the parent field. If Field is not found with the requested name, the null is returned.

Returns:
Requested field or null if not found.

getField

Field getField(int index)
Return the requested sub-field by index from the field. If index is out of range, null is returned.

Returns:
Field requested by the index, or null if out of range.

getFieldCount

int getFieldCount()
Returns the number of sub-fields within this field. If none, the 0 is returned.

Returns:
Number of sub-fields within this field.

getValue

java.lang.Object getValue()
Conveniece method to retrieve a value of a field directly.

Returns:
Opaque value of the field.
Since:
JNetStream 0.2.2

getValue

java.lang.Object getValue(java.lang.String name)
Conveniece method to retrieve a value of a property directly.

Parameters:
name - property name to retrieve the value from.
Returns:
Opaque value of the property.