rdate.c

来自「the source code from the book "UNIX Netw」· C语言 代码 · 共 60 行

C
60
字号
/* * rdate.c - client program for remote date service. */#include	<stdio.h>#include	<rpc/rpc.h>	/* standard RPC include file */#include	"date.h"	/* this file is generated by rpcgen */main(argc, argv)int	argc;char	*argv[];{	CLIENT		*cl;		/* RPC handle */	char		*server;	long		*lresult;	/* return value from bin_date_1() */	char		**sresult;	/* return value from str_date_1() */	if (argc != 2) {		fprintf(stderr, "usage: %s hostname\n", argv[0]);		exit(1);	}	server = argv[1];	/*	 * Create the client "handle."	 */	if ( (cl = clnt_create(server, DATE_PROG, DATE_VERS, "udp")) == NULL) {		/*		 * Couldn't establish connection with server.		 */		clnt_pcreateerror(server);		exit(2);	}	/*	 * First call the remote procedure "bin_date".	 */	if ( (lresult = bin_date_1(NULL, cl)) == NULL) {		clnt_perror(cl, server);		exit(3);	}	printf("time on host %s = %ld\n", server, *lresult);	/*	 * Now call the remote procedure "str_date".	 */	if ( (sresult = str_date_1(lresult, cl)) == NULL) {		clnt_perror(cl, server);		exit(4);	}	printf("time on host %s = %s", server, *sresult);	clnt_destroy(cl);		/* done with the handle */	exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?