これは私のクライアントコードです
cl.c
#include "S.h"
int main()
{
CLIENT *cl;
cl=clnt_create("127.0.0.1",S_PROG,S_VERS,"tcp");
struct st i,*o;i.a=3;
o=square_1(&i,cl);
printf("%d",o->a);
return 0;
}
サーバーコード
server1.c
#include "S.h"
struct st* square_1_svc(struct st *i,struct svc_req *r)
{
static struct st o;
o.a=i->a*i->a;
return &o;
}
Sx
struct st
{
int a;
};
program S_PROG
{
version S_VERS
{
st square(st)=1;
}=1;
}=OX31231234;
コンパイル手順
rpcgen -C S.x
gcc -c S_xdr.c
gcc -c S_clnt.c
gcc -c S_svc.c
gcc -c cl.c
gcc -c server1.c
オブジェクトファイルを手動で構築する
gcc -o rpccl S_xdr.o S_clnt.o cl.o -lnsl
gcc -o rpcserver1 S_xdr.o S_svc.o server1.o -lnsl
./rpserver1
./spccl
クライアント出力ファイル、つまり「./spccl」行を実行すると、セグメンテーション違反が発生します。