Simplified math in ptransfer() to avoid destroying bits (and somethings
[unix-history] / usr / src / usr.bin / ftp / ftp.c
index 85c9d4e..6f3ed61 100644 (file)
@@ -1,21 +1,21 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)ftp.c      4.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)ftp.c      4.12 (Berkeley) %G%";
 #endif
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #endif
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 
 #include <netinet/in.h>
 
 #include <netinet/in.h>
+#include <arpa/ftp.h>
 
 #include <stdio.h>
 #include <signal.h>
 
 #include <stdio.h>
 #include <signal.h>
-#include <time.h>
 #include <errno.h>
 #include <netdb.h>
 
 #include <errno.h>
 #include <netdb.h>
 
-#include "ftp.h"
 #include "ftp_var.h"
 
 struct sockaddr_in hisctladdr;
 #include "ftp_var.h"
 
 struct sockaddr_in hisctladdr;
@@ -272,7 +272,7 @@ sendrequest(cmd, local, remote)
                                fflush(stdout);
                        }
                }
                                fflush(stdout);
                        }
                }
-               if (hash) {
+               if (hash && bytes > 0) {
                        putchar('\n');
                        fflush(stdout);
                }
                        putchar('\n');
                        fflush(stdout);
                }
@@ -303,6 +303,8 @@ sendrequest(cmd, local, remote)
                        }
                }
                if (hash) {
                        }
                }
                if (hash) {
+                       if (bytes < hashbytes)
+                               putchar('#');
                        putchar('\n');
                        fflush(stdout);
                }
                        putchar('\n');
                        fflush(stdout);
                }
@@ -404,7 +406,7 @@ recvrequest(cmd, local, remote, mode)
                                fflush(stdout);
                        }
                }
                                fflush(stdout);
                        }
                }
-               if (hash) {
+               if (hash && bytes > 0) {
                        putchar('\n');
                        fflush(stdout);
                }
                        putchar('\n');
                        fflush(stdout);
                }
@@ -437,6 +439,8 @@ recvrequest(cmd, local, remote, mode)
                        bytes++;
                }
                if (hash) {
                        bytes++;
                }
                if (hash) {
+                       if (bytes < hashbytes)
+                               putchar('#');
                        putchar('\n');
                        fflush(stdout);
                }
                        putchar('\n');
                        fflush(stdout);
                }
@@ -487,6 +491,11 @@ noport:
                perror("ftp: socket");
                return (1);
        }
                perror("ftp: socket");
                return (1);
        }
+       if (!sendport)
+               if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, 0, 0) < 0) {
+                       perror("ftp: setsockopt (resuse address)");
+                       goto bad;
+               }
        if (bind(data, (char *)&data_addr, sizeof (data_addr), 0) < 0) {
                perror("ftp: bind");
                goto bad;
        if (bind(data, (char *)&data_addr, sizeof (data_addr), 0) < 0) {
                perror("ftp: bind");
                goto bad;
@@ -547,15 +556,14 @@ ptransfer(direction, bytes, t0, t1)
        struct timeval *t0, *t1;
 {
        struct timeval td;
        struct timeval *t0, *t1;
 {
        struct timeval td;
-       long ms;
-       float bs;
+       float s, bs;
 
        tvsub(&td, t1, t0);
 
        tvsub(&td, t1, t0);
-       ms = (td.tv_sec * 1000) + (td.tv_usec / 1000);
+       s = td.tv_sec + (td.tv_usec / 1000000.);
 #define        nz(x)   ((x) == 0 ? 1 : (x))
 #define        nz(x)   ((x) == 0 ? 1 : (x))
-       bs = ((bytes * NBBY * 1000) / (float) nz(ms)) / NBBY;
-       printf("%ld bytes %s in %d.%02d seconds (%.2g Kbytes/s)\n",
-               bytes, direction, td.tv_sec, td.tv_usec / 10000, bs / 1024.);
+       bs = bytes / nz(s);
+       printf("%ld bytes %s in %.2g seconds (%.2g Kbytes/s)\n",
+               bytes, direction, s, bs / 1024.);
 }
 
 tvadd(tsum, t0)
 }
 
 tvadd(tsum, t0)