-#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);
- if (f < 0) {
- perror("socket");
- sleep(5);
- continue;
- }
-again:
- n = receive(f, &from, buf, sizeof (buf));
- if (n <= 0) {
- if (n < 0)
- perror("receive");
- 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;
+ from.sin_family = AF_INET;
+ alarm(0);
+ close(0);
+ close(1);
+ peer = socket(AF_INET, SOCK_DGRAM, 0);
+ if (peer < 0) {
+ openlog("tftpd", LOG_PID, 0);
+ syslog(LOG_ERR, "socket: %m");
+ exit(1);