int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 1; //Default test result set to FAILED SVCXPRT *svcr = NULL; int fd = 0; //create a server svcr = svcfd_create(fd, 1024, 1024); //call routine xprt_register(svcr); //If we are here, xprt_register returned : test has passed test_status = 0; //clean up svc_destroy(svcr); //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 1; //Default test result set to FAILED int fd = 0; SVCXPRT *svcr = NULL; //create a server svcr = svcfd_create(fd, 0, 0); //check returned value test_status = ((SVCXPRT *) svcr != NULL) ? 0 : 1; //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 0; //Default test result set to PASS int progNum = atoi(argc[2]); int i; params paramList[NBCASE]; int fd; SVCXPRT *svcr = NULL; //Test initialization paramList[0].bufsnd = 1; paramList[0].bufrec = 0; paramList[1].bufsnd = 0; paramList[1].bufrec = 1; paramList[2].bufsnd = 0; paramList[2].bufrec = 2147483647; paramList[3].bufsnd = 2147483647; paramList[3].bufrec = 0; //Call tested function using all tests cases for (i = 0; i < NBCASE; i++) { //Debug mode prints if (run_mode == 1) { printf("Test using values : %d ", paramList[i].bufsnd); printf("%d", paramList[i].bufrec); printf("\n"); } //Call function svcr = svcfd_create(fd, paramList[i].bufsnd, paramList[i].bufrec); //Check result if (svcr == NULL) { //test has failed test_status = 1; break; } } //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // argc[3] : Number of testes function calls // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 1; //Default test result set to FAILED int fd; SVCXPRT *svcr = NULL; int nbCall = atoi(argc[3]); int nbOk = 0; int i; //First of all, create a server for (i = 0; i < nbCall; i++) { svcr = svcfd_create(fd, 0, 0); //Then call destroy macro svc_destroy(svcr); nbOk++; } //If we are here, macro call was successful if (run_mode == 1) { printf("Aimed : %d\n", nbCall); printf("Got : %d\n", nbOk); } test_status = (nbOk == nbCall) ? 0 : 1; //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
/** * Closes the socket on failure. * * @param[in] up7 The upstream LDM-7 to be initialized. * @param[in] sock The socket for the upstream LDM-7. * @param[in] termFd Termination file-descriptor. * @retval 0 Success. */ static int up7_init( Up7* const up7, const int sock) { /* * 0 => use default read/write buffer sizes. * `sock` will be closed by `svc_destroy()`. */ SVCXPRT* const xprt = svcfd_create(sock, 0, 0); CU_ASSERT_PTR_NOT_EQUAL_FATAL(xprt, NULL); /* * Set the remote address of the RPC server-side transport because * `svcfd_create()` doesn't. */ { struct sockaddr_in addr; socklen_t addrLen = sizeof(addr); int status = getpeername(sock, &addr, &addrLen); CU_ASSERT_EQUAL_FATAL(status, 0); CU_ASSERT_EQUAL_FATAL(addrLen, sizeof(addr)); CU_ASSERT_EQUAL_FATAL(addr.sin_family, AF_INET); xprt->xp_raddr = addr; xprt->xp_addrlen = addrLen; } // Last argument == 0 => don't register with portmapper bool success = svc_register(xprt, LDMPROG, SEVEN, ldmprog_7, 0); CU_ASSERT_TRUE_FATAL(success); up7->xprt = xprt; return 0; }
/* * Handles an incoming RPC connection on a socket. This method will fork(2) * a copy of this program, if appropriate, for handling incoming RPC messages. * * sock The socket with the incoming RPC connection. */ static void handle_connection( int sock) { struct sockaddr_in raddr; socklen_t len; int xp_sock; pid_t pid; SVCXPRT *xprt; int status = 1; /* EXIT_FAILURE assumed unless one_svc_run() success */ peer_info* remote = get_remote(); again: len = sizeof(raddr); (void) memset(&raddr, 0, len); xp_sock = accept(sock, (struct sockaddr *) &raddr, &len); (void) exitIfDone(0); if (xp_sock < 0) { if (errno == EINTR) { errno = 0; goto again; } /* else */ serror("accept"); return; } /* * Don't bother continuing if no more clients are allowed. */ if (cps_count() >= maxClients) { setremote(&raddr, xp_sock); unotice("Denying connection from [%s] because too many clients", remote->astr); (void) close(xp_sock); return; } pid = ldmfork(); if (pid == -1) { log_add("Couldn't fork process to handle incoming connection"); log_log(LOG_ERR); /* TODO: try again?*/ (void) close(xp_sock); return; } if (pid > 0) { /* parent */ /* unotice("child %d", pid); */ (void) close(xp_sock); if (cps_add(pid)) serror("Couldn't add child PID to set"); return; } /* else child */ setremote(&raddr, xp_sock); /* Access control */ if (!lcf_isHostOk(remote)) { ensureRemoteName(&raddr); if (!lcf_isHostOk(remote)) { if (remote->printname == remote->astr) { unotice("Denying connection from [%s] because not " "allowed", remote->astr); } else { unotice("Denying connection from \"%s\" because not " "allowed", remote_name()); } /* * Try to tell the other guy. * TODO: Why doesn't this work? */ xprt = svcfd_create(xp_sock, remote->sendsz, remote->recvsz); if (xprt != NULL ) { xprt->xp_raddr = raddr; xprt->xp_addrlen = (int) len; svcerr_weakauth(xprt); svc_destroy(xprt); } goto unwind_sock; } } /* else */ endpriv(); portIsMapped = 0; /* don't call pmap_unset() from child */ (void) close(sock); /* Set the ulog identifier, optional. */ set_abbr_ident(remote_name(), NULL ); uinfo("Connection from %s", remote_name()); xprt = svcfd_create(xp_sock, remote->sendsz, remote->recvsz); if (xprt == NULL ) { uerror("Can't create fd service."); goto unwind_sock; } /* hook up the remote address to the xprt. */ /* xprt->xp_raddr = raddr; */ xprt->xp_raddr = raddr; xprt->xp_addrlen = (int) len; if (!svc_register(xprt, LDMPROG, 4, ldmprog_4, 0)) { uerror("unable to register LDM-4 service."); svc_destroy(xprt); goto unwind_sock; } if (!svc_register(xprt, LDMPROG, FIVE, ldmprog_5, 0)) { uerror("unable to register LDM-5 service."); svc_destroy(xprt); goto unwind_sock; } if (!svc_register(xprt, LDMPROG, SIX, ldmprog_6, 0)) { uerror("unable to register LDM-6 service."); svc_destroy(xprt); goto unwind_sock; } #if WANT_MULTICAST if (!svc_register(xprt, LDMPROG, SEVEN, ldmprog_7, 0)) { uerror("unable to register LDM-7 service."); svc_destroy(xprt); goto unwind_sock; } #endif /* * handle rpc requests */ { const unsigned TIMEOUT = 2*interval; status = one_svc_run(xp_sock, TIMEOUT); (void) exitIfDone(0); if (status == 0) { log_add("Done"); log_log(LOG_INFO); } else if (status == ETIMEDOUT) { log_add("Connection from client LDM silent for %u seconds", TIMEOUT); log_log(LOG_NOTICE); } else { /* connection to client lost */ log_add("Connection with client LDM closed"); log_log(LOG_INFO); status = 0; /* EXIT_SUCCESS */ } } /* svc_destroy(xprt); done by svc_getreqset() */ unwind_sock: (void) close(xp_sock); exit(status); }
int main( int argc, char* argv[] ) { SVCXPRT *transp = NULL; int sock; int proto = 0; struct sockaddr_in saddr; int asize = sizeof (saddr); if (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) { int ssize = sizeof (int); if (saddr.sin_family != AF_INET) exit(1); if (getsockopt(0, SOL_SOCKET, SO_TYPE, (char *)&_rpcfdtype, &ssize) == -1) exit(1); sock = 0; _rpcpmstart = 1; proto = 0; openlog("Smoking", LOG_PID, LOG_DAEMON); } else { #ifndef RPC_SVC_FG int size; int pid, i; pid = fork(); if (pid < 0) { perror("cannot fork"); exit(1); } if (pid) exit(0); size = getdtablesize(); for (i = 0; i < size; i++) (void) close(i); i = open("/dev/console", 2); (void) dup2(i, 1); (void) dup2(i, 2); i = open("/dev/tty", 2); if (i >= 0) { (void) ioctl(i, TIOCNOTTY, (char *)NULL); (void) close(i); } openlog("Smoking", LOG_PID, LOG_DAEMON); #endif sock = RPC_ANYSOCK; (void) pmap_unset(SMOKE, SMOKERS); } if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) { transp = svcudp_create(sock); if (transp == NULL) { _msgout("cannot create udp service."); exit(1); } if (!_rpcpmstart) proto = IPPROTO_UDP; if (!svc_register(transp, SMOKE, SMOKERS, smoke_1, proto)) { _msgout("unable to register (SMOKE, SMOKERS, udp)."); exit(1); } } if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) { if (_rpcpmstart) transp = svcfd_create(sock, 0, 0); else transp = svctcp_create(sock, 0, 0); if (transp == NULL) { _msgout("cannot create tcp service."); exit(1); } if (!_rpcpmstart) proto = IPPROTO_TCP; if (!svc_register(transp, SMOKE, SMOKERS, smoke_1, proto)) { _msgout("unable to register (SMOKE, SMOKERS, tcp)."); exit(1); } } if (transp == (SVCXPRT *)NULL) { _msgout("could not create a handle"); exit(1); } if (_rpcpmstart) { (void) signal(SIGALRM, (SIG_PF) closedown); (void) alarm(_RPCSVC_CLOSEDOWN); } svc_run(); _msgout("svc_run returned"); exit(1); /* NOTREACHED */ }