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 sock = 600; SVCXPRT *svcr = NULL; //create a server // sock = socket(AF_UNIX, SOCK_SEQPACKET, IPPROTO_UDP); svcr = svcudp_bufcreate(sock, 1500, 1500); //check returned value test_status = ((SVCXPRT *) svcr != NULL) ? 0 : 1; //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; }
SVCXPRT * svcudp_create( int sock) { return(svcudp_bufcreate(sock, UDPMSGSIZE, UDPMSGSIZE)); }
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 sock = 600; 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; sock = socket(AF_UNIX, SOCK_DGRAM, IPPROTO_TCP); //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 = svcudp_bufcreate(sock, 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; }
/* * Create the amq service for amd (both TCP and UDP) */ int create_amq_service(int *udp_soAMQp, SVCXPRT **udp_amqpp, struct netconfig **dummy1, int *tcp_soAMQp, SVCXPRT **tcp_amqpp, struct netconfig **dummy2) { /* first create TCP service */ if (tcp_soAMQp) { *tcp_soAMQp = socket(AF_INET, SOCK_STREAM, 0); if (*tcp_soAMQp < 0) { plog(XLOG_FATAL, "cannot create tcp socket for amq service: %m"); return 1; } /* now create RPC service handle for amq */ if (tcp_amqpp && (*tcp_amqpp = svctcp_create(*tcp_soAMQp, AMQ_SIZE, AMQ_SIZE)) == NULL) { plog(XLOG_FATAL, "cannot create tcp service for amq: soAMQp=%d", *tcp_soAMQp); return 2; } } /* next create UDP service */ if (udp_soAMQp) { *udp_soAMQp = socket(AF_INET, SOCK_DGRAM, 0); if (*udp_soAMQp < 0) { plog(XLOG_FATAL, "cannot create udp socket for amq service: %m"); return 3; } /* now create RPC service handle for amq */ if (udp_amqpp && (*udp_amqpp = svcudp_bufcreate(*udp_soAMQp, AMQ_SIZE, AMQ_SIZE)) == NULL) { plog(XLOG_FATAL, "cannot create udp service for amq: soAMQp=%d", *udp_soAMQp); return 4; } } return 0; /* all is well */ }
/* * Create the amq service for amd (both TCP and UDP) */ int create_amq_service(int *udp_soAMQp, SVCXPRT **udp_amqpp, struct netconfig **dummy1, int *tcp_soAMQp, SVCXPRT **tcp_amqpp, struct netconfig **dummy2, u_short preferred_amq_port) { /* first create TCP service */ if (tcp_soAMQp) { *tcp_soAMQp = socket(AF_INET, SOCK_STREAM, 0); if (*tcp_soAMQp < 0) { plog(XLOG_FATAL, "cannot create tcp socket for amq service: %m"); return 1; } /* next, bind to a specific (TCP) port if asked for */ if (preferred_amq_port > 0) { /* * Note: if &preferred_amq_port is non-null and is greater than 0, * then the pointer will not be modified. We don't want it to be * modified because it was passed down to create_amq_service as a * non-pointer (a variable on the stack, not to be modified!) */ if (bind_resv_port(*tcp_soAMQp, &preferred_amq_port) < 0) { plog(XLOG_FATAL, "can't bind amq service to requested TCP port %d: %m)", preferred_amq_port); return 1; } } /* now create RPC service handle for amq */ if (tcp_amqpp && (*tcp_amqpp = svctcp_create(*tcp_soAMQp, AMQ_SIZE, AMQ_SIZE)) == NULL) { plog(XLOG_FATAL, "cannot create tcp service for amq: soAMQp=%d", *tcp_soAMQp); return 1; } #ifdef SVCSET_CONNMAXREC /* * This is *BSD at its best. * They just had to do things differently than everyone else * so they fixed a library DoS issue by forcing client-side changes... */ # ifndef RPC_MAXDATASIZE # define RPC_MAXDATASIZE 9000 # endif /* not RPC_MAXDATASIZE */ if (tcp_amqpp) { int maxrec = RPC_MAXDATASIZE; SVC_CONTROL(*tcp_amqpp, SVCSET_CONNMAXREC, &maxrec); } #endif /* not SVCSET_CONNMAXREC */ } /* next create UDP service */ if (udp_soAMQp) { *udp_soAMQp = socket(AF_INET, SOCK_DGRAM, 0); if (*udp_soAMQp < 0) { plog(XLOG_FATAL, "cannot create udp socket for amq service: %m"); return 1; } /* next, bind to a specific (UDP) port if asked for */ if (preferred_amq_port > 0) { /* * Note: see comment about using &preferred_amq_port above in this * function. */ if (bind_resv_port(*udp_soAMQp, &preferred_amq_port) < 0) { plog(XLOG_FATAL, "can't bind amq service to requested UDP port %d: %m)", preferred_amq_port); return 1; } } /* now create RPC service handle for amq */ if (udp_amqpp && (*udp_amqpp = svcudp_bufcreate(*udp_soAMQp, AMQ_SIZE, AMQ_SIZE)) == NULL) { plog(XLOG_FATAL, "cannot create udp service for amq: soAMQp=%d", *udp_soAMQp); return 1; } } return 0; /* all is well */ }
static int getprognum(long *prognum, SVCXPRT **xprt, char *fd_str, char *prog_str, long vers, char *tp_type) { static ulong_t start = 0x40000000; int fd; #ifdef TDRPC ushort_t port; int proto; #else struct netconfig *nc; struct netbuf *nb; #endif /* If prognum specified, use it instead of transient hassel. */ if (*prognum) { *xprt = NULL; sprintf(fd_str, "-1"); /* have child close all fds */ sprintf(prog_str, "%u", *prognum); return (TRUE); } /* * Transient hassel: * - parent must create mapping since someone else could * steal the transient prognum before child created it * - pass the child the fd to use for service * - close the fd (after exec), free xprt, leave mapping intact */ #ifdef TDRPC if (strcmp(tp_type, "udp") != 0) { proto = IPPROTO_UDP; *xprt = svcudp_bufcreate(RPC_ANYSOCK, 0, 0); } else { proto = IPPROTO_TCP; *xprt = svctcp_create(RPC_ANYSOCK, 0, 0); } if (*xprt == NULL) return (FALSE); port = (*xprt)->xp_port; fd = (*xprt)->xp_sock; while (!pmap_set(start, vers, proto, port)) start++; #else /* tp_type is legit: users choice or a loopback netid */ if ((nc = getnetconfigent(tp_type)) == NULL) return (FALSE); if ((*xprt = svc_tli_create(RPC_ANYFD, nc, NULL, 0, 0)) == NULL) { freenetconfigent(nc); return (FALSE); } nb = &(*xprt)->xp_ltaddr; fd = (*xprt)->xp_fd; while (!rpcb_set(start, vers, nc, nb)) start++; freenetconfigent(nc); #endif *prognum = start; sprintf(fd_str, "%u", fd); sprintf(prog_str, "%u", *prognum); return (TRUE); }