【问题标题】:Use of unsigned long long with rpcgen gives error将 unsigned long long 与 rpcgen 一起使用会产生错误
【发布时间】:2017-04-03 13:45:46
【问题描述】:

我有一个文件 reken.x、client.c 和 server.c 来创建一个分布式系统。客户端将两个素数的乘积(所以一个数字)发送到服务器上的“ontbind”函数,该函数将数字分解回两个素数。当我将“reken_in”和“reken_uit”结构中的变量“getal1”、“antwoord1”和“antwoord2”声明为整数时,这可以正常工作。但是,当我使用 unsigned long longs 时,会出现以下错误:

user@DTP12771:~/Desktop/tarbal$ rpcgen reken.x
 unsigned long long getal1;
^^^^^^^^^^^^^^^^^^^
reken.x, line 2: expected '*' or 'identifier'

如何使用 unsigned long long 类型进行这项工作?请参考我下面的代码。

reken.x

struct reken_in { /*input argument*/
    unsigned long long getal1;
};

struct reken_uit {
        unsigned long long antwoord1;
    unsigned long long antwoord2;
};

program BEREKEN {
    version  BERVERS{
        reken_uit ONTBIND(reken_in) =1; /*procedure nr. 1*/
         }=1;
}=0x31230000;     /*programma nummer*/

client.c

#include    <stdio.h>
#include    <rpc/rpc.h>
#include    "reken.h"
#include    <stdlib.h>

main(int argc,char *argv[])
{
//hi
CLIENT *cl;
char *server;
reken_in getallen;
reken_uit *antw;

if(argc !=3) {
    puts("aantal argumenten niet goed  <server   productPriemen>");
    exit(1);
}

server=argv[1];
getallen.getal1= strtoull(argv[2], NULL, 10);

cl=clnt_create(server,BEREKEN,BERVERS,"tcp");
if(cl==NULL) {
  printf("fout bij het zoeken naar de server");
  clnt_pcreateerror(server);
  exit(1);
}

antw= ontbind_1(&getallen,cl);
if(antw==NULL)
  puts("fout bij teruggeef parameter");

printf("Het getal %llu is het product van priemgetal %llu en %llu\n",getallen.getal1, antw->antwoord1, antw->antwoord2);
exit (0);
}

server.c

#include  <stdio.h>
#include <rpc/rpc.h>
#include <dirent.h>

#include "reken.h"
#include <math.h>

reken_uit *ontbind_1_svc(struct reken_in *g,struct svc_req *reg)
{
   static reken_uit getallen;

   unsigned long long number = g->getal1;
   unsigned long long i;
   unsigned long long fact;
    for(i = 2; i <= sqrt(number); i++) { //loop tot de sqrt
        if (!isPrime(i) || (i % 2 == 0 && i != 2)) continue;

        if ( number % i != 0 ) continue;

        fact = number / i;      //deel door de i. De i is een prime

        int prime = isPrime(fact);

        if (!prime) continue;

        getallen.antwoord1 = i;
        getallen.antwoord2 = fact;
        return (&getallen);
    }

    return (&getallen);
}

int isPrime (const long long number) {
    int i;  
    for(i = 2; i < number / 2; i++) { // 7
        if ((number % i) == 0) // 7 % 2 == 1
            return 0;
    }
    return 1;
}

【问题讨论】:

    标签: c rpc distributed-computing


    【解决方案1】:

    在 XDR 中,unsigned long long 未定义,而是使用: unsigned hyperhyper 已签名。有关更多详细信息,请查找spec

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      • 2013-06-21
      • 2021-10-24
      • 1970-01-01
      • 2012-08-21
      相关资源
      最近更新 更多