0

I'm writing a TFTP server in Ruby and I don't understand a couple things.

First, I read through the entire RFC and I understand the TFTP part of the packet (2 bytes opcode, etc), but I don't know where the TID's go. Also, I've never done anything in Ruby at a byte level. I don't know how to create a variable that's 2 bytes this and then 1 byte that and then whatever.

If someone could show me an example of how to construct a read request packet in ruby, that'd be sweet. Say I'm on the client side and I select port #20000 (for my local TID) and I want to read the file named /Users/pachun/documents/hello.txt on the server which has a TID of 69 right now because it's the first request. How would I construct that packet in Ruby?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
pachun
  • 926
  • 2
  • 10
  • 26
  • Can you tell us what that packet would look like in binary so we don't have to read the whole RFC? – Linuxios Mar 21 '13 at 21:52
  • Search for "Order of Headers" on in the RFC and it should be in I. Appendix. It describes the packet layout. EDIT: it's the second occurance of "Order of Headers" in the RFC. – pachun Mar 21 '13 at 22:03
  • The first thing to do is show code you've been working on. It's always easier for us to correct your code than to write something from scratch; Our code might not fit your codebase at all and could require a lot of rework on your part, or worse, be unusable. – the Tin Man Mar 21 '13 at 23:13
  • "[ruby tftp server](http://stackoverflow.com/questions/6038283/ruby-tftp-server)" might help, along with the source code for "[putbinary(remotefile, io)](http://www.ruby-doc.org/gems/docs/n/net-tftp-0.1.0/Net/TFTP.html#method-i-putbinary)". – the Tin Man Mar 21 '13 at 23:21

1 Answers1

1

Check out this project:

https://github.com/spiceworks/net-tftp

The code there should answer your questions regarding how to construct byte sequences for communicating with tftp protocol.

Michael Lang
  • 1,028
  • 12
  • 21