远程过程调用:如何在 XDR 文件中声明同一程序的两个版本

发布于 2024-11-01 10:10:08 字数 1478 浏览 1 评论 0原文

我正在编写一个程序,它使 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白龙吟 2024-11-08 10:10:08

“版本名称在范围内不能出现多次
程序定义。版本号也不能出现多次
在程序定义的范围内。” - RFC 1057

您只需提供版本字符串不同的名称,例如:

program MSGPROG{

    version PRINTMSGVERSION_1 {
        int PRINTMSG(string) = 1;
    } = 1;

    version PRINTMSGVERSION_2{
        int PRINTMSG(string) = 1;
    } = 2;

} = 0x2000001;

"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.:

program MSGPROG{

    version PRINTMSGVERSION_1 {
        int PRINTMSG(string) = 1;
    } = 1;

    version PRINTMSGVERSION_2{
        int PRINTMSG(string) = 1;
    } = 2;

} = 0x2000001;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文