Package: atftp
Version: 0.7-7

When atftpd is run on a linux server, it listens on the local broadcast address 255.255.255.255 instead of the local network 0.0.0.0. This confuses some clients such as Sparcstation 20. There is no Linux kernel attribute to fix this. The following patch adds a command line option to atftpd that forces it to listen to 0.0.0.0 so these clients may communicate with the server. I have been using this patch without problem for two years in a production environment.

For more information about the patch, please see: http://atftplocalnet.sourceforge.net

I am using Redhat Linux AS Release 3, kernel 2.4.21-20smp, atftp0.7-7.

<--- cut here --->
ATFTPListenLocal Patch
This patch adds the --listen-local command-line option to in.tftpd.
This option forces the service daemon to listen on a local network
address (0.0.0.0 or a local interface).

Original patch by Michael Martinez <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Copyright (c) 2004, Michael Martinez
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:

- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of Michael Martinez nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

====================================================================
diff -r -u atftp-0.7/tftpd.c atftp-0.7-listenlocal/tftpd.c
--- atftp-0.7/tftpd.c   2004-02-26 19:05:26.000000000 -0700
+++ atftp-0.7-listenlocal/tftpd.c       2004-10-28 15:22:53.000000000 -0600
@@ -60,6 +60,9 @@
 char directory[MAXLEN] = "/tftpboot/";
 int retry_timeout = S_TIMEOUT;

+int on = 1;
+int listen_local = 0;
+
 int tftpd_daemon = 0;           /* By default we are started by inetd */
 int tftpd_daemon_no_fork = 0;   /* For who want a false daemon mode */
 short tftpd_port = 0;           /* Port atftpd listen to */
@@ -615,6 +618,24 @@
           data->sockfd = socket(PF_INET, SOCK_DGRAM, 0);
           to.sin_family = AF_INET;
           to.sin_port = 0;
+ /* Force socket to listen on local address. Do not listen on broadcast address 255.255.255.255. + If the socket listens on the broadcast address, Linux tells the remote client the port + is unreachable. This happens even if SO_BROADCAST is set in setsockopt for this socket. + I was unable to find a kernel option or /proc/sys flag to make the kernel pay attention to + these requests, so the workaround is to force listening on the local address. */
+          if (listen_local == 1)
+          {
+               to.sin_addr.s_addr = INADDR_ANY;
+ logger(LOG_INFO, "forcing socket to listen on local address"); + if (setsockopt(data->sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) != 0) {
+                  logger(LOG_ERR, "setsockopt: %s", strerror(errno));
+               }
+          }
+          else
+          {
+ logger(LOG_INFO, "socket may listen on any address, including broadcast");
+          }
+
           if (data->sockfd > 0)
           {
                /* bind the socket to the interface */
@@ -811,6 +832,7 @@
           { "no-multicast", 0, NULL, 'M' },
           { "logfile", 1, NULL, 'L' },
           { "pidfile", 1, NULL, 'I'},
+          { "listen-local", 0, NULL, 'F'},
           { "daemon", 0, NULL, 'D' },
           { "no-fork", 0, NULL, 'N'},
           { "user", 1, NULL, 'U'},
@@ -888,6 +910,9 @@
           case 'I':
                pidfile = strdup(optarg);
                break;
+          case 'F':
+               listen_local = 1;
+               break;
           case 'D':
                tftpd_daemon = 1;
                break;
@@ -1015,6 +1040,10 @@
logger(LOG_INFO, " log file: %s", (log_file==NULL) ? "syslog":log_file);
      if (pidfile)
           logger(LOG_INFO, "  pid file: %s", pidfile);
+     if (listen_local == 1)
+          logger(LOG_INFO, "  forcing to listen on local interfaces: on.");
+     else
+          logger(LOG_INFO, "  not forcing to listen on local interfaces.");
      if (tftpd_daemon == 1)
           logger(LOG_INFO, "  server timeout: Not used");
      else
@@ -1116,6 +1145,7 @@
" --no-multicast : disable 'multicast' from RFC2090\n"
             "  --logfile <file>           : logfile to log logs to ;-)\n"
             "  --pidfile <file>           : write PID to this file\n"
+ " --listen-local : force listen on local network address\n" " --daemon : run atftpd standalone (no inetd)\n"
             "  --no-fork                  : run as a daemon, don't fork\n"
             "  --user <user[.group]>      : default is nobody\n"




<--- cut here --->

--
Regards,

Michael Martinez
Engineering Manager
Tech Computer Center (TCC), Speare Room 128
New Mexico Tech, 801 Leroy Place, Socorro, NM 87801
(505) 835-5388 [EMAIL PROTECTED]
http://www.nmt.edu/tcc/
--
http://sftplogging.sourceforge.net
http://atftplocalnet.sourceforge.net/


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to