convert to 4.1c sys calls and directory layout
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 15 Nov 1982 07:21:59 +0000 (23:21 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 15 Nov 1982 07:21:59 +0000 (23:21 -0800)
SCCS-vsn: usr.bin/ruptime/ruptime.c 4.6
SCCS-vsn: usr.sbin/rwhod/rwhod.c 4.5
SCCS-vsn: include/protocols/rwhod.h 4.2
SCCS-vsn: usr.bin/telnet/telnet.c 4.12
SCCS-vsn: libexec/telnetd/telnetd.c 4.10
SCCS-vsn: usr.bin/tftp/main.c 4.3
SCCS-vsn: usr.bin/tftp/tftp.c 4.3
SCCS-vsn: libexec/tftpd/tftpd.c 4.4

usr/src/include/protocols/rwhod.h
usr/src/libexec/telnetd/telnetd.c
usr/src/libexec/tftpd/tftpd.c
usr/src/usr.bin/ruptime/ruptime.c
usr/src/usr.bin/telnet/telnet.c
usr/src/usr.bin/tftp/main.c
usr/src/usr.bin/tftp/tftp.c
usr/src/usr.sbin/rwhod/rwhod.c

index 1c4b3da..e178ef3 100644 (file)
@@ -1,11 +1,11 @@
-/*     rwhod.h 4.1     82/04/02        */
+/*     rwhod.h 4.2     82/11/14        */
 
 struct whod {
        int     wd_sendtime;
        int     wd_recvtime;
        char    wd_hostname[32];
        int     wd_loadav[3];
 
 struct whod {
        int     wd_sendtime;
        int     wd_recvtime;
        char    wd_hostname[32];
        int     wd_loadav[3];
-       int     wd_bootime;
+       int     wd_boottime;
        struct  whoent {
                struct  utmp we_utmp;
                int     we_idle;
        struct  whoent {
                struct  utmp we_utmp;
                int     we_idle;
index abc2ec1..d0afe58 100644 (file)
@@ -1,22 +1,24 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)telnetd.c  4.9 82/10/10";
+static char sccsid[] = "@(#)telnetd.c  4.10 82/11/14";
 #endif
 
 /*
  * Stripped-down telnet server.
  */
 #endif
 
 /*
  * Stripped-down telnet server.
  */
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
 #include <stdio.h>
 #include <signal.h>
 #include <errno.h>
 #include <sgtty.h>
 #include <wait.h>
 #include <stdio.h>
 #include <signal.h>
 #include <errno.h>
 #include <sgtty.h>
 #include <wait.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/in.h>
 #include <netdb.h>
 #include <netdb.h>
+
 #include "telnet.h"
 
 #include "telnet.h"
 
-#define        INFINITY        10000000
 #define        BELL            '\07'
 
 char   hisopts[256];
 #define        BELL            '\07'
 
 char   hisopts[256];
@@ -42,7 +44,6 @@ extern        int errno;
 char   line[] = "/dev/ptyp0";
 
 struct sockaddr_in sin = { AF_INET };
 char   line[] = "/dev/ptyp0";
 
 struct sockaddr_in sin = { AF_INET };
-int    options = SO_ACCEPTCONN|SO_KEEPALIVE;
 
 main(argc, argv)
        char *argv[];
 
 main(argc, argv)
        char *argv[];
@@ -58,8 +59,6 @@ main(argc, argv)
        }
        sin.sin_port = sp->s_port;
        argc--, argv++;
        }
        sin.sin_port = sp->s_port;
        argc--, argv++;
-       if (argc > 0 && !strcmp(argv[0], "-d"))
-               options |= SO_DEBUG, argc--, argv++;
        if (argc > 0) {
                sin.sin_port = atoi(*argv);
                if (sin.sin_port <= 0) {
        if (argc > 0) {
                sin.sin_port = atoi(*argv);
                if (sin.sin_port <= 0) {
@@ -67,7 +66,7 @@ main(argc, argv)
                        exit(1);
                }
        }
                        exit(1);
                }
        }
-       sin.sin_port = htons(sin.sin_port);
+       sin.sin_port = htons((u_short)sin.sin_port);
 #ifndef DEBUG
        if (fork())
                exit(0);
 #ifndef DEBUG
        if (fork())
                exit(0);
@@ -83,24 +82,32 @@ main(argc, argv)
          }
        }
 #endif
          }
        }
 #endif
+again:
+       s = socket(0, SOCK_STREAM, 0, 0);
+       if (s < 0) {
+               perror("telnetd: socket");;
+               sleep(5);
+               goto again;
+       }
+       while (bind(s, (caddr_t)&sin, sizeof (sin), 0) < 0) {
+               perror("telnetd: bind");
+               sleep(5);
+       }
+       listen(s, 10);
        for (;;) {
        for (;;) {
-               errno = 0;
-               if ((s = socket(SOCK_STREAM, 0, &sin, options)) < 0) {
-                       perror("socket");
-                       sleep(5);
-                       continue;
-               }
-               if (accept(s, 0) < 0) {
+               int s2;
+
+               s2 = accept(s, (caddr_t)0, 0);
+               if (s2 < 0) {
                        perror("accept");
                        perror("accept");
-                       close(s);
                        sleep(1);
                        continue;
                }
                if ((pid = fork()) < 0)
                        printf("Out of processes\n");
                else if (pid == 0)
                        sleep(1);
                        continue;
                }
                if ((pid = fork()) < 0)
                        printf("Out of processes\n");
                else if (pid == 0)
-                       doit(s);
-               close(s);
+                       doit(s2);
+               close(s2);
                while (wait3(status, WNOHANG, 0) > 0)
                        continue;
        }
                while (wait3(status, WNOHANG, 0) > 0)
                        continue;
        }
@@ -202,7 +209,7 @@ telnet(f, p)
                        ibits |= (1 << f);
                if (ncc < 0 && pcc < 0)
                        break;
                        ibits |= (1 << f);
                if (ncc < 0 && pcc < 0)
                        break;
-               select(32, &ibits, &obits, INFINITY);
+               select(16, &ibits, &obits, 0, 0);
                if (ibits == 0 && obits == 0) {
                        sleep(5);
                        continue;
                if (ibits == 0 && obits == 0) {
                        sleep(5);
                        continue;
@@ -393,7 +400,7 @@ telrcv()
                        continue;
 
                default:
                        continue;
 
                default:
-                       printf("netser: panic state=%d\n", state);
+                       printf("telnetd: panic state=%d\n", state);
                        exit(1);
                }
        }
                        exit(1);
                }
        }
@@ -560,7 +567,9 @@ cleanup()
 
        rmut();
        vhangup();
 
        rmut();
        vhangup();
+#ifndef notdef
        ioctl(net, SIOCDONE, &how);
        ioctl(net, SIOCDONE, &how);
+#endif
        kill(0, SIGKILL);
        exit(1);
 }
        kill(0, SIGKILL);
        exit(1);
 }
index 361282c..42fd238 100644 (file)
@@ -1,25 +1,27 @@
-/*     tftpd.c 4.3     82/10/08        */
+/*     tftpd.c 4.4     82/11/14        */
 
 /*
  * Trivial file transfer protocol server.
  */
 #include <sys/types.h>
 
 /*
  * Trivial file transfer protocol server.
  */
 #include <sys/types.h>
-#include <net/in.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
-#include <signal.h>
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
+
+#include <netinet/in.h>
+
+#include <signal.h>
 #include <stat.h>
 #include <stdio.h>
 #include <wait.h>
 #include <errno.h>
 #include <ctype.h>
 #include <netdb.h>
 #include <stat.h>
 #include <stdio.h>
 #include <wait.h>
 #include <errno.h>
 #include <ctype.h>
 #include <netdb.h>
+
 #include "tftp.h"
 
 extern int errno;
 struct sockaddr_in sin = { AF_INET };
 int    f;
 #include "tftp.h"
 
 extern int errno;
 struct sockaddr_in sin = { AF_INET };
 int    f;
-int    options;
 char   buf[BUFSIZ];
 
 main(argc, argv)
 char   buf[BUFSIZ];
 
 main(argc, argv)
@@ -36,7 +38,7 @@ main(argc, argv)
                fprintf(stderr, "tftpd: udp/tftp: unknown service\n");
                exit(1);
        }
                fprintf(stderr, "tftpd: udp/tftp: unknown service\n");
                exit(1);
        }
-       sin.sin_port = htons(sp->s_port);
+       sin.sin_port = htons((u_short)sp->s_port);
 #ifndef DEBUG
        if (fork())
                exit(0);
 #ifndef DEBUG
        if (fork())
                exit(0);
@@ -52,36 +54,37 @@ main(argc, argv)
          }
        }
 #endif
          }
        }
 #endif
-       argc--, argv++;
-       if (argc > 0 && !strcmp(argv[0], "-d"))
-               options |= SO_DEBUG;
        for (;;) {
        for (;;) {
-               errno = 0;
-               f = socket(SOCK_DGRAM, 0, &sin, options);
+               int fromlen;
+
+               f = socket(0, SOCK_DGRAM, 0, 0);
                if (f < 0) {
                if (f < 0) {
-                       perror("socket");
+                       perror("tftpd: socket");
+                       close(f);
+                       sleep(5);
+                       continue;
+               }
+               while (bind(f, (caddr_t)&sin, sizeof (sin), 0) < 0) {
+                       perror("tftpd: bind");
+                       close(f);
                        sleep(5);
                        continue;
                }
 again:
                        sleep(5);
                        continue;
                }
 again:
-               n = receive(f, &from, buf, sizeof (buf));
+               fromlen = sizeof (from);
+               n = recvfrom(f, buf, sizeof (buf), (caddr_t)&from, &fromlen, 0);
                if (n <= 0) {
                        if (n < 0)
                if (n <= 0) {
                        if (n < 0)
-                               perror("receive");
+                               perror("tftpd: recvfrom");
                        goto again;
                }
                tp = (struct tftphdr *)buf;
                        goto again;
                }
                tp = (struct tftphdr *)buf;
-#if vax || pdp11
                tp->th_opcode = ntohs(tp->th_opcode);
                tp->th_opcode = ntohs(tp->th_opcode);
-#endif
                if (tp->th_opcode == RRQ || tp->th_opcode == WRQ)
                        if (fork() == 0)
                                tftp(&from, tp, n);
                (void) close(f);
                if (tp->th_opcode == RRQ || tp->th_opcode == WRQ)
                        if (fork() == 0)
                                tftp(&from, tp, n);
                (void) close(f);
-#ifdef notdef
                while (wait3(status, WNOHANG, 0) > 0)
                while (wait3(status, WNOHANG, 0) > 0)
-#else
-               while (wait3(status, 0, 0) > 0)
                        continue;
        }
 }
                        continue;
        }
 }
@@ -118,7 +121,7 @@ tftp(client, tp, size)
        register struct formats *pf;
        char *filename, *mode;
 
        register struct formats *pf;
        char *filename, *mode;
 
-       if (connect(f, client) < 0) {
+       if (connect(f, (caddr_t)client, sizeof (*client), 0) < 0) {
                perror("connect");
                exit(1);
        }
                perror("connect");
                exit(1);
        }
@@ -241,8 +244,8 @@ again:
                }
                alarm(0);
 #if vax || pdp11
                }
                alarm(0);
 #if vax || pdp11
-               tp->th_opcode = ntohs(tp->th_opcode);
-               tp->th_block = ntohs(tp->th_block);
+               tp->th_opcode = ntohs((u_short)tp->th_opcode);
+               tp->th_block = ntohs((u_short)tp->th_block);
 #endif
                if (tp->th_opcode == ERROR)
                        break;
 #endif
                if (tp->th_opcode == ERROR)
                        break;
@@ -288,8 +291,8 @@ again:
                }
                alarm(0);
 #if vax || pdp11
                }
                alarm(0);
 #if vax || pdp11
-               tp->th_opcode = ntohs(tp->th_opcode);
-               tp->th_block = ntohs(tp->th_block);
+               tp->th_opcode = ntohs((u_short)tp->th_opcode);
+               tp->th_block = ntohs((u_short)tp->th_block);
 #endif
                if (tp->th_opcode == ERROR)
                        break;
 #endif
                if (tp->th_opcode == ERROR)
                        break;
index d54ab41..20e11b6 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)ruptime.c  4.5 82/10/07";
+static char sccsid[] = "@(#)ruptime.c  4.6 82/11/14";
 #endif
 
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
@@ -118,7 +118,7 @@ again:
                printf("%-8.8s%s,  %4d user%s  load %*.2f, %*.2f, %*.2f\n",
                    hsp->hs_wd->wd_hostname,
                    interval(hsp->hs_wd->wd_sendtime -
                printf("%-8.8s%s,  %4d user%s  load %*.2f, %*.2f, %*.2f\n",
                    hsp->hs_wd->wd_hostname,
                    interval(hsp->hs_wd->wd_sendtime -
-                       hsp->hs_wd->wd_bootime, "  up"),
+                       hsp->hs_wd->wd_boottime, "  up"),
                    hsp->hs_nusers,
                    hsp->hs_nusers == 1 ? ", " : "s,",
                    maxloadav >= 1000 ? 5 : 4,
                    hsp->hs_nusers,
                    hsp->hs_nusers == 1 ? ", " : "s,",
                    maxloadav >= 1000 ? 5 : 4,
@@ -209,9 +209,9 @@ tcmp(h1, h2)
 
        return (
                (down(h2) ? h2->hs_wd->wd_recvtime - now
 
        return (
                (down(h2) ? h2->hs_wd->wd_recvtime - now
-                         : h2->hs_wd->wd_sendtime - h2->hs_wd->wd_bootime)
+                         : h2->hs_wd->wd_sendtime - h2->hs_wd->wd_boottime)
                -
                (down(h1) ? h1->hs_wd->wd_recvtime - now
                -
                (down(h1) ? h1->hs_wd->wd_recvtime - now
-                         : h1->hs_wd->wd_sendtime - h1->hs_wd->wd_bootime)
+                         : h1->hs_wd->wd_sendtime - h1->hs_wd->wd_boottime)
        );
 }
        );
 }
index c03247e..a157be0 100644 (file)
@@ -1,23 +1,25 @@
-static char sccsid[] = "@(#)telnet.c   4.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)telnet.c   4.12 (Berkeley) %G%";
 /*
  * User telnet program.
  */
 /*
  * User telnet program.
  */
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
 #include <stdio.h>
 #include <ctype.h>
 #include <errno.h>
 #include <signal.h>
 #include <sgtty.h>
 #include <setjmp.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <errno.h>
 #include <signal.h>
 #include <sgtty.h>
 #include <setjmp.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/in.h>
 #include <netdb.h>
 #include <netdb.h>
+
 #define        TELOPTS
 #include "telnet.h"
 
 #define        ctrl(x)         ((x) & 037)
 #define        strip(x)        ((x)&0177)
 #define        TELOPTS
 #include "telnet.h"
 
 #define        ctrl(x)         ((x) & 037)
 #define        strip(x)        ((x)&0177)
-#define        INFINITY        10000000
 
 char   ttyobuf[BUFSIZ], *tfrontp = ttyobuf, *tbackp = ttyobuf;
 char   netobuf[BUFSIZ], *nfrontp = netobuf, *nbackp = netobuf;
 
 char   ttyobuf[BUFSIZ], *tfrontp = ttyobuf, *tbackp = ttyobuf;
 char   netobuf[BUFSIZ], *nfrontp = netobuf, *nbackp = netobuf;
@@ -144,9 +146,11 @@ tn(argc, argv)
        }
        host = gethostbyname(argv[1]);
        if (host) {
        }
        host = gethostbyname(argv[1]);
        if (host) {
-               bcopy(host->h_addr, &sin.sin_addr, host->h_length);
+               sin.sin_family = host->h_addrtype;
+               bcopy(host->h_addr, (caddr_t)&sin.sin_addr, host->h_length);
                hostname = host->h_name;
        } else {
                hostname = host->h_name;
        } else {
+               sin.sin_family = AF_INET;
                sin.sin_addr.s_addr = inet_addr(argv[1]);
                if (sin.sin_addr.s_addr == -1) {
                        printf("%s: unknown host\n", argv[1]);
                sin.sin_addr.s_addr = inet_addr(argv[1]);
                if (sin.sin_addr.s_addr == -1) {
                        printf("%s: unknown host\n", argv[1]);
@@ -164,15 +168,16 @@ tn(argc, argv)
                }
        }
        sin.sin_port = htons(sin.sin_port);
                }
        }
        sin.sin_port = htons(sin.sin_port);
-       if ((net = socket(SOCK_STREAM, 0, 0, options)) < 0) {
-               perror("socket");
+       net = socket(0, SOCK_STREAM, 0, 0);
+       if (net < 0) {
+               perror("telnet: socket");
                return;
        }
        sigset(SIGINT, intr);
        sigset(SIGPIPE, deadpeer);
        printf("Trying...\n");
                return;
        }
        sigset(SIGINT, intr);
        sigset(SIGPIPE, deadpeer);
        printf("Trying...\n");
-       if (connect(net, &sin)) {
-               perror("connect");
+       if (connect(net, (caddr_t)&sin, sizeof (sin), 0) < 0) {
+               perror("telnet: connect");
                sigset(SIGINT, SIG_DFL);
                return;
        }
                sigset(SIGINT, SIG_DFL);
                return;
        }
@@ -241,7 +246,9 @@ bye()
 
        (void) mode(0);
        if (connected) {
 
        (void) mode(0);
        if (connected) {
+#ifndef notdef
                ioctl(net, SIOCDONE, &how);
                ioctl(net, SIOCDONE, &how);
+#endif
                printf("Connection closed.\n");
                close(net);
                connected = 0;
                printf("Connection closed.\n");
                close(net);
                connected = 0;
@@ -332,6 +339,7 @@ mode(f)
                else
                        stbuf.sg_flags |= ECHO;
                tchars.t_intrc = tchars.t_quitc = -1;
                else
                        stbuf.sg_flags |= ECHO;
                tchars.t_intrc = tchars.t_quitc = -1;
+               tchars.t_stopc = tchars.t_startc = -1;
                disc = OTTYDISC;
                onoff = 1;
        }
                disc = OTTYDISC;
                onoff = 1;
        }
@@ -372,7 +380,7 @@ telnet(s)
                        ibits |= (1 << s);
                if (scc < 0 && tcc < 0)
                        break;
                        ibits |= (1 << s);
                if (scc < 0 && tcc < 0)
                        break;
-               select(32, &ibits, &obits, INFINITY);
+               select(16, &ibits, &obits, 0, 0);
                if (ibits == 0 && obits == 0) {
                        sleep(5);
                        continue;
                if (ibits == 0 && obits == 0) {
                        sleep(5);
                        continue;
index 701792b..eb3e1c4 100644 (file)
@@ -1,11 +1,13 @@
-/*     main.c  4.2     82/10/08        */
+/*     main.c  4.3     82/11/14        */
 
 /*
  * TFTP User Program -- Command Interface.
  */
 #include <sys/types.h>
 
 /*
  * TFTP User Program -- Command Interface.
  */
 #include <sys/types.h>
-#include <net/in.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
+
+#include <netinet/in.h>
+
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
@@ -13,9 +15,8 @@
 #include <ctype.h>
 #include <netdb.h>
 
 #include <ctype.h>
 #include <netdb.h>
 
-struct sockaddr_in sin = { AF_INET };
+struct sockaddr_in sin;
 int    f;
 int    f;
-int    options;
 int    trace;
 int    verbose;
 int    connected;
 int    trace;
 int    verbose;
 int    connected;
@@ -75,12 +76,7 @@ main(argc, argv)
                fprintf(stderr, "tftp: udp/tftp: unknown service\n");
                exit(1);
        }
                fprintf(stderr, "tftp: udp/tftp: unknown service\n");
                exit(1);
        }
-       sin.sin_port = htons(sp->s_port);
-       if (argc > 1 && !strcmp(argv[1], "-d")) {
-               options |= SO_DEBUG;
-               argc--, argv++;
-       }
-       f = socket(SOCK_DGRAM, 0, 0, options);
+       f = socket(0, SOCK_DGRAM, 0, 0);
        if (f < 0) {
                perror("socket");
                exit(3);
        if (f < 0) {
                perror("socket");
                exit(3);
@@ -120,9 +116,11 @@ setpeer(argc, argv)
        }
        host = gethostbyname(argv[1]);
        if (host) {
        }
        host = gethostbyname(argv[1]);
        if (host) {
+               sin.sin_family = host->h_addrtype;
                bcopy(host->h_addr, &sin.sin_addr, host->h_length);
                hostname = host->h_name;
        } else {
                bcopy(host->h_addr, &sin.sin_addr, host->h_length);
                hostname = host->h_name;
        } else {
+               sin.sin_family = AF_INET;
                sin.sin_addr.s_addr = inet_addr(argv[1]);
                if (sin.sin_addr.s_addr == -1) {
                        connected = 0;
                sin.sin_addr.s_addr = inet_addr(argv[1]);
                if (sin.sin_addr.s_addr == -1) {
                        connected = 0;
@@ -141,9 +139,7 @@ setpeer(argc, argv)
                        return;
                }
        }
                        return;
                }
        }
-#if vax || pdp11
-       sin.sin_port = htons(sin.sin_port);
-#endif
+       sin.sin_port = htons((u_short)sin.sin_port);
        connected = 1;
 }
 
        connected = 1;
 }
 
@@ -228,7 +224,7 @@ put(argc, argv)
                        printf("%s: Unknown host.\n", cp);
                        return;
                }
                        printf("%s: Unknown host.\n", cp);
                        return;
                }
-               bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
+               bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
                sin.sin_family = hp->h_addrtype;
                connected = 1;
                hostname = hp->h_name;
                sin.sin_family = hp->h_addrtype;
                connected = 1;
                hostname = hp->h_name;
@@ -311,7 +307,7 @@ get(argc, argv)
                                printf("%s: Unknown host.\n", argv[n]);
                                continue;
                        }
                                printf("%s: Unknown host.\n", argv[n]);
                                continue;
                        }
-                       bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
+                       bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
                        sin.sin_family = hp->h_addrtype;
                        connected = 1;
                        hostname = hp->h_name;
                        sin.sin_family = hp->h_addrtype;
                        connected = 1;
                        hostname = hp->h_name;
@@ -474,7 +470,6 @@ quit()
 
 /*
  * Help command.
 
 /*
  * Help command.
- * Call each command handler with argc == 0 and argv[0] == name.
  */
 help(argc, argv)
        int argc;
  */
 help(argc, argv)
        int argc;
index cc3584b..4fe9c10 100644 (file)
@@ -1,15 +1,18 @@
-/*     tftp.c  4.2     82/08/17        */
+/*     tftp.c  4.3     82/11/14        */
 
 /*
  * TFTP User Program -- Protocol Machines
  */
 #include <sys/types.h>
 
 /*
  * TFTP User Program -- Protocol Machines
  */
 #include <sys/types.h>
-#include <net/in.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
+
+#include <netinet/in.h>
+
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
 #include <setjmp.h>
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
 #include <setjmp.h>
+
 #include "tftp.h"
 
 extern int errno;
 #include "tftp.h"
 
 extern int errno;
@@ -44,6 +47,7 @@ sendfile(fd, name)
        register int block = 0, size, n, amount = 0;
        struct sockaddr_in from;
        time_t start = time(0), delta;
        register int block = 0, size, n, amount = 0;
        struct sockaddr_in from;
        time_t start = time(0), delta;
+       int fromlen;
 
        size = makerequest(WRQ, name) - 4;
        timeout = 0;
 
        size = makerequest(WRQ, name) - 4;
        timeout = 0;
@@ -63,12 +67,14 @@ sendfile(fd, name)
 rexmt:
                if (trace)
                        tpacket("sent", tp, size + 4);
 rexmt:
                if (trace)
                        tpacket("sent", tp, size + 4);
-               if (send(f, &sin, buf, size + 4) != size + 4) {
+               n = sendto(f, buf, size + 4, (caddr_t)&sin, sizeof (sin), 0);
+               if (n != size + 4) {
                        perror("send");
                        break;
                }
 again:
                        perror("send");
                        break;
                }
 again:
-               n = receive(f, &from, buf, sizeof (buf));
+               fromlen = sizeof (from);
+               n = recvfrom(f, buf, sizeof (buf), (caddr_t)&from, &fromlen, 0);
                if (n <= 0) {
                        if (n == 0)
                                goto again;
                if (n <= 0) {
                        if (n == 0)
                                goto again;
@@ -81,6 +87,7 @@ again:
                alarm(0);
                if (trace)
                        tpacket("received", tp, n);
                alarm(0);
                if (trace)
                        tpacket("received", tp, n);
+               /* should verify packet came from server */
 #if vax || pdp11
                tp->th_opcode = ntohs(tp->th_opcode);
                tp->th_block = ntohs(tp->th_block);
 #if vax || pdp11
                tp->th_opcode = ntohs(tp->th_opcode);
                tp->th_block = ntohs(tp->th_block);
@@ -115,6 +122,7 @@ recvfile(fd, name)
        register int block = 1, n, size, amount = 0;
        struct sockaddr_in from;
        time_t start = time(0), delta;
        register int block = 1, n, size, amount = 0;
        struct sockaddr_in from;
        time_t start = time(0), delta;
+       int fromlen;
 
        size = makerequest(RRQ, name);
        timeout = 0;
 
        size = makerequest(RRQ, name);
        timeout = 0;
@@ -131,12 +139,12 @@ recvfile(fd, name)
 rexmt:
                if (trace)
                        tpacket("sent", tp, size);
 rexmt:
                if (trace)
                        tpacket("sent", tp, size);
-               if (send(f, &sin, buf, size) != size) {
+               if (sendto(f, buf, size, (caddr_t)&sin, sizeof (sin), 0) != size) {
                        perror("send");
                        break;
                }
 again:
                        perror("send");
                        break;
                }
 again:
-               n = receive(f, &from, buf, sizeof (buf));
+               n = recvfrom(f, buf, sizeof (buf), (caddr_t)&from, &fromlen, 0);
                if (n <= 0) {
                        if (n == 0)
                                goto again;
                if (n <= 0) {
                        if (n == 0)
                                goto again;
@@ -149,6 +157,7 @@ again:
                alarm(0);
                if (trace)
                        tpacket("received", tp, n);
                alarm(0);
                if (trace)
                        tpacket("received", tp, n);
+               /* should verify client address */
 #if vax || pdp11
                tp->th_opcode = ntohs(tp->th_opcode);
                tp->th_block = ntohs(tp->th_block);
 #if vax || pdp11
                tp->th_opcode = ntohs(tp->th_opcode);
                tp->th_block = ntohs(tp->th_block);
@@ -170,7 +179,7 @@ again:
        alarm(0);
        tp->th_opcode = htons((u_short)ACK);
        tp->th_block = htons((u_short)block);
        alarm(0);
        tp->th_opcode = htons((u_short)ACK);
        tp->th_block = htons((u_short)block);
-       (void) send(f, &sin, buf, 4);
+       (void) sendto(f, buf, 4, &sin, sizeof (sin), 0);
        (void) close(fd);
        if (amount > 0) {
                delta = time(0) - start;
        (void) close(fd);
        if (amount > 0) {
                delta = time(0) - start;
index 0e5f3f8..56d12ca 100644 (file)
@@ -1,21 +1,24 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rwhod.c    4.4 82/10/10";
+static char sccsid[] = "@(#)rwhod.c    4.5 82/11/14";
 #endif
 
 #endif
 
-#include <stdio.h>
-#include <signal.h>
 #include <sys/types.h>
 #include <sys/types.h>
-#include <net/in.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
-#include <errno.h>
-#include <utmp.h>
-#include "rwhod.h"
 #include <sys/stat.h>
 #include <sys/stat.h>
-#include <nlist.h>
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
+
+#include <netinet/in.h>
+
+#include <nlist.h>
+#include <stdio.h>
+#include <signal.h>
+#include <errno.h>
+#include <utmp.h>
 #include <ctype.h>
 #include <netdb.h>
 
 #include <ctype.h>
 #include <netdb.h>
 
+#include "rwhod.h"
+
 struct sockaddr_in sin = { AF_INET };
 
 extern errno;
 struct sockaddr_in sin = { AF_INET };
 
 extern errno;
@@ -26,8 +29,8 @@ char  *myname = "myname";
 struct nlist nl[] = {
 #define        NL_AVENRUN      0
        { "_avenrun" },
 struct nlist nl[] = {
 #define        NL_AVENRUN      0
        { "_avenrun" },
-#define        NL_BOOTIME      1
-       { "_bootime" },
+#define        NL_BOOTTIME     1
+       { "_boottime" },
        0
 };
 
        0
 };
 
@@ -51,10 +54,7 @@ main()
                fprintf(stderr, "rwhod: udp/who: unknown service\n");
                exit(1);
        }
                fprintf(stderr, "rwhod: udp/who: unknown service\n");
                exit(1);
        }
-#if vax || pdp11
        sp->s_port = htons(sp->s_port);
        sp->s_port = htons(sp->s_port);
-#endif
-       sin.sin_port = sp->s_port;
 #ifndef DEBUG
        if (fork())
                exit(0);
 #ifndef DEBUG
        if (fork())
                exit(0);
@@ -97,23 +97,26 @@ main()
                perror("rwhod: /etc/utmp");
                exit(1);
        }
                perror("rwhod: /etc/utmp");
                exit(1);
        }
+       sin.sin_port = sp->s_port;
        getkmem();
        getkmem();
-again:
-       if ((s = socket(SOCK_DGRAM, 0, &sin, 0)) < 0) {
+       if ((s = socket(0, SOCK_DGRAM, 0, 0)) < 0) {
                perror("rwhod: socket");
                perror("rwhod: socket");
-               sleep(5);
-               goto again;
+               exit(1);
+       }
+       if (bind(s, &sin, sizeof (sin), 0) < 0) {
+               perror("rwhod: bind");
+               exit(1);
        }
        sigset(SIGALRM, onalrm);
        onalrm();
        for (;;) {
                struct whod wd;
        }
        sigset(SIGALRM, onalrm);
        onalrm();
        for (;;) {
                struct whod wd;
-               int cc, whod;
+               int cc, whod, len=sizeof (from);
 
 
-               cc = receive(s, &from, (char *)&wd, sizeof (struct whod));
+               cc = recvfrom(s, (char *)&wd, sizeof (struct whod), 0, &from, &len);
                if (cc <= 0) {
                        if (cc < 0 && errno != EINTR)
                if (cc <= 0) {
                        if (cc < 0 && errno != EINTR)
-                               perror("rwhod: receive");
+                               perror("rwhod: recv");
                        continue;
                }
                if (from.sin_port != sp->s_port) {
                        continue;
                }
                if (from.sin_port != sp->s_port) {
@@ -212,7 +215,7 @@ onalrm()
                mywd.wd_loadav[i] = avenrun[i] * 100;
        cc = (char *)we - (char *)&mywd;
        (void) time(&mywd.wd_sendtime);
                mywd.wd_loadav[i] = avenrun[i] * 100;
        cc = (char *)we - (char *)&mywd;
        (void) time(&mywd.wd_sendtime);
-       send(s, &sin, (char *)&mywd, cc);
+       (void) sendto(s, (char *)&mywd, cc, 0, &sin, sizeof (sin));
        (void) alarm(60);
 }
 
        (void) alarm(60);
 }
 
@@ -240,6 +243,6 @@ loop:
                sleep(300);
                goto loop;
        }
                sleep(300);
                goto loop;
        }
-       (void) lseek(kmemf, (long)nl[NL_BOOTIME].n_value, 0);
-       (void) read(kmemf, (char *)&mywd.wd_bootime, sizeof (mywd.wd_bootime));
+       (void) lseek(kmemf, (long)nl[NL_BOOTTIME].n_value, 0);
+       (void) read(kmemf, (char *)&mywd.wd_boottime, sizeof (mywd.wd_boottime));
 }
 }