Implementing a trivial TFTP client?
Ronald F. Guilmette
rfg at tristatelogic.com
Tue Nov 23 12:12:50 UTC 2010
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.
More information about the freebsd-net
mailing list