diff options
author | Hanoh Haim <hhaim@cisco.com> | 2015-09-20 17:34:55 +0300 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2015-09-20 17:34:55 +0300 |
commit | 3fe28431157f7b2ed2ed8184ed85017c42a4cb6c (patch) | |
tree | 41fa17684842885e1664cc63ff1520157f191261 /scripts/external_libs/dpkt-1.8.6/dpkt/tftp.py | |
parent | 588bb20e9c8f8438db4eb3e8db85111f41bd7306 (diff) | |
parent | 28fef018f75b5a54ac69ac7c919127bf47f5b61f (diff) |
Merge branch 'master' of csi-sceasr-b45:/auto/proj-pcube-b/apps/PL-b/tools/repo//trex-core into wen
Diffstat (limited to 'scripts/external_libs/dpkt-1.8.6/dpkt/tftp.py')
-rw-r--r-- | scripts/external_libs/dpkt-1.8.6/dpkt/tftp.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/external_libs/dpkt-1.8.6/dpkt/tftp.py b/scripts/external_libs/dpkt-1.8.6/dpkt/tftp.py new file mode 100644 index 00000000..046ae8d2 --- /dev/null +++ b/scripts/external_libs/dpkt-1.8.6/dpkt/tftp.py @@ -0,0 +1,55 @@ +# $Id: tftp.py 23 2006-11-08 15:45:33Z dugsong $ + +"""Trivial File Transfer Protocol.""" + +import struct +import dpkt + +# Opcodes +OP_RRQ = 1 # read request +OP_WRQ = 2 # write request +OP_DATA = 3 # data packet +OP_ACK = 4 # acknowledgment +OP_ERR = 5 # error code + +# Error codes +EUNDEF = 0 # not defined +ENOTFOUND = 1 # file not found +EACCESS = 2 # access violation +ENOSPACE = 3 # disk full or allocation exceeded +EBADOP = 4 # illegal TFTP operation +EBADID = 5 # unknown transfer ID +EEXISTS = 6 # file already exists +ENOUSER = 7 # no such user + +class TFTP(dpkt.Packet): + __hdr__ = (('opcode', 'H', 1), ) + + def unpack(self, buf): + dpkt.Packet.unpack(self, buf) + if self.opcode in (OP_RRQ, OP_WRQ): + l = self.data.split('\x00') + self.filename = l[0] + self.mode = l[1] + self.data = '' + elif self.opcode in (OP_DATA, OP_ACK): + self.block = struct.unpack('>H', self.data[:2]) + self.data = self.data[2:] + elif self.opcode == OP_ERR: + self.errcode = struct.unpack('>H', self.data[:2]) + self.errmsg = self.data[2:].split('\x00')[0] + self.data = '' + + def __len__(self): + return len(str(self)) + + def __str__(self): + if self.opcode in (OP_RRQ, OP_WRQ): + s = '%s\x00%s\x00' % (self.filename, self.mode) + elif self.opcode in (OP_DATA, OP_ACK): + s = struct.pack('>H', self.block) + elif self.opcode == OP_ERR: + s = struct.pack('>H', self.errcode) + ('%s\x00' % self.errmsg) + else: + s = '' + return self.pack_hdr() + s + self.data |