Daniel Krom Daniel Krom - 3 months ago 10
C Question

rpcgen adds _svc extension

I have an exercise to create a simple

server-client
program using
rpcgen
.

I'm writing this
ex7.x
file:

program REMOTE_PROG {
version MSG_RCV {
int STRLEN(string) = 1;
double SQUARE(double *) = 2;
int NUM_OF_DEV(int *) = 3;

} = 1;
} = 99;


executing with
rpcgen ex7.x
-> generates
ex7_svc.c
.

in the
ex7_svc.c
file, for some reason, it generates each function case with
_svc
extension:

case STRLEN:
xdr_argument = xdr_wrapstring;
xdr_result = xdr_int;
local = (char *(*)()) strlen_1_svc; //<--_SVC
break;


and when I try to compile the server after implementing the functions

int * strlen_1(char **, CLIENT *);


the compiler raises that error:

"_strlen_1_svc", referenced from:
_remote_prog_1 in ex7_svc-8501b7.o
ld: symbol(s) not found for architecture x86_64


But if I'll delete that auto generated _svc extension,
local = (char *(*)()) strlen_1; //no _svc
the program will compile successfully.


Why does this happen? why does the rpcgen adds the _svc extension to the functions and am I doing something wrong when I delete the _svc?



P.S same error also for square and num_of_dev functions, gave only strlen for example.



Thanks!

nos nos
Answer

That's the convention, the _svc is short for service.

Your server needs to implement the service function, that is the strlen_1_svc function.

Your client calls the strlen_1 function. rpcgen + the RPC library does all the inbetween - it generates code for strlen_1 used by the client which will serialize the data and transfer it to the server, where an event loop dispatches the call to your code in the strlen_1_svc function.

Comments