Search code examples
crpcdistributed-computing

Use of unsigned long long with rpcgen gives error


I have a file reken.x, client.c and server.c to create a distributed system. The client sends the product of two prime numbers (so one number) to the "ontbind" function on the server which factorizes the number back into the two prime numbers. This works fine when I declare the variables "getal1", "antwoord1", and "antwoord2" in the "reken_in" and "reken_uit" structs as ints. However, when I use unsigned long longs I get the following error:

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

How do I make this work with the unsigned long long type? Please refer to my code below.

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;
}

Solution

  • In XDR, unsigned long long is not defined instead use: unsigned hyper or hyper for signed. For more details find the spec.