远程过程调用:如何在 XDR 文件中声明同一程序的两个版本
我正在编写一个程序,它使 RPC 打印一条消息,并将该消息作为参数发送给远程函数。远程函数不应该返回任何内容,但是出于好奇,我设计了远程函数以返回整数。
不管怎样,一切正常,我能够远程打印消息。现在我正在尝试在 XDR 文件中创建程序的两个版本(只是好奇!!!),但它对我来说不起作用。
这是我的新 XDR 文件
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ cat spec.x
program MSGPROG{
version PRINTMSGVERSION{
int PRINTMSG(string) = 1;
} = 1;
version PRINTMSGVERSION{
int PRINTMSG(string) = 1;
} = 2;
} = 0x2000001;
这是服务器代码:
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ cat server.c
#include<stdio.h>
#include "spec.h"
int *printmsg_1_svc(char **msg,struct svc_req * sr){
static int ret;
printf("version = 1--%s\n",*msg);
ret = 1;
return &ret;
}
int *printmsg_2_svc(char **msg,struct svc_req * sr){
static int ret;
printf("version = 2--%s\n",*msg);
ret = 1;
return &ret;
}
这是我在编译时遇到的错误:
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ rpcgen -C spec.x
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ gcc server.c spec_svc.c -o ani_server -lnsl
In file included from server.c:2:
spec.h:32: warning: "PRINTMSGVERSION" redefined
spec.h:18: note: this is the location of the previous definition
In file included from spec_svc.c:6:
spec.h:32: warning: "PRINTMSGVERSION" redefined
spec.h:18: note: this is the location of the previous definition
所以错误的出现是因为我无法弄清楚如何在 XDR 文件中声明程序的两个版本。非常感谢您阅读我的帖子。请帮帮我。提前致谢。
I am writing a program which makes a RPC to print a message that I send as a parameter to the remote function. The remote function is not supposed to return anything, however just out of curiosity I have designed the remote function to return an integer.
Anyways, everything worked fine and I was able to print a message remotely. Now I am trying to create two versions of a program in XDR file (Just curious!!!) but its not working out for me.
here is my new XDR file
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ cat spec.x
program MSGPROG{
version PRINTMSGVERSION{
int PRINTMSG(string) = 1;
} = 1;
version PRINTMSGVERSION{
int PRINTMSG(string) = 1;
} = 2;
} = 0x2000001;
Here is the server code:
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ cat server.c
#include<stdio.h>
#include "spec.h"
int *printmsg_1_svc(char **msg,struct svc_req * sr){
static int ret;
printf("version = 1--%s\n",*msg);
ret = 1;
return &ret;
}
int *printmsg_2_svc(char **msg,struct svc_req * sr){
static int ret;
printf("version = 2--%s\n",*msg);
ret = 1;
return &ret;
}
Here are the errors that I get at compile time:
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ rpcgen -C spec.x
anirudh@anirudh-Aspire-5920:~/Documents/C/DS/RPC$ gcc server.c spec_svc.c -o ani_server -lnsl
In file included from server.c:2:
spec.h:32: warning: "PRINTMSGVERSION" redefined
spec.h:18: note: this is the location of the previous definition
In file included from spec_svc.c:6:
spec.h:32: warning: "PRINTMSGVERSION" redefined
spec.h:18: note: this is the location of the previous definition
So the error is coming because I am not able to figure out how to declare two versions of a program in XDR file. Thanks a lot for reading my post. Please help me out. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“版本名称在范围内不能出现多次
程序定义。版本号也不能出现多次
在程序定义的范围内。” - RFC 1057
您只需提供版本字符串不同的名称,例如:
"A version name cannot occur more than once within the scope of a
program definition. Nor can a version number occur more than once
within the scope of a program definition." - RFC 1057
You simply have to give the version string distinct names, e.g.: