X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/9bc1815c561f8518c48bb62c19e9846d5a34bb25..de3b21e8101dd8d6b168acb6fa8e09e48292a2e9:/usr/src/libexec/tftpd/tftpd.c diff --git a/usr/src/libexec/tftpd/tftpd.c b/usr/src/libexec/tftpd/tftpd.c index edb2cef484..42fd238872 100644 --- a/usr/src/libexec/tftpd/tftpd.c +++ b/usr/src/libexec/tftpd/tftpd.c @@ -1,24 +1,27 @@ -/* tftpd.c 4.2 82/08/19 */ +/* 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, IPPORT_TFTP }; +struct sockaddr_in sin = { AF_INET }; int f; -int options; char buf[BUFSIZ]; main(argc, argv) @@ -28,7 +31,14 @@ main(argc, argv) struct sockaddr_in from; register struct tftphdr *tp; register int n; + struct servent *sp; + sp = getservbyname("tftp", "udp"); + if (sp == 0) { + fprintf(stderr, "tftpd: udp/tftp: unknown service\n"); + exit(1); + } + sin.sin_port = htons((u_short)sp->s_port); #ifndef DEBUG if (fork()) exit(0); @@ -44,39 +54,37 @@ main(argc, argv) } } #endif -#if vax || pdp11 - sin.sin_port = htons(sin.sin_port); -#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; } } @@ -113,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); } @@ -236,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; @@ -283,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;