Linux和Solaris之间的RPC通信

时间:2013-04-12 17:35:55

标签: linux solaris rpc

我在Solaris中运行了RPC服务器。我有一个在Solaris中运行良好的RPC客户端 当我在Ubuntu中编译并运行相同的代码时,我在服务器中获得了Error decoding arguments

Solaris使用SunRPC(ONC RPC)。不知道如何找到rpc的版本。

Linux和Linux中可用的RPC之间有什么区别吗?的Solaris?
在Solaris和Solaris中生成的xdr之间是否存在任何不匹配? Linux呢?

我该如何找出问题?

注意:无法发布代码

3 个答案:

答案 0 :(得分:0)

@twalberg,@ cppcoder你解决了这个问题吗?我有同样的问题,但我可以发布我的代码,如果它会有所帮助。代码的某些部分是:

/ *现在分配一个LoopListRequestStruct并用请求数据* /

填充它
llrs = malloc(sizeof(LoopListRequestStruct));

fill_llrs(llrs);

/* Now, make the client request to the bossServer   */

client_call_status = clnt_call(request_client, ModifyDhctState,
        (xdrproc_t)xdr_LoopListRequestStruct,
        (caddr_t)llrs, 
        (xdrproc_t)xdr_void,
        0,
        dummy_timeval
    );

void fill_llrs(LoopListRequestStruct * llrs) {

Descriptor_Loop* dl = 0;
DhctState_d *dhct_state_ptr = 0;
PackageAuthorization_d *pkg_auth_ptr = 0; 

llrs->TRANS_NUM = 999999;   /* strictly arbitraty, use whatever you want */
                                                    /* the bossServer simply passes this back in */
                                                    /* in the response you use it to match       */
                                                    /* request/response if you want or you can   */
                                                    /* choose to ignore it if you want           */

/* now set the response program number, this is the program number of  */
/* transient program that was set up using the svc_reg_utils.[ch]      */
/* it is that program that the response will be sent to                */

llrs->responseProgramNum = response_program_number; 

/* now allocate some memory for the data structures that will actually */
/* carry the request data */

llrs->ARG_PTR = malloc(sizeof(LoopListRequestArgs));

dl = llrs->ARG_PTR->loopList.Loop_List_val;

/* we are using a single descriptor loop at a time, this should always */
/* be the case */

llrs->ARG_PTR->loopList.Loop_List_len = 1;
llrs->ARG_PTR->loopList.Loop_List_val = malloc(sizeof(Descriptor_Loop));

/* now allocate memory and set the size for the ModifyDhctConfiguration */
/* this transaction always has 3 descriptors, the DhctMacAddr_d, the    */
/* DhctState_d, and the PackageAuthorization_d                          */

dl = llrs->ARG_PTR->loopList.Loop_List_val;
dl->Descriptor_Loop_len = 2;
dl->Descriptor_Loop_val = 
    malloc((2 * sizeof(Resource_descriptor_union)));

/* now, populate each descriptor */
/* the order doesn't really matter I'm just doing it in the order I    */
/* always have done */

/* first the mac address descriptor */

dl->Descriptor_Loop_val->type = 
    dhct_mac_addr_type;

strcpy(
    dl->Descriptor_Loop_val[0].Resource_descriptor_union_u.dhctMacAddr.dhctMacAddr,
    dhct_mac_addr
);

/* second the dhct state descriptor */

dl->Descriptor_Loop_val[1].type = 
    dhct_state_type;

dhct_state_ptr =
    &(dl->Descriptor_Loop_val[1].Resource_descriptor_union_u.dhctState);

if(dis_enable)
    dhct_state_ptr->disEnableFlag = DIS_Enabled;
else
    dhct_state_ptr->disEnableFlag = DIS_Disabled;

if(dms_enable)
    dhct_state_ptr->dmsEnableFlag = DMS_Enabled;
else
    dhct_state_ptr->dmsEnableFlag = DMS_Disabled;

if(analog_enable)
    dhct_state_ptr->analogEnableFlag = AEF_Enabled;
else
    dhct_state_ptr->analogEnableFlag = AEF_Disabled;

if(ippv_enable)
    dhct_state_ptr->ippvEnableFlag = IEF_Enabled;
else
    dhct_state_ptr->ippvEnableFlag = IEF_Disabled;

dhct_state_ptr->creditLimit = credit_limit;
dhct_state_ptr->maxIppvEvents = max_ippv_events;

/* we don't currently use the powerkey pin, instead we use an      */
/* application layer pin for purchases and blocking so always turn */   
/* pinEnable off */

dhct_state_ptr->pinEnable = PE_Disabled;
dhct_state_ptr->pin = 0;


if(fast_refresh_enable)
    dhct_state_ptr->fastRefreshFlag = FRF_Enabled;
else
    dhct_state_ptr->fastRefreshFlag = FRF_Disabled;

dhct_state_ptr->locationX = location_x;
dhct_state_ptr->locationY = location_y;

}

答案 1 :(得分:0)

在与同一软件集成期间,我遇到了这个错误。 Linux版本确实会产生错误的请求。这种行为的原因是null c-string的序列化。 SUN rpc的Glibc版本无法编码,xdr_string返回零。但是您正在处理的样本将'pin'设置为0.只需将'pin'替换为“”,或者在xdr_string()上创建一些包装,样本就可以工作。

我对PowerKey示例的补丁如下所示:

<       if (!xdr_string(xdrs, objp, PIN_SZ))
<               return (FALSE);
<       return (TRUE);
---
>     char *t = "";
>     return  xdr_string(xdrs, *objp? objp : &t , PIN_SZ);

但它可以变得更简单,当然。一般来说,你应该修复生成代码的使用,在我的例子中,软件作者提供的样本源中的'pin'变量必须在xdr_string()调用之前初始化。

答案 2 :(得分:0)

请注意,XDR将处理字节序,但如果您使用特定于应用程序的不透明字段,如果您自己不处理字节序,则解码将中断。确保整数作为XDR整数发送