Пример #1
0
int CCPppcontroller::Connect( string aRemoteHost )
{
	// check that we are not already connected
	if( cl != NULL ) {
		return ERR_STUB_ALREADY_CONNECTED;
	}

	// start the rpc library
	rpc_nt_init();

	// connect to the service
	cl = clnt_create( aRemoteHost.c_str(), PPPCONTROLLER, PPPCONTROLLER_VERSION, "tcp" );
	if( cl == NULL ) {
		rpc_nt_exit();
		return ERR_FAILED_TO_CONNECT;
	}

	// done
	return ERR_NONE;
}
Пример #2
0
main()
{
	SVCXPRT *xprt;
	int sock, pid, t;
	struct sockaddr_in addr;
	int len = sizeof(struct sockaddr_in);

#if 0
	if (!debug) {
		pid = daemon(0,0);	/* from libutil */
		if (pid < 0) {
			perror("portmap: fork");
			exit(1);
		}
	}

	openlog("portmap:", LOG_PID, LOG_DAEMON);
#endif

	if (rpc_nt_init() != 0) {
		fprintf(stderr, "cannot init WinSock\n");
		exit(1);
	}
	

	if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {
		fprintf(stderr, "cannot create socket\n");
		exit(1);
	}

	addr.sin_addr.s_addr = 0;
	addr.sin_family = AF_INET;
	addr.sin_port = htons(PMAPPORT);
	if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
		fprintf(stderr, "cannot bind\n");
		exit(1);
	}

	if ((xprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
		fprintf(stderr, "couldn't do udp_create\n");
		exit(1);
	}

	if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
		fprintf(stderr, "cannot create socket\n");
		exit(1);
	}
	if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
		fprintf(stderr, "cannot bind\n");
		exit(1);
	}
	if ((xprt = svctcp_create(sock, 0, 0)) == (SVCXPRT *)NULL) {
		fprintf(stderr, "couldn't do tcp_create\n");
		exit(1);
	}

        (void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
	svc_run();
	fprintf(stderr, "run_svc returned unexpectedly\n");

	rpc_nt_exit();

	abort();
}