verinec.adaptation.snmp.tftpserver
Class TFTPPacket

java.lang.Object
  extended by verinec.adaptation.snmp.tftpserver.TFTPPacket

public class TFTPPacket
extends Object

Class responsible for encapsulating TFTP packets. It is actually a straight forward implementation of the RFC 1350.

Most of the source was taken from http://www.it.rit.edu/~netsyslb/vksf522/class_examples/Day09_TFTPServer/TFTPPacket.pdf
I removed the gui part.

Version:
1.0
Author:
christoph.ehret at unifr.ch

Field Summary
static int ACCESVIOLATION
          Access violation error code
static int ACK
          ACK opcode
private  int blkNo
           
private  byte[] data
           
static int DATA
          Data opcode
static int DISKFULL
          Disk full error code
private  String errMsg
           
private  int errNo
           
static int ERROR
          Error opcode
static int FILEEXISTS
          File exists error code
static int FILENOTFOUND
          File not found error code
private  String fname
           
static int ILLEGALOPERATION
          Illegal operation error code
private  Logger logger
           
private  String mode
           
static int NOSUCHUSER
          No such user error code
private  int opcode
           
static int RRQ
          Read Request opcode
static int UNKNOWN
          Unknown opcode
static int UNKNOWNCODE
          Unknowncode error code
static int UNKNOWNTID
          Unknown TID error code
static int WRQ
          Write Request opcode
 
Constructor Summary
TFTPPacket()
           
 
Method Summary
 byte[] build()
          Builds a TFTP packet
 void clearPacket()
          Method to put all the packet fields to their default value
 int getBlockNo()
          Gets the block number of the packet
 byte[] getData()
          Gets the data
 String getErrorMsg()
          Gets the error message
 int getErrorNo()
          Gets the error opcode number
 String getFName()
          Gets the name of the file to write
 String getMode()
          Gets the mode to use
 int getOpcode()
          Gets the opcode
 void parse(byte[] rawPacket, int offset, int length)
          Parses a raw packet to get different informations
 String readNTString(DataInputStream dis)
          Reads a null terminated string for a data input stream
 void setBlockNo(int blkNo)
          Sets the blocknumber of the packet
 void setData(byte[] data)
          Sets the data
 void setErrorMsg(String errMsg)
          Sets the error message
 void setErrorNo(int errNo)
          Sets the error number, i.e one of the error codes
 void setFName(String fname)
          Sets the name of the file to write
 void setMode(String mode)
          Sets the mode
 void setOpcode(int opcode)
          Sets the data opcode to the given opcode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private Logger logger

RRQ

public static final int RRQ
Read Request opcode

See Also:
Constant Field Values

WRQ

public static final int WRQ
Write Request opcode

See Also:
Constant Field Values

DATA

public static final int DATA
Data opcode

See Also:
Constant Field Values

ACK

public static final int ACK
ACK opcode

See Also:
Constant Field Values

ERROR

public static final int ERROR
Error opcode

See Also:
Constant Field Values

UNKNOWN

public static final int UNKNOWN
Unknown opcode

See Also:
Constant Field Values

UNKNOWNCODE

public static final int UNKNOWNCODE
Unknowncode error code

See Also:
Constant Field Values

FILENOTFOUND

public static final int FILENOTFOUND
File not found error code

See Also:
Constant Field Values

ACCESVIOLATION

public static final int ACCESVIOLATION
Access violation error code

See Also:
Constant Field Values

DISKFULL

public static final int DISKFULL
Disk full error code

See Also:
Constant Field Values

ILLEGALOPERATION

public static final int ILLEGALOPERATION
Illegal operation error code

See Also:
Constant Field Values

UNKNOWNTID

public static final int UNKNOWNTID
Unknown TID error code

See Also:
Constant Field Values

FILEEXISTS

public static final int FILEEXISTS
File exists error code

See Also:
Constant Field Values

NOSUCHUSER

public static final int NOSUCHUSER
No such user error code

See Also:
Constant Field Values

opcode

private int opcode

fname

private String fname

mode

private String mode

blkNo

private int blkNo

data

private byte[] data

errNo

private int errNo

errMsg

private String errMsg
Constructor Detail

TFTPPacket

public TFTPPacket()
Method Detail

setOpcode

public void setOpcode(int opcode)
Sets the data opcode to the given opcode

Parameters:
opcode - Opcode number that specifies the data identity

setFName

public void setFName(String fname)
Sets the name of the file to write

Parameters:
fname - Name of the file to write

setMode

public void setMode(String mode)
Sets the mode

Parameters:
mode - Mode to use

setBlockNo

public void setBlockNo(int blkNo)
Sets the blocknumber of the packet

Parameters:
blkNo - Block number of the packet

setData

public void setData(byte[] data)
Sets the data

Parameters:
data - Data

setErrorNo

public void setErrorNo(int errNo)
Sets the error number, i.e one of the error codes

Parameters:
errNo -

setErrorMsg

public void setErrorMsg(String errMsg)
Sets the error message

Parameters:
errMsg - Error message

getOpcode

public int getOpcode()
Gets the opcode

Returns:
Opcode number

getFName

public String getFName()
Gets the name of the file to write

Returns:
Name of the file to write

getMode

public String getMode()
Gets the mode to use

Returns:
Mode to use

getBlockNo

public int getBlockNo()
Gets the block number of the packet

Returns:
Block number of the packet

getData

public byte[] getData()
Gets the data

Returns:
Data

getErrorNo

public int getErrorNo()
Gets the error opcode number

Returns:
Error opcode number

getErrorMsg

public String getErrorMsg()
Gets the error message

Returns:
Error message

parse

public void parse(byte[] rawPacket,
                  int offset,
                  int length)
Parses a raw packet to get different informations

Parameters:
rawPacket - Raw data
offset - Offset from where begining to read in rawPacket
length - Number of bytes to read in rawPacket

build

public byte[] build()
Builds a TFTP packet

Returns:
The byte array for the packet

clearPacket

public void clearPacket()
Method to put all the packet fields to their default value


readNTString

public String readNTString(DataInputStream dis)
                    throws IOException
Reads a null terminated string for a data input stream

Parameters:
dis - The stream to read from.
Returns:
The next null terminated string from dis.
Throws:
IOException - If reading the string fails.

Copyright © 2005 Verinec, DIUF