From: Sam Leffler Date: Mon, 15 Nov 1982 07:21:59 +0000 (-0800) Subject: convert to 4.1c sys calls and directory layout X-Git-Tag: BSD-4_1c_2-Snapshot-Development~1830 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/de3b21e8101dd8d6b168acb6fa8e09e48292a2e9 convert to 4.1c sys calls and directory layout 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 --- diff --git a/usr/src/include/protocols/rwhod.h b/usr/src/include/protocols/rwhod.h index 1c4b3da141..e178ef3dfd 100644 --- a/usr/src/include/protocols/rwhod.h +++ b/usr/src/include/protocols/rwhod.h @@ -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]; - int wd_bootime; + int wd_boottime; struct whoent { struct utmp we_utmp; int we_idle; diff --git a/usr/src/libexec/telnetd/telnetd.c b/usr/src/libexec/telnetd/telnetd.c index abc2ec14c6..d0afe5833e 100644 --- a/usr/src/libexec/telnetd/telnetd.c +++ b/usr/src/libexec/telnetd/telnetd.c @@ -1,22 +1,24 @@ #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. */ +#include +#include + +#include + #include #include #include #include #include -#include -#include -#include #include + #include "telnet.h" -#define INFINITY 10000000 #define BELL '\07' char hisopts[256]; @@ -42,7 +44,6 @@ extern int errno; char line[] = "/dev/ptyp0"; struct sockaddr_in sin = { AF_INET }; -int options = SO_ACCEPTCONN|SO_KEEPALIVE; main(argc, argv) char *argv[]; @@ -58,8 +59,6 @@ main(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) { @@ -67,7 +66,7 @@ main(argc, argv) exit(1); } } - sin.sin_port = htons(sin.sin_port); + sin.sin_port = htons((u_short)sin.sin_port); #ifndef DEBUG if (fork()) exit(0); @@ -83,24 +82,32 @@ main(argc, argv) } } #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 (;;) { - 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"); - close(s); 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; } @@ -202,7 +209,7 @@ telnet(f, p) 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; @@ -393,7 +400,7 @@ telrcv() continue; default: - printf("netser: panic state=%d\n", state); + printf("telnetd: panic state=%d\n", state); exit(1); } } @@ -560,7 +567,9 @@ cleanup() rmut(); vhangup(); +#ifndef notdef ioctl(net, SIOCDONE, &how); +#endif kill(0, SIGKILL); exit(1); } diff --git a/usr/src/libexec/tftpd/tftpd.c b/usr/src/libexec/tftpd/tftpd.c index 361282c473..42fd238872 100644 --- a/usr/src/libexec/tftpd/tftpd.c +++ b/usr/src/libexec/tftpd/tftpd.c @@ -1,25 +1,27 @@ -/* tftpd.c 4.3 82/10/08 */ +/* tftpd.c 4.4 82/11/14 */ /* * Trivial file transfer protocol server. */ #include -#include #include -#include #include + +#include + +#include #include #include #include #include #include #include + #include "tftp.h" extern int errno; struct sockaddr_in sin = { AF_INET }; int f; -int options; char buf[BUFSIZ]; main(argc, argv) @@ -36,7 +38,7 @@ main(argc, argv) 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); @@ -52,36 +54,37 @@ main(argc, argv) } } #endif - argc--, argv++; - if (argc > 0 && !strcmp(argv[0], "-d")) - options |= SO_DEBUG; for (;;) { - errno = 0; - f = socket(SOCK_DGRAM, 0, &sin, options); + int fromlen; + + f = socket(0, SOCK_DGRAM, 0, 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: - 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) - perror("receive"); + perror("tftpd: recvfrom"); goto again; } tp = (struct tftphdr *)buf; -#if vax || pdp11 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); -#ifdef notdef while (wait3(status, WNOHANG, 0) > 0) -#else - while (wait3(status, 0, 0) > 0) continue; } } @@ -118,7 +121,7 @@ tftp(client, tp, size) 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); } @@ -241,8 +244,8 @@ again: } 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; @@ -288,8 +291,8 @@ again: } 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; diff --git a/usr/src/usr.bin/ruptime/ruptime.c b/usr/src/usr.bin/ruptime/ruptime.c index d54ab41580..20e11b639a 100644 --- a/usr/src/usr.bin/ruptime/ruptime.c +++ b/usr/src/usr.bin/ruptime/ruptime.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)ruptime.c 4.5 82/10/07"; +static char sccsid[] = "@(#)ruptime.c 4.6 82/11/14"; #endif #include @@ -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 - - hsp->hs_wd->wd_bootime, " up"), + hsp->hs_wd->wd_boottime, " up"), 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 - : 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 - : h1->hs_wd->wd_sendtime - h1->hs_wd->wd_bootime) + : h1->hs_wd->wd_sendtime - h1->hs_wd->wd_boottime) ); } diff --git a/usr/src/usr.bin/telnet/telnet.c b/usr/src/usr.bin/telnet/telnet.c index c03247e1b4..a157be0003 100644 --- a/usr/src/usr.bin/telnet/telnet.c +++ b/usr/src/usr.bin/telnet/telnet.c @@ -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. */ +#include +#include + +#include + #include #include #include #include #include #include -#include -#include -#include #include + #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; @@ -144,9 +146,11 @@ tn(argc, argv) } 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 { + 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]); @@ -164,15 +168,16 @@ tn(argc, argv) } } 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"); - if (connect(net, &sin)) { - perror("connect"); + if (connect(net, (caddr_t)&sin, sizeof (sin), 0) < 0) { + perror("telnet: connect"); sigset(SIGINT, SIG_DFL); return; } @@ -241,7 +246,9 @@ bye() (void) mode(0); if (connected) { +#ifndef notdef ioctl(net, SIOCDONE, &how); +#endif 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; + tchars.t_stopc = tchars.t_startc = -1; disc = OTTYDISC; onoff = 1; } @@ -372,7 +380,7 @@ telnet(s) 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; diff --git a/usr/src/usr.bin/tftp/main.c b/usr/src/usr.bin/tftp/main.c index 701792bd87..eb3e1c4fd4 100644 --- a/usr/src/usr.bin/tftp/main.c +++ b/usr/src/usr.bin/tftp/main.c @@ -1,11 +1,13 @@ -/* main.c 4.2 82/10/08 */ +/* main.c 4.3 82/11/14 */ /* * TFTP User Program -- Command Interface. */ #include -#include #include + +#include + #include #include #include @@ -13,9 +15,8 @@ #include #include -struct sockaddr_in sin = { AF_INET }; +struct sockaddr_in sin; int f; -int options; int trace; int verbose; int connected; @@ -75,12 +76,7 @@ main(argc, argv) 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); @@ -120,9 +116,11 @@ setpeer(argc, argv) } 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 { + sin.sin_family = AF_INET; 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; } } -#if vax || pdp11 - sin.sin_port = htons(sin.sin_port); -#endif + sin.sin_port = htons((u_short)sin.sin_port); connected = 1; } @@ -228,7 +224,7 @@ put(argc, argv) 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; @@ -311,7 +307,7 @@ get(argc, argv) 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; @@ -474,7 +470,6 @@ quit() /* * Help command. - * Call each command handler with argc == 0 and argv[0] == name. */ help(argc, argv) int argc; diff --git a/usr/src/usr.bin/tftp/tftp.c b/usr/src/usr.bin/tftp/tftp.c index cc3584b500..4fe9c10c20 100644 --- a/usr/src/usr.bin/tftp/tftp.c +++ b/usr/src/usr.bin/tftp/tftp.c @@ -1,15 +1,18 @@ -/* tftp.c 4.2 82/08/17 */ +/* tftp.c 4.3 82/11/14 */ /* * TFTP User Program -- Protocol Machines */ #include -#include #include + +#include + #include #include #include #include + #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; + int fromlen; size = makerequest(WRQ, name) - 4; timeout = 0; @@ -63,12 +67,14 @@ sendfile(fd, name) 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: - 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; @@ -81,6 +87,7 @@ again: 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); @@ -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; + int fromlen; size = makerequest(RRQ, name); timeout = 0; @@ -131,12 +139,12 @@ recvfile(fd, name) 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: - 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; @@ -149,6 +157,7 @@ again: 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); @@ -170,7 +179,7 @@ again: 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; diff --git a/usr/src/usr.sbin/rwhod/rwhod.c b/usr/src/usr.sbin/rwhod/rwhod.c index 0e5f3f8dbf..56d12ca6f3 100644 --- a/usr/src/usr.sbin/rwhod/rwhod.c +++ b/usr/src/usr.sbin/rwhod/rwhod.c @@ -1,21 +1,24 @@ #ifndef lint -static char sccsid[] = "@(#)rwhod.c 4.4 82/10/10"; +static char sccsid[] = "@(#)rwhod.c 4.5 82/11/14"; #endif -#include -#include #include -#include #include -#include -#include -#include "rwhod.h" #include -#include #include + +#include + +#include +#include +#include +#include +#include #include #include +#include "rwhod.h" + struct sockaddr_in sin = { AF_INET }; extern errno; @@ -26,8 +29,8 @@ char *myname = "myname"; struct nlist nl[] = { #define NL_AVENRUN 0 { "_avenrun" }, -#define NL_BOOTIME 1 - { "_bootime" }, +#define NL_BOOTTIME 1 + { "_boottime" }, 0 }; @@ -51,10 +54,7 @@ main() fprintf(stderr, "rwhod: udp/who: unknown service\n"); exit(1); } -#if vax || pdp11 sp->s_port = htons(sp->s_port); -#endif - sin.sin_port = sp->s_port; #ifndef DEBUG if (fork()) exit(0); @@ -97,23 +97,26 @@ main() perror("rwhod: /etc/utmp"); exit(1); } + sin.sin_port = sp->s_port; getkmem(); -again: - if ((s = socket(SOCK_DGRAM, 0, &sin, 0)) < 0) { + if ((s = socket(0, SOCK_DGRAM, 0, 0)) < 0) { 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; - 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) - perror("rwhod: receive"); + perror("rwhod: recv"); 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); - send(s, &sin, (char *)&mywd, cc); + (void) sendto(s, (char *)&mywd, cc, 0, &sin, sizeof (sin)); (void) alarm(60); } @@ -240,6 +243,6 @@ 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)); }