Skip to content

Commit

Permalink
TFTP::Client retransmit lost data blocks on upload
Browse files Browse the repository at this point in the history
Retransmit data blocks until we receieve a matching ACK.
  • Loading branch information
David Barksdale committed Jun 9, 2015
1 parent 9fa4234 commit 91a06fb
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/rex/proto/tftp/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,27 @@ def send_data(host,port)
yield "Sending #{expected_size} bytes (#{expected_blocks} blocks)"
end
data_blocks.each_with_index do |data_block,idx|
req = [OpData, (idx + 1), data_block].pack("nnA*")
if self.server_sock.sendto(req, host, port) > 0
sent_data += data_block.size
end
res = self.server_sock.recvfrom(65535)
if res
code, type, msg = parse_tftp_response(res[0])
if code == 4
sent_blocks += 1
yield "Sent #{data_block.size} bytes in block #{sent_blocks}" if block_given?
else
if block_given?
yield "Got an unexpected response: Code:%d, Type:%d, Message:'%s'. Aborting." % [code, type, msg]
while true
req = [OpData, (idx + 1), data_block].pack("nnA*")
self.server_sock.sendto(req, host, port)

This comment has been minimized.

Copy link
@hdm

hdm Jun 9, 2015

The return value of sendto() should be checked

This comment has been minimized.

Copy link
@amatus

amatus Jun 9, 2015

Owner

If it fails we'll just get an ACK for the previous block and then re-transmit anyway.

res = self.server_sock.recvfrom(65535)
if res
code, type, msg = parse_tftp_response(res[0])
if code == 4
if type == idx + 1
sent_blocks += 1
sent_data += data_block.size
yield "Sent #{data_block.size} bytes in block #{idx+1}" if block_given?
break
else
next
end
else
if block_given?
yield "Got an unexpected response: Code:%d, Type:%d, Message:'%s'. Aborting." % [code, type, msg]
end
break
end
break
end
end
end
Expand Down

0 comments on commit 91a06fb

Please sign in to comment.