Home | Trees | Indices | Help |
|
---|
|
1 # $Id: tftp.py 23 2006-11-08 15:45:33Z dugsong $ 2 3 """Trivial File Transfer Protocol.""" 4 5 import struct 6 import dpkt 7 8 # Opcodes 9 OP_RRQ = 1 # read request 10 OP_WRQ = 2 # write request 11 OP_DATA = 3 # data packet 12 OP_ACK = 4 # acknowledgment 13 OP_ERR = 5 # error code 14 15 # Error codes 16 EUNDEF = 0 # not defined 17 ENOTFOUND = 1 # file not found 18 EACCESS = 2 # access violation 19 ENOSPACE = 3 # disk full or allocation exceeded 20 EBADOP = 4 # illegal TFTP operation 21 EBADID = 5 # unknown transfer ID 22 EEXISTS = 6 # file already exists 23 ENOUSER = 7 # no such user 2426 __hdr__ = (('opcode', 'H', 1), ) 275629 dpkt.Packet.unpack(self, buf) 30 if self.opcode in (OP_RRQ, OP_WRQ): 31 l = self.data.split('\x00') 32 self.filename = l[0] 33 self.mode = l[1] 34 self.data = '' 35 elif self.opcode in (OP_DATA, OP_ACK): 36 self.block = struct.unpack('>H', self.data[:2]) 37 self.data = self.data[2:] 38 elif self.opcode == OP_ERR: 39 self.errcode = struct.unpack('>H', self.data[:2]) 40 self.errmsg = self.data[2:].split('\x00')[0] 41 self.data = ''4244 return len(str(self))4547 if self.opcode in (OP_RRQ, OP_WRQ): 48 s = '%s\x00%s\x00' % (self.filename, self.mode) 49 elif self.opcode in (OP_DATA, OP_ACK): 50 s = struct.pack('>H', self.block) 51 elif self.opcode == OP_ERR: 52 s = struct.pack('>H', self.errcode) + ('%s\x00' % self.errmsg) 53 else: 54 s = '' 55 return self.pack_hdr() + s + self.data
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Mar 19 07:50:08 2015 | http://epydoc.sourceforge.net |