EzDevInfo.com

tftp interview questions

Top tftp frequently asked interview questions

Not sure if I'm using "using" correctly c# in tftp app

I'm trying to use this pre-made C# tftp server app with my windows c# form. In the authors server example, which works great, he uses a console app. When I trying porting his console example into my form app it doesn't work (no errors, just doesn't connect) and I believe my issue is in the "using" statement:

using (var server = new TftpServer())
{
    server.OnReadRequest += new TftpServerEventHandler(server_OnReadRequest);
    server.OnWriteRequest += new TftpServerEventHandler(server_OnWriteRequest);
    server.Start();
    Console.Read();
}

Not sure if I understand correctly but I believe the Console.Read() blocks keeping the app from exiting. If this is the case how would I implement a equivalent with a form app. I just can't get my head around the "using". Sorry I'm new to c#.


Source: (StackOverflow)

Tftp protocol implementation and difference between netascii and octect

I'm building an application that is a server that implements the tftp protocol. I'm having hard times in understand what's the difference between ASCII format and binary format (netascii and octect) in tftp, and how should I read files differently as the protocol states.

I know that an ASCII char can be rapresented with a single byte. So I don't understand what's the difference between reading in ascii mode (1 byte each character) and binary mode (1 raw byte).

I can read the file with flag ios::binary for binary mode (octet in tftp) and without it for ascii (netascii in tftp), but I really don't understand what's the difference in reading files in these two ways (I always come up with an array of bytes).

If someone can help me understand, I'll really appreciate it

The tftp protocol specification: http://www.rfc-editor.org/rfc/rfc1350.txt

The part that I don't understand is this one:

Three modes of transfer are currently supported: netascii (This is ascii as defined in "USA Standard Code for Information Interchange"
[1] with the modifications specified in "Telnet Protocol
Specification" [3].) Note that it is 8 bit ascii. The term
"netascii" will be used throughout this document to mean this
particular version of ascii.); octet (This replaces the "binary" mode of previous versions of this document.) raw 8 bit bytes; mail,
netascii characters sent to a user rather than a file. (The mail
mode is obsolete and should not be implemented or used.) Additional
modes can be defined by pairs of cooperating hosts.


Source: (StackOverflow)

Advertisements

How to list the windows tftp server directories and files from command prompt?

I have installed Tftpd32 software in my windows 7 pc. I have running tftp server on my windows pc and tftp home directory has few directories and files. I have to display the tftp servers directories and files from windows command prompt ? How to display the tftp server directories and folders ?

C:\Users\user1>tftp

Transfers files to and from a remote computer running the TFTP service.

TFTP [-i] host [GET | PUT] source [destination]

  -i              Specifies binary image transfer mode (also called
                  octet). In binary image mode the file is moved
                  literally, byte by byte. Use this mode when
                  transferring binary files.
  host            Specifies the local or remote host.
  GET             Transfers the file destination on the remote host to
                  the file source on the local host.
  PUT             Transfers the file source on the local host to
                  the file destination on the remote host.
  source          Specifies the file to transfer.
  destination     Specifies where to transfer the file.


C:\Users\user1>

Source: (StackOverflow)

TFTP pipelining protocol

Wikipedia on TFTP states:

Windows 2008 introduced pipelined TFTP

Its aim is to enable good throughput over high latency links. Unfortunately no reference is given. The only other reference I found is Bazootftp mention pipelining-support.

  • So how is pipelining implemented? Is it negotiated per RFC 2347?
  • Is it possible to do pipelining, if only one side supports it (eg. via some ACK-tricks)?

I've seen Bazootftp add another packet-type, to signal the end of the stream.

  • Is Bazootftp's pipelining the same as in Windows?
  • And I haven't exactly understand, how the windowing works, esp. with lost packets.

Any hints appreciated.


Source: (StackOverflow)

u-Boot VxWorks TFTP boot failure: " ERROR: booting os 'Unknown OS' (14) is not supported"

I am trying to boot VxWOrks using tftp for zynq.
I have set the enviroment varibles for ipaddr, serverip, netmask accordingly and files are loaded in RAM succesfully. however, i get the following error when trying to boot the vxWorks image. There is not problem with the VxWOrks image as i can successfully boot with these iamges when i write these files to SDcard and boot from the sdcard

zynq-uboot> bootm 0x5000000 - 0x4000000

#ERROR: booting os 'Unknown OS' (14) is not supported"

Here is a complete screen shot

zynq-uboot> setenv ipaddr 192.168.88.169;setenv serverip 192.168.88.88;setenv netmask 255.255.255.0
zynq-uboot> tftp 0x8000000 BOOT.bin

Trying to set up GEM link...
Phy ID: 01410E40
Resetting PHY...
PHY reset complete.
Waiting for PHY to complete auto-negotiation...
Link is now at 1000Mbps!
Using zynq_gem device
TFTP from server 192.168.88.88; our IP address is 192.168.88.169
Filename 'BOOT.bin'.
Load address: 0x8000000
Loading: T ########################
done
Bytes transferred = 345180 (5445c hex)
zynq-uboot> tftp 0x5000000 uVxWorks && tftp 0x4000000 zynq-7000.dtb

Using zynq_gem device
TFTP from server 192.168.88.88; our IP address is 192.168.88.169
Filename 'uVxWorks'.
Load address: 0x5000000
Loading: T T #################################################################
         #################################################################
         ###############################################################
done
Bytes transferred = 2829468 (2b2c9c hex)
Using zynq_gem device
TFTP from server 192.168.88.88; our IP address is 192.168.88.169
Filename 'zynq-7000.dtb'.
Load address: 0x4000000
Loading: #
done
Bytes transferred = 3588 (e04 hex)
zynq-uboot> bootm 0x5000000 - 0x4000000

## Booting kernel from Legacy Image at 05000000 ...
   Image Name:   vxWorks
   Image Type:   ARM Unknown OS Kernel Image (uncompressed)
   Data Size:    2829404 Bytes = 2.7 MiB
   Load Address: 00200000
   Entry Point:  00200000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK
ERROR: booting os 'Unknown OS' (14) is not supported

zynq-uboot> <INTERRUPT>

Source: (StackOverflow)

inotify event IN_MODIFY occuring twice for tftp put

I am using inotify to listen to modifications to a file.

When I test file modification, program is working fine.

# echo "test" > /tftpboot/.TEST

Output:
Read 16 data
IN_MODIFY

But when I do tftp put, two events are generated:

tftp>  put .TEST
Sent 6 bytes in 0.1 seconds
tftp>

Output:
Read 16 data
IN_MODIFY
Read 16 data
IN_MODIFY

Any idea how to avoid the duplicate notification?

Code is given below:

#include <sys/inotify.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <iostream>

using namespace std;

int main(int argc, const char *argv[])
{
    int fd = inotify_init();
    if (fd < 0)
    {
        cout << "inotify_init failed\n";
        return 1;
    }
    int wd = inotify_add_watch(fd, "/tftpboot/.TEST", IN_MODIFY);
    if (wd < 0)
    {
        cout << "inotify_add_watch failed\n";
        return 1;
    }
    while (true)
    {
        char buffer[sizeof(struct inotify_event) + NAME_MAX + 1] = {0};
        ssize_t length;

        do
        {
            length = read( fd, buffer, sizeof(struct inotify_event));
            cout << "Read " << length << " data\n";
        }while (length < 0);

        if (length < 0)
        {
            cout << "read failed\n";
            return 1;
        }

        struct inotify_event *event = ( struct inotify_event * ) buffer;
        if ( event->mask & IN_ACCESS )
            cout << "IN_ACCESS\n";
        if ( event->mask & IN_CLOSE_WRITE )
            cout << "IN_CLOSE_WRITE\n";
        if ( event->mask & IN_CLOSE_NOWRITE )
            cout << "IN_CLOSE_NOWRITE\n";
        if ( event->mask & IN_MODIFY )
            cout << "IN_MODIFY \n";
        if ( event->mask & IN_OPEN )
            cout << "IN_OPEN\n";
    }

    inotify_rm_watch( fd, wd );
    close (fd);

    return 0;
}

Source: (StackOverflow)

In the TFTP Client Server application, how does a UDP datagram modify the IP header?

I am building a TFTP(RC1350) application using Java. So far I have been able to make the successful transfers between two different computers whether its for a read request or a write request. As the RC1350 specification suggests, I specify the destination address and the port number by putting this information into a DatagramPacket.

Based on RC1350, the order of headers is the following:

      ---------------------------------------------------
     |  Local Medium  |  Internet  |  Datagram  |  TFTP  |
      ---------------------------------------------------

                  Figure 3-1: Order of Headers

And it also states "TFTP DOES NOT specify any of the values in the Internet header".

Since my TFTP application does not touch the IP header at all, than how does IP determine what to put as an address into an IP header?


Source: (StackOverflow)

Replace string by regex for tftp

I want to use tftp-hpa file-remapping feature (see the man page). It uses regex, but it doesn't have much functionality. What I want is when the client send a request for foo, the server send client_IP/foo. For the moment I have this rule :

r foo \i/foo

But as you can guess, it works only for foo, whereas I want it to work whatever is the request. I've tried this :

r /.*/ \i//.*/

But it doesn't work. As the documentation and the examples aren't much, I don't know what to try, so maybe you can have some suggestions. (So yeah, I know it's not really a programing question, but as programmers you know regex and maybe you'll have the good answer)


Source: (StackOverflow)

tftpGet error from tftpLib in VxWorks

I'm writing a little function that downloads a file from a TFTP server using VxWork's tftpLib (http://www.vxdev.com/docs/vx55man/vxworks/ref/tftpLib.html) - now I realized that my tftpGet() command is returning an error 1 but I'm not sure what errorcode 1 means. On the posted website it says:

ERRNO
S_tftpLib_INVALID_DESCRIPTOR
S_tftpLib_INVALID_ARGUMENT
S_tftpLib_NOT_CONNECTED

But how do I know what 1 corresponds with? The get portion of my code looks like this:

/* Initialize and createlocal file handle */
pFile = fopen("ngfm.bin","wb");
if (pFile != NULL)
    {
    /* Get file from TFTP server and write it to the file descriptor */
    status = tftpGet (pTftpDesc, pFilename, pFile, TFTP_CLIENT);
    printf("GOT %s\n",pFilename);
    }
else
    {
    printf("Error in tftpGet()\nfailed to get %s from %s\nERRNO %d",pFilename,pHost, status);
    }

Source: (StackOverflow)

Can't connect to docker published port for tftp

i'm desperately trying to run tftp-hpa in a docker container. I built an image from dockerfile and start it with:

docker run -v /tmp:/srv/tftp -d -p 69:69/udp -t tftp_server

It's up and running and i can access the server via the virtual docker interface:

me@hostmachine$ tftp 172.17.0.79
tftp> get /srv/tftp/test
Received 7 bytes in 0.0 seconds

But from my opinion the -p 69:69/udp switch should forward the 69 port of my host machine to the containers port 69. But this does not seem to work:

me@hostmachine$ tftp localhost
tftp> get /srv/tftp/test
Transfer timed out.

From netstat, i see that port 69 on my hostmachine is open. I tried exactly the same scenario with an httpd server and port 80. It works here, i can access the website via 127.0.0.1:80 in my browser. The host machine is ubuntu 15.04 intel and the docker image is based on debian base image.

Can anybody help me? Is there something i could have missed? Any ideas how to debug? I will happily share my Dockerfile or any more information, but tried to keep question short.


Source: (StackOverflow)

Calling tftp get command from c source code

I'm calling system command

system("tftp -m binary 192.168.1.1 -c get myfile  > /dev/null") ;

it works fine when tftp server is running but it makes my c program crashed when tftp server is off.

Is there a way to check whether the server is available or not in c source code ?


Source: (StackOverflow)

Python package that implements TFTP, FTP, SFTP servers

I'm using tftpy to create TFTP server in my Python program and it works amazing. However, I need to have other flavors of servers: TFTP, FTP, SFTP. What package may I use that supports all of them?


Source: (StackOverflow)

Detecting incoming port for TFTP data?

I'm working on implementing a TFTP client (UDP socket).

Currently I have to switch off the entire firewall on my Windows 8 machine or else the data doesn't reach the TFTP client. The outgoing connect request happens on port 69, but the first data packet from the TFTP server is transmitted back on a different, random port. So my question is : how do I ensure that the TFTP client (as an application) is able to receive packets on a machine with the firewall on?

When I run the TFTP client in debug mode in Visual Studio 2005, the client doesn't receive packets either unless I turn off the firewall. How do I solve that?

Thanks

UPDATE (code)

void main(void)
{
    unsigned short OPCODE = htons((unsigned short)1);
    char* fileName = "thisfile.cnf.xml";
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
    SOCKET sockfd;
    int n;
    char buf[256] = {0};
    int L;
    struct sockaddr_in servaddr;
    char recvline[1000];
    int rc;

    wVersionRequested = MAKEWORD( 2, 2 );
    err = WSAStartup( wVersionRequested, &wsaData );
    memcpy(buf, &OPCODE, 2);
    sprintf_s(&buf[2], 254, "%s%c%s%c", fileName, '\0', "octet", '\0');
    L = (int) strlen(fileName) + 9;
    sockfd=socket(AF_INET,SOCK_DGRAM,0);
    memset(&servaddr,0,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr=inet_addr("212.158.10.33");
    servaddr.sin_port=htons(69);
    rc = sendto(sockfd,buf,L,0, (struct sockaddr *)&servaddr,sizeof(servaddr));

    while (1)
    {
       printf("Receive 1st packet...\n");
       /* This call gets blocked unless firewall is off */
       n=recvfrom(sockfd,recvline,1000,0,NULL,NULL);
       printf("%d bytes received\n", n);
       break;
    }
}

Source: (StackOverflow)

uint16_t in array of char

For a school project, I have to develop a TFTP server in C. I have to build a packet in a array of char like this :

 2 bytes    2 bytes    n bytes
+--------+-----------+--------+
|  CODE  |  Block #  |  Data  |
+--------+-----------+--------+

Here is how I build this packet:

int tftp_make_data(char *buffer, size_t *length, uint16_t block, const char *data, size_t n) {
    memset(buffer, 0, *length);
    *length = 0;
    *(buffer) = DATA;
    *length += sizeof(uint16_t);
    *(buffer + *length) = block;
    *length += sizeof(uint16_t);
    memcpy(buffer + *length, data, n);
    *length += n;

    return 0;
}

This function fill buffer with the packet content and fill length with the size of the packet. This works fine if block is lower than 128. If it's greeter than 128, it becomes -128.

Can you help me?


Source: (StackOverflow)

JAVA - Tftp client how to set block size

I am programming a tftp client and it works just fine, as long as i use default block size (512). But since it is a school assignment, i need to test it also with a block size of 1430 and 4300.

When i first comunicate with the server, i use this method:

public void setFilename( String s, String mode) {
        byte []a = s.getBytes();
        int i,j,k;
        for ( i=0; i+2<lenght && i<a.length; i++ ) {
            packet[i+2] = a[i];
        }
        packet[i+2] = 0;
        a = mode.getBytes();
        for ( j=0,i++; i<lenght && j<a.length; i++,j++ ) {
            packet[i+2] = a[j];
        }
        packet[i+2] = 0;


    }

It will set the filename i want to read. and it works just fine.

But i've changed it so i can define a block size:

public void setFilename( String s, String mode, String blockSize ) {
        byte []a = s.getBytes();
        int i,j,k;
        for ( i=0; i+2<lenght && i<a.length; i++ ) {
            packet[i+2] = a[i];
        }
        packet[i+2] = 0;
        a = mode.getBytes();
        for ( j=0,i++; i<lenght && j<a.length; i++,j++ ) {
            packet[i+2] = a[j];
        }
        packet[i+2] = 0;

        a = BLOCKSIZE.getBytes();
        for ( k=0,i++; i<lenght && k<a.length; i++,k++ ) {
            packet[i+2] = a[k];
        }
        packet[i+2] = 0;

        a = blockSize.getBytes();
        for ( k=0,i++; i<lenght && k<a.length; i++,k++ ) {
            packet[i+2] = a[k];
        }
        packet[i+2] = 0;

    }

and here BLOCKSIZE = "blksize" (string) and blockSize = 1430 (int); The problem is, it doesn't work :-/

Can somebody please explain to me how can i define the block size?

Thank you guys :-)


Source: (StackOverflow)