From owner-freebsd-net@FreeBSD.ORG Tue Nov 23 13:42:00 2010 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CD321106566C for ; Tue, 23 Nov 2010 13:42:00 +0000 (UTC) (envelope-from "."@babolo.ru) Received: from smtp1.babolo.ru (smtp1.babolo.ru [195.9.14.139]) by mx1.freebsd.org (Postfix) with ESMTP id 3F95A8FC14 for ; Tue, 23 Nov 2010 13:41:59 +0000 (UTC) Received: from cicuta.babolo.ru ([194.58.246.5]) by smtp1.babolo.ru (8.14.2/8.14.2) with SMTP id oANDdCe5067544; Tue, 23 Nov 2010 16:39:12 +0300 (MSK) (envelope-from .@babolo.ru) Received: (nullmailer pid 36391 invoked by uid 136); Tue, 23 Nov 2010 13:42:54 -0000 Date: Tue, 23 Nov 2010 16:42:54 +0300 From: Aleksandr A Babaylov <.@babolo.ru> To: "Ronald F. Guilmette" Message-ID: <20101123134254.GB36224@babolo.ru> References: <41880.1290514369@tristatelogic.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41880.1290514369@tristatelogic.com> Cc: freebsd-net@freebsd.org Subject: Re: Implementing a trivial TFTP client? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2010 13:42:00 -0000 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