-#endif
- signal(SIGCHLD, reapchild);
- for (;;) {
- int fromlen;
-
- f = socket(AF_INET, SOCK_DGRAM, 0);
- if (f < 0) {
- perror("tftpd: socket");
- sleep(5);
- continue;
- }
- if (setsockopt(f, SOL_SOCKET, SO_REUSEADDR, 0, 0) < 0)
- perror("tftpd: setsockopt (SO_REUSEADDR)");
- sleep(1); /* let child do connect */
- while (bind(f, (caddr_t)&sin, sizeof (sin), 0) < 0) {
- perror("tftpd: bind");
- sleep(5);
- }
- do {
- fromlen = sizeof (from);
- n = recvfrom(f, buf, sizeof (buf), 0,
- (caddr_t)&from, &fromlen);
- } while (n <= 0);
- tp = (struct tftphdr *)buf;
- tp->th_opcode = ntohs(tp->th_opcode);
- if (tp->th_opcode == RRQ || tp->th_opcode == WRQ)
- if (fork() == 0)
- tftp(&from, tp, n);
- (void) close(f);
+ if (bind(peer, (caddr_t)&sin, sizeof (sin)) < 0) {
+ openlog("tftpd", LOG_PID, 0);
+ syslog(LOG_ERR, "bind: %m");
+ exit(1);