{"id":44,"date":"2015-05-10T03:56:45","date_gmt":"2015-05-10T03:56:45","guid":{"rendered":"http:\/\/www.beer.org\/beerblog\/?p=44"},"modified":"2016-12-23T18:29:42","modified_gmt":"2016-12-23T18:29:42","slug":"tftpd-and-xinetd-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.beer.org\/blog\/index.php\/2015\/05\/10\/tftpd-and-xinetd-on-ubuntu\/","title":{"rendered":"tftpd and xinetd on Ubuntu"},"content":{"rendered":"<p>I&#8217;ve been doing embedded for a long time but I&#8217;ve been doing unix admin stuff for way longer. I&#8217;ve probably been using inetd and tftp for 25 years. I&#8217;m always shocked at the ability for tftp to take up a couple hours of time the first time you want to get it running on a host.<\/p>\n<p>When doing embedded, I typically like to point tftpboot at my compiler output directory which saves a copy step. Sometimes you forget to copy and you can&#8217;t figure out why your printf()s aren&#8217;t showing up (because you&#8217;re still running an old version).<\/p>\n<p>Anyway, on Ubuntu, you typically install xinetd and tftpd&#8230;<\/p>\n<pre>sudo apt-get install xinetd tftpd\r\n<\/pre>\n<p>Then you want to create \/etc\/xinetd.d\/tftpd :<\/p>\n<pre>service tftp\r\n{\r\n        disable         = no\r\n        socket_type     = dgram\r\n        protocol        = udp\r\n        wait            = yes\r\n        user            = hpeyerl\r\n        server          = \/usr\/sbin\/in.tftpd\r\n        server_args     = -s \/home\/hpeyerl\/trunk\/firmware\/esp8266\r\n}\r\n<\/pre>\n<p>Then poke xinetd:<\/p>\n<pre>$ sudo pkill -1 xinetd\r\n<\/pre>\n<p>I always like to debug by using tcpdump:<\/p>\n<pre>06:11:42.796755 IP (tos 0x0, ttl 255, id 4, offset 0, flags [none], proto UDP (17), length 56)\r\n    192.168.37.249.69 &gt; 192.168.37.30.69:  28 RRQ \"\/images\/antares.rom\" octet\r\n    0x0000:  4500 0038 0004 0000 ff11 ef48 c0a8 25f9  E..8.......H..%.\r\n    0x0010:  c0a8 251e 0045 0045 0024 c8b6 0001 2f69  ..%..E.E.$....\/i\r\n    0x0020:  6d61 6765 732f 616e 7461 7265 732e 726f  mages\/antares.ro\r\n    0x0030:  6d00 6f63 7465 7400                      m.octet.\r\n06:11:42.799663 IP (tos 0x0, ttl 64, id 8086, offset 0, flags [DF], proto UDP (17), length 49)\r\n    192.168.37.30.42622 &gt; 192.168.37.249.69:  21 ERROR EACCESS \"Access violation\"\r\n    0x0000:  4500 0031 1f96 4000 4011 4ebe c0a8 251e  E..1..@.@.N...%.\r\n    0x0010:  c0a8 25f9 a67e 0045 001d cc96 0005 0002  ..%..~.E........\r\n    0x0020:  4163 6365 7373 2076 696f 6c61 7469 6f6e  Access.violation\r\n    0x0030:  00                                       .\r\n<\/pre>\n<p>Sometimes syslog is helpful:<\/p>\n<pre>May 10 06:03:57 pm001 in.tftpd[4564]: connect from 192.168.37.30 (192.168.37.30)\r\nMay 10 06:03:57 pm001 tftpd[4565]: tftpd: trying to get file: antares.rom\r\nMay 10 06:03:57 pm001 tftpd[4565]: tftpd: serving file from \/srv\/tftp\r\n<\/pre>\n<p>The key there is &#8220;\/srv\/tftp&#8221;&#8230; Since there&#8217;s no mention of \/srv\/tftp in your xinetd.d config file, something else must be happening&#8230;<\/p>\n<p>So, here are some gotchas that will consume some debug time:<\/p>\n<ul>\n<li>If you&#8217;re testing this by using tftp on the same host as tftpd, you won&#8217;t see anything in tcpdump because the packets are short-cutting through your localhost interface.<\/li>\n<li>On Ubuntu, there is also an \/etc\/inetd.conf which is your culprit:<\/li>\n<\/ul>\n<pre>#:BOOT: TFTP service is provided primarily for booting.  Most sites\r\n#       run this only on machines acting as \"boot servers.\"\r\ntftp           dgram   udp     wait    nobody  \/usr\/sbin\/tcpd  \/usr\/sbin\/in.tftpd \/srv\/tftp\r\n<\/pre>\n<ul>\n<li>tftpd is very picky about permissions. You might be tempted to make every element in your path 777, I don&#8217;t need to tell you this is a bad idea.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been doing embedded for a long time but I&#8217;ve been doing unix admin stuff for way longer. I&#8217;ve probably been using inetd and tftp for 25 years. I&#8217;m always shocked at the ability for tftp to take up a couple hours of time the first time you want to get it running on a&#8230; <a class=\"moretag\" href=\"https:\/\/www.beer.org\/blog\/index.php\/2015\/05\/10\/tftpd-and-xinetd-on-ubuntu\/\">Continue reading &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,7],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-memotoself","category-tech-stuff"],"_links":{"self":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":1,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":45,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/44\/revisions\/45"}],"wp:attachment":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}