int main(int argc, char **argv) { pid_t pid; int fds[2]; int kidret; int ret; if (argc != 2) { fprintf(stderr, "Usage: unit hostservice\n"); exit(1); } ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, fds); if (ret == -1) { perror("socketpair"); exit(1); } pid = fork(); switch (pid) { case 0: close(fds[0]); ret = runserver(fds[1]); fprintf(stderr, "Child exiting.\n"); exit(ret); case -1: perror("fork"); exit(1); default: close(fds[1]); ret = runclient(fds[0], argv[1]); break; } if (wait(&kidret) == -1) { perror("wait"); kidret = 1; } if (ret) fprintf(stderr, "Parent failed.\n"); if (kidret) fprintf(stderr, "Child failed.\n"); fprintf(stderr, "Parent exiting.\n"); if (ret || kidret) return 1; return 0; }
/* * Scan client list for guys that need to retransmit. */ void runtimer( ) { Client *cl, *cln; cl = clientlist; while( cl != NULL ) { cln = cl->next; cl->tp = NULL; cl->tpcc = 0; if (cl->wakeup != 0 && cl->wakeup <= now) { runclient( cl ); } else if (cl->wakeup == 0) { cl->wakeup = now; } cl = cln; } }
/* Process an incoming tftp packet */ void process( struct sockaddr_in *fromp, struct tftphdr *tp, int cc ) { Client *cl; /* Look for old session */ cl = findclient( fromp ); if (cl == NULL) { cl = newclient(); if (cl == NULL) return; cl->sin = *fromp; cl->dynam = 0; cl->proc = CP_TFTP; /* log(LOG_DEBUG, "%s.%d starting", cl->s_ipaddr, cl->sin.sin_port); */ } cl->tp = tp; cl->tpcc = cc; /* Start up this client */ runclient( cl ); }