bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] Re: [PATCH] Add `tftpd' and `tftp' test.


From: Ludovic Courtès
Subject: [bug-inetutils] Re: [PATCH] Add `tftpd' and `tftp' test.
Date: Sat, 23 Oct 2010 16:03:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hello!

The tftpd test broke on Hydra[*] because the call
‘getservbyname ("tftp", "udp")’ failed there since chroot builds lack
/etc/services:

--8<---------------cut here---------------start------------->8---
170+0 records in
170+0 records out
174080 bytes (174 kB) copied, 0.00138769 s, 125 MB/s
trying with address `192.168.1.19'...
tftp: udp/tftp: unknown service
cmp: tftp-test-file: No such file or directory
./tftp.sh: line 76: kill: (10728) - No such process
FAIL: tftp.sh
--8<---------------cut here---------------end--------------->8---

In fact, that call is not needed for the test since it specifies a port
number when invoking ‘tftp’.

The attached patch fixes ‘tftp’ so that it only tries to resolve the
“tftp” service when no port was explicitly specified.

Thanks,
Ludo’.

[*] http://hydra.nixos.org/job/gnu/inetutils-master/build

>From 19d17c06a327b728bfc443bdc1c91f5f4da579be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <address@hidden>
Date: Sat, 23 Oct 2010 15:57:40 +0200
Subject: [PATCH] tftp: Resolve the "tftp" service only when no port is 
specified.

* src/tftp.c (port): Change from `short' to `int'.  Add comment.
  (sp): Remove variable.
  (main): Remove `getservbyname ("tftp", "udp")'.
  (setpeer): Add `getservbyname ("tftp", "udp")' call for when
  ARGC != 3.
  (put, get): Refer to PORT instead of SP->s_port.
---
 ChangeLog  |   11 +++++++++++
 src/tftp.c |   36 +++++++++++++++++++++++-------------
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d2f4be6..11a3e64 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-10-23  Ludovic Courtès  <address@hidden>
+
+       tftp: Resolve the "tftp" service only when no port is specified.
+
+       * src/tftp.c (port): Change from `short' to `int'.  Add comment.
+       (sp): Remove variable.
+       (main): Remove `getservbyname ("tftp", "udp")'.
+       (setpeer): Add `getservbyname ("tftp", "udp")' call for when
+       ARGC != 3.
+       (put, get): Refer to PORT instead of SP->s_port.
+
 2010-10-19  Alfred M. Szmidt  <address@hidden>
 
        Added gendocs module for generation of web manual.
diff --git a/src/tftp.c b/src/tftp.c
index 6515976..9364cb6 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -99,11 +99,13 @@ static int maxtimeout = 5 * TIMEOUT;
 
 static struct sockaddr_in peeraddr;    /* filled in by main */
 static int f;                  /* the opened socket */
-static short port;
 static int trace;
 static int verbose;
 static int connected;
 
+/* Port number in network byte order of the server.  */
+static int port;
+
 char mode[32];
 char line[200];
 int margc;
@@ -111,7 +113,6 @@ char *margv[20];
 char *prompt = "tftp";
 jmp_buf toplevel;
 void intr (int signo);
-struct servent *sp;
 
 void get (int, char **);
 void help (int, char **);
@@ -226,12 +227,6 @@ main (int argc, char *argv[])
   iu_argp_init ("tftp", default_program_authors);
   argp_parse (&argp, argc, argv, 0, NULL, NULL);
 
-  sp = getservbyname ("tftp", "udp");
-  if (sp == 0)
-    {
-      fprintf (stderr, "tftp: udp/tftp: unknown service\n");
-      exit (EXIT_FAILURE);
-    }
   f = socket (AF_INET, SOCK_DGRAM, 0);
   if (f < 0)
     {
@@ -345,9 +340,9 @@ setpeer (int argc, char *argv[])
       hostname = xstrdup (argv[1]);
     }
 
-  port = sp->s_port;
   if (argc == 3)
     {
+      /* Take the user-specified port number.  */
       port = atoi (argv[2]);
       if (port < 0)
        {
@@ -357,6 +352,21 @@ setpeer (int argc, char *argv[])
        }
       port = htons (port);
     }
+  else
+    {
+      /* Use the standard TFTP port.  */
+      struct servent *sp;
+
+      sp = getservbyname ("tftp", "udp");
+      if (sp == 0)
+       {
+         fprintf (stderr, "tftp: udp/tftp: unknown service\n");
+         exit (EXIT_FAILURE);
+       }
+
+      port = sp->s_port;
+    }
+
   connected = 1;
 }
 
@@ -483,7 +493,7 @@ put (int argc, char *argv[])
        }
       if (verbose)
        printf ("putting %s to %s:%s [%s]\n", cp, hostname, targ, mode);
-      peeraddr.sin_port = port ? port : sp->s_port;
+      peeraddr.sin_port = port;
       send_file (fd, targ, mode);
       return;
     }
@@ -503,7 +513,7 @@ put (int argc, char *argv[])
        }
       if (verbose)
        printf ("putting %s to %s:%s [%s]\n", argv[n], hostname, targ, mode);
-      peeraddr.sin_port = port ? port : sp->s_port;
+      peeraddr.sin_port = port;
       send_file (fd, targ, mode);
     }
 }
@@ -568,7 +578,7 @@ get (int argc, char *argv[])
          if (verbose)
            printf ("getting from %s:%s to %s [%s]\n",
                    hostname, src, cp, mode);
-         peeraddr.sin_port = port ? port : sp->s_port;
+         peeraddr.sin_port = port;
          recvfile (fd, src, mode);
          break;
        }
@@ -582,7 +592,7 @@ get (int argc, char *argv[])
        }
       if (verbose)
        printf ("getting from %s:%s to %s [%s]\n", hostname, src, cp, mode);
-      peeraddr.sin_port = port ? port : sp->s_port;
+      peeraddr.sin_port = port;
       recvfile (fd, src, mode);
     }
 }
-- 
1.7.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]