Date: Tue, 23 Nov 2010 16:42:54 +0300 From: Aleksandr A Babaylov <.@babolo.ru> To: "Ronald F. Guilmette" <rfg@tristatelogic.com> Cc: freebsd-net@freebsd.org Subject: Re: Implementing a trivial TFTP client? Message-ID: <20101123134254.GB36224@babolo.ru> In-Reply-To: <41880.1290514369@tristatelogic.com> References: <41880.1290514369@tristatelogic.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Nov 23, 2010 at 04:12:49AM -0800, Ronald F. Guilmette wrote: > I have been attempting to implment a trivial sort of TFTP client from > scratch, and its been somewhat of a humbling experience so far, and > its taught me that I don't know quite as much about BSD socket programming > as I though I did. > > So anyway, maybe some kind soul here would be willing to help me out and > offer me some guidance. > > I'm not going to go over thet TFTP protocol here. That's well documented > elsewhere. My question is really pretty simple: What would be the proper > sequence of socket-related kernel calls necessary to implement a TFTP > client that just simply connected to a TFTP server, and then sent (wrote) > one file consisting of less than 512 bytes of data (i.e. just one packet's > worth)? > > I've been trying the following sequence, and my code is kinda-sorta working, > but apparently not quite (because the file never actually gets there): > > socket() > bind() /* grab a fixed local port# */ > /* NOTE: sin_addr=INADDR_ANY and sin_port=0 */ > sendto() /* send the initial WRQ packet */ > recvfrom() /* get the initial ACK packet */ > connect() /* now that we know what port# the sever wants to talk > to us on, we can "connect" our existing socket to > that specific port# on the server's side */ > send() /* Send the data packet */ > recv() /* receive the data ACK packet */ > > Obviously, I am leaving out all of the grubby little details. I just want > to focus on the proper sequence of socket primitive calls to make a trivial > TFTP client. > > So, ah, does the above sequence look reasonable for that job? If not, where > have I gone wrong? > > It does appear that the initial few calls are doing what they should, and > the connection does start up, lickety split. But then after that, ACK > responses to the data packets seem to arrive VERY VERY slowly, and although > the remote TFTP daemon _does_ create the new output file up on the server > (see the tftp "-w" option) the file never seems to get any bigger than 0 > bytes in length. :-( > > My guess is that I'm doing multiple things in a substantially Wrong way. > > Any guidance would be appreciated. Try ktrace -i tftp and look at kdump to see how it works
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101123134254.GB36224>