開放網路運算遠程過程調用是一種被廣泛套用的遠程過程調用(RPC)系統,是一種屬於套用層的協定堆疊,底層為TCP/IP協定。開放網路運算(ONC)最早源自於太陽微系統(Sun),是網路檔案系統計畫的一部分,因此它經常也被稱為Sun ONC 或 Sun RPC。現今在多數類UNIX系統上都實現了這套系統,微軟公司也以Windows Services for UNIX在他們產品上提供ONC RPC的支持。2009年,太陽微系統以標準三條款的BSD許可證發布這套系統。2010年,收購了太陽微系統的甲骨文公司確認了這套軟體BSD許可證的有效性與適用範圍。
基本介紹
- 中文名:開放網路運算遠程過程調用
- 外文名:Open Network Computing Remote Procedure Call
簡介
實例
#include <stdlib.h> #include <stdio.h> #include <rpc/rpc.h> #include <netconfig.h> #include "date.h" main(argc, argv) int argc; char **argv; { CLIENT *cl; /* rpc handle */ char *server; long *lresult; /* return from bin_date_1 */ char **sresult; /* return from str_date_1 */ if (argc != 2) { fprintf(stderr, "usage: %s hostnamen", argv[0]); exit(1); } server = argv[1]; /* get the name of the server */ /* create the client handle */ if ((cl=clnt_create(server, DATE_PROG, DATE_VERS, "netpath")) == NULL) { /* failed! */ clnt_pcreateerror(server); exit(1); } /* call the procedure bin_date */ if ((lresult=bin_date_1(NULL, cl))==NULL) { /* failed ! */ clnt_perror(cl, server); exit(1); } printf("time on %s is %ldn", server, *lresult); /* have the server convert the result to a date string */ if ((sresult=str_date_1(lresult, cl)) == NULL) { /* failed ! */ clnt_perror(cl, server); exit(1); } printf("date is %sn", *sresult); clnt_destroy(cl); /* get rid of the handle */ exit(0); }
#include <rpc/rpc.h> #include "date.h" /* bin_date_1 returns the system time in binary format */ long * bin_date_1() { static long timeval; /* must be static!! This value is */ /* used by rpc after bin_date_1 returns */ long time(); /* Unix time function; returns time */ timeval = time((long *)0); return &timeval; } /* str_date_1 converts a binary time into a date string */ char ** str_date_1(bintime) long *bintime; { static char *ptr; /* return value... MUST be static! */ char *ctime(); /* Unix library function that does the work */ ptr = ctime(bintime); return &ptr; }
/* date.x - description of remote date service */ /* we define two procedures: */ /* bin_date_1 returns the time in binary format */ /* (seconds since Jan 1, 1970 00:00:00 GMT) */ /* str_date_1 converts a binary time to a readable date string */ program DATE_PROG { version DATE_VERS { long BIN_DATE(void) = 1; /* procedure number = 1 */ string STR_DATE(long) = 2; /* procedure number = 2 */ } = 1; } = 0x31415926;
- date.h
- date_svc.c
- date_clnt.c
- date_xdr.c
- “netpath”
- “circuit_n”
- “visible”
- “circuit_v”
- “datagram_v”