i get a tftp timeout from vxworks

2.4k views Asked by At

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;
}
2

There are 2 answers

0
stdcerr On BEST ANSWER

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.

1
Noam Rathaus On

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