0

I wrote some code on VxWorks to download a file from a TFTP server using tftpLib but the get gives me a timeout:

ERR [TFTP] tftpSend:479: Transfer Timed Out.
ERR [TFTP] tftpGet:1077: File transfer error.
Error has occurred: 4915207

which isn't right as the host is reachable:

ping("3.94.213.53",3)

Pinging 3.94.213.53 (3.94.213.53) with 64 bytes of data:
Reply from 3.94.213.53 bytes=64 ttl=63 seq=0 time<1ms
Reply from 3.94.213.53 bytes=64 ttl=63 seq=1 time<1ms
Reply from 3.94.213.53 bytes=64 ttl=63 seq=2 time<1ms

and when I do this from the Linux shell, it works just as expected:

tftp -r "artifacts/ngfm.bin" -g 3.94.213.53

What might be the problem here? The get section of my code looks like:

pFile = fopen("flash:/ngfm.bin","wb");
    if (pFile != NULL) {
        /* Get file from TFTP server and write it to the file descriptor */
        if (OK == (status = tftpGet (pTftpDesc, pFilename, pFile, TFTP_CLIENT))) {
         printf("tftpGet() successful\n");
        } else {
         printf("Error has occurred: %d\n", errno); // errno is where the error is stored
        }
    } else {
        printf("Bad file pointer pFile");
    }

edit:

The code I have above the get portion is:

/*Initiate TFTP session*/
if ((pTftpDesc = tftpInit ()) == NULL)
   printf("Error on tftpInit()\n");

/*connect to TFTP host and set transfer mode*/
if ((tftpPeerSet (pTftpDesc, pHost, port) == ERROR) ||
    (tftpModeSet (pTftpDesc, pMode) == ERROR)) {
    (void) tftpQuit (pTftpDesc);
    printf("Error on tftpPeerSet()\n");
    return ERROR;
}
stdcerr
  • 13,725
  • 25
  • 71
  • 128
  • Please give me a upvote on the answer I gave you on the other question :) – Noam Rathaus Dec 05 '13 at 20:43
  • 1
    Can you put wireshark (or any other packet sniffer) and look into the data stream? – Noam Rathaus Dec 05 '13 at 20:44
  • Yes, I hooked up Wire shark now and see a minimal difference. From the VxWorks side I see stuff like 'Port unreachable' which I have to look into, other than that the difference between the init line in Linux vs VxWorks is minimal: Linux `7263 579.036996 3.94.213.214 3.94.213.53 TFTP 77 Read Request, File: artifacts/ngfm.bin, Transfer type: octet, tsize\000=0\000` vs VxWorks: `81921 748.913374 3.94.213.214 3.94.213.53 TFTP 69 Read Request, File: artifacts/ngfm.bin, Transfer type: octet ` – stdcerr Dec 05 '13 at 20:55
  • The ``tsize`` should be bigger than 0, as it is the "total size" can you paste the TFTP transfer in you OP? just copy the packet's TFTP description (right click on the TFTP line and select Description) – Noam Rathaus Dec 06 '13 at 06:03

2 Answers2

1

I believe your problem is caused by lack of calling of tftpModeSet - http://www.vxdev.com/docs/vx55man/vxworks/ref/tftpLib.html#tftpModeSet

So add:

tftpModeSet(pTftpDesc, "binary");

This will prevent your binary file from causing the stream to die off on the first \n

Noam Rathaus
  • 5,405
  • 2
  • 28
  • 37
0

Okay, turns out that TFTP is a no go in my situation. I hooked up Wireshark and saw that my client is getting through to the server just fine on port 69. I previously have also made sure that I have port forwarding on port 69 setup in my iptable rules properly. Now I just read this on Wikipedia:

Data transfer is initiated on port 69, but the data transfer ports are chosen independently by the sender and receiver during initialization of the connection. The ports are chosen at random according to the parameters of the networking stack, typically from the range of ephemeral ports

i.e. TFTP won't work for me because I need NAT and it has to be secure. I'll need to go with a protocol that's connection orriented, ftp e.g.

I found that the standar VxWorks library also contains ftpLib.h (http://www.vxdev.com/docs/vx55man/vxworks/ref/ftpLib.html#ftpLs) that will hopefully resolve my NAT issues as FTP works with connection based TCP.

stdcerr
  • 13,725
  • 25
  • 71
  • 128