Those who do not understand Unix are condemned to reinvent it, poorly.
不懂Unix 的人注定最终还要重复发明一个蹩脚的Unix 。
Usenet 签名, 1987 年11 月 ——Henry Spencer
1. 如何使用rpc?
先要安装rpcbind库(可能需要portmap支持)
apt-get install rpcbind
2. 查看rpcbind中注册的服务
使用rpcinfo命令, 可以使用man rpcinfo查看参数用法,默认如下或者带上参数-p,都是本地host的信息.
3. rpcgen的简单讲解及例子程序
3.1 创建规格文件(test.x)
/* filename: test.x */
const ADD = 0;
const SUB = 1;
const MUL = 2;
const DIV = 3;
struct TEST
{
int op; /* 0-ADD, 1-SUB, 2-MUL, 3-DIV */
float arg1;
float arg2;
float result;
};
program TEST_PROG
{
version TEST_VER
{
struct TEST TEST_PROC(struct TEST) = 1;
} = 2;
} = 0x20000001;
/* filename: test.x */
3.2 用 rpcgen -C -a test.x 生成7个文件
Makefile.test test_client.c test_clnt.c test.h test_server.c test_svc.c test_xdr.c
3.3 修改test_client.c & test_server.c文件:
参考https://www.jianshu.com/p/b33fc01c1f59
3.4 添加完成后执行
make -f Makefile.test
3.5 在命令行运行
$ ./test_server
$ ./test_client 127.0.0.1
https://command-not-found.com/rpcinfo
https://www.tutorialspoint.com/unix_commands/rpcgen.htm
https://www.jianshu.com/p/b33fc01c1f59