[ 
https://issues.apache.org/jira/browse/NET-181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12571802#action_12571802
 ] 

Dan Armbrust commented on NET-181:
----------------------------------

Here is a patch which implements block wrapping.

I tested this against the tftpd server in Ubuntu, and against my own tftp 
server which I will be attaching shortly.


{noformat}
Index: TFTPClient.java
===================================================================
--- .   (revision 630373)
+++ .   (working copy)
@@ -231,6 +231,12 @@
                                 throw e;
                             }
                             ++block;
+                            if (block > 65535)
+                                                       {
+                                                               // wrap the 
block number
+                                                               block = 0;
+                                                       }
+                            
                             break _receivePacket;
                         }
                         else
@@ -237,7 +243,7 @@
                         {
                             discardPackets();
 
-                            if (lastBlock == (block - 1))
+                            if (lastBlock == (block == 0 ? 65535 : (block - 
1)))
                                 continue _sendPacket;  // Resend last 
acknowledgement.
 
                             continue _receivePacket; // Start fetching packets 
again.
@@ -464,6 +470,11 @@
                         if (lastBlock == block)
                         {
                             ++block;
+                            if (block > 65535)
+                                                       {
+                                                               // wrap the 
block number
+                                                               block = 0;
+                                                       }
                             if (lastAckWait) {
                                 
                               break _sendPacket;
@@ -476,7 +487,7 @@
                         {
                             discardPackets();
 
-                            if (lastBlock == (block - 1))
+                            if (lastBlock == (block == 0 ? 65535 : (block - 
1)))
                                 continue _sendPacket;  // Resend last 
acknowledgement.
 
                             continue _receivePacket; // Start fetching packets 
again.
{noformat}


> tftp client limited to ~32 MB file sizes
> ----------------------------------------
>
>                 Key: NET-181
>                 URL: https://issues.apache.org/jira/browse/NET-181
>             Project: Commons Net
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Dan Armbrust
>            Priority: Minor
>
> I just noticed that the TFTPClient class does not support a block wraparound 
> - hence, when the block number exceeds the max allowed by the rfc (65535) - 
> about a 32 mb file - bad things will happen.
> I can't find any rfc that specifies how the wraparound is supposed to occur, 
> but this wiki page mentions it:
> http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
> And I am working on implementing a TFTPServer - and in my tests with the tftp 
> client that is shipped with fedora, I have determined that that tftp client 
> expects the next block number after 65535 to be 0.
> So it appears that the TFTPClient should wrap its block number so that it 
> properly supports larger files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to