From owner-freebsd-net@FreeBSD.ORG Tue Nov 23 12:12:50 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 24D7F106564A for ; Tue, 23 Nov 2010 12:12:50 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from outgoing.tristatelogic.com (segfault.tristatelogic.com [69.62.255.118]) by mx1.freebsd.org (Postfix) with ESMTP id 048068FC12 for ; Tue, 23 Nov 2010 12:12:49 +0000 (UTC) Received: from segfault-nmh-helo.tristatelogic.com (localhost [127.0.0.1]) by segfault.tristatelogic.com (Postfix) with ESMTP id 5840BBDC75 for ; Tue, 23 Nov 2010 04:12:49 -0800 (PST) To: freebsd-net@freebsd.org Date: Tue, 23 Nov 2010 04:12:49 -0800 Message-ID: <41880.1290514369@tristatelogic.com> From: "Ronald F. Guilmette" Subject: 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 12:12:50 -0000 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. Regards, rfg P.S. If possible, please answer on-list. Otherwise my geeky spam filter may cause me to miss your reply. Thanks.