Last active
June 1, 2017 06:36
-
-
Save Wachiwi/4df456383858419f59e0c0848243c38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a template Makefile generated by rpcgen | |
# Parameters | |
CLIENT = vs_client | |
SERVER = vs_server | |
SOURCES_CLNT.c = | |
SOURCES_CLNT.h = | |
SOURCES_SVC.c = | |
SOURCES_SVC.h = | |
SOURCES.x = vs.x | |
TARGETS_SVC.c = vs_svc.c vs_server.c vs_xdr.c | |
TARGETS_CLNT.c = vs_clnt.c vs_client.c vs_xdr.c | |
TARGETS = server.h vs_xdr.c vs_clnt.c vs_svc.c vs_client.c vs_server.c | |
OBJECTS_CLNT = $(SOURCES_CLNT.c:%.c=%.o) $(TARGETS_CLNT.c:%.c=%.o) | |
OBJECTS_SVC = $(SOURCES_SVC.c:%.c=%.o) $(TARGETS_SVC.c:%.c=%.o) | |
# Compiler flags | |
CFLAGS += -g | |
LDLIBS += -lnsl | |
RPCGENFLAGS = | |
# Targets | |
all : $(CLIENT) $(SERVER) | |
$(TARGETS) : $(SOURCES.x) | |
rpcgen $(RPCGENFLAGS) $(SOURCES.x) | |
$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) $(TARGETS_CLNT.c) | |
$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) $(TARGETS_SVC.c) | |
$(CLIENT) : $(OBJECTS_CLNT) | |
$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS) | |
$(SERVER) : $(OBJECTS_SVC) | |
$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS) | |
clean: | |
$(RM) core $(TARGETS) $(OBJECTS_CLNT) $(OBJECTS_SVC) $(CLIENT) $(SERVER) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Please do not edit this file. | |
* It was generated using rpcgen. | |
*/ | |
#ifndef _VS_H_RPCGEN | |
#define _VS_H_RPCGEN | |
#include <rpc/rpc.h> | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
struct add_params { | |
long p1; | |
long p2; | |
}; | |
typedef struct add_params add_params; | |
struct concat_params { | |
char *str1; | |
char *str2; | |
}; | |
typedef struct concat_params concat_params; | |
struct split_return { | |
char *pre; | |
char *post; | |
}; | |
typedef struct split_return split_return; | |
#define VS11SERVER 0x20004123 | |
#define VSSERVERVERS 1 | |
#if defined(__STDC__) || defined(__cplusplus) | |
#define vs_square 1 | |
extern long * vs_square_1(long *, CLIENT *); | |
extern long * vs_square_1_svc(long *, struct svc_req *); | |
#define vs_add 2 | |
extern long * vs_add_1(add_params *, CLIENT *); | |
extern long * vs_add_1_svc(add_params *, struct svc_req *); | |
#define vs_concat 3 | |
extern char ** vs_concat_1(concat_params *, CLIENT *); | |
extern char ** vs_concat_1_svc(concat_params *, struct svc_req *); | |
#define vs_split 4 | |
extern split_return * vs_split_1(char **, CLIENT *); | |
extern split_return * vs_split_1_svc(char **, struct svc_req *); | |
#define vs_increment 5 | |
extern void * vs_increment_1(long *, CLIENT *); | |
extern void * vs_increment_1_svc(long *, struct svc_req *); | |
#define vs_Shutdown 6 | |
extern void * vs_shutdown_1(void *, CLIENT *); | |
extern void * vs_shutdown_1_svc(void *, struct svc_req *); | |
extern int vs11server_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t); | |
#else /* K&R C */ | |
#define vs_square 1 | |
extern long * vs_square_1(); | |
extern long * vs_square_1_svc(); | |
#define vs_add 2 | |
extern long * vs_add_1(); | |
extern long * vs_add_1_svc(); | |
#define vs_concat 3 | |
extern char ** vs_concat_1(); | |
extern char ** vs_concat_1_svc(); | |
#define vs_split 4 | |
extern split_return * vs_split_1(); | |
extern split_return * vs_split_1_svc(); | |
#define vs_increment 5 | |
extern void * vs_increment_1(); | |
extern void * vs_increment_1_svc(); | |
#define vs_Shutdown 6 | |
extern void * vs_shutdown_1(); | |
extern void * vs_shutdown_1_svc(); | |
extern int vs11server_1_freeresult (); | |
#endif /* K&R C */ | |
/* the xdr functions */ | |
#if defined(__STDC__) || defined(__cplusplus) | |
extern bool_t xdr_add_params (XDR *, add_params*); | |
extern bool_t xdr_concat_params (XDR *, concat_params*); | |
extern bool_t xdr_split_return (XDR *, split_return*); | |
#else /* K&R C */ | |
extern bool_t xdr_add_params (); | |
extern bool_t xdr_concat_params (); | |
extern bool_t xdr_split_return (); | |
#endif /* K&R C */ | |
#ifdef __cplusplus | |
} | |
#endif | |
#endif /* !_VS_H_RPCGEN */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sourcecode by David Schwarzmann, 29.05.17 */ | |
struct add_params { | |
long p1; | |
long p2; | |
}; | |
struct concat_params { | |
string str1<>; | |
string str2<>; | |
}; | |
struct split_return { | |
string pre<>; | |
string post<>; | |
}; | |
program VS11SERVER { | |
version VSSERVERVERS { | |
long vs_square(long)=1; | |
long vs_add(add_params)=2; | |
string vs_concat(concat_params)=3; | |
split_return vs_split(string)=4; | |
void vs_increment(long)=5; | |
void vs_Shutdown(void)=6; | |
}=1; | |
} = 0x20004123; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sourcecode by David Schwarzmann, 29.05.17 */ | |
#include "vs.h" | |
void | |
vs11server_1(char *host) | |
{ | |
CLIENT *clnt; | |
long *result_1; | |
long vs_square_1_arg = 2; | |
long *result_2; | |
add_params vs_add_1_arg = {4, 5}; | |
char * *result_3; | |
concat_params vs_concat_1_arg = {"abc", "def"}; | |
split_return *result_4; | |
char * vs_split_1_arg = "abc def"; | |
void *result_5; | |
long vs_increment_1_arg = 6; | |
void *result_6; | |
char *vs_shutdown_1_arg = NULL; | |
#ifndef DEBUG | |
clnt = clnt_create (host, VS11SERVER, VSSERVERVERS, "tcp"); | |
if (clnt == NULL) { | |
clnt_pcreateerror (host); | |
exit (1); | |
} | |
#endif /* DEBUG */ | |
result_1 = vs_square_1(&vs_square_1_arg, clnt); | |
if (result_1 == (long *) NULL) { | |
clnt_perror (clnt, "vs_square call failed"); | |
} | |
printf("square(%li) = %li\n", vs_square_1_arg, *result_1); | |
result_2 = vs_add_1(&vs_add_1_arg, clnt); | |
if (result_2 == (long *) NULL) { | |
clnt_perror (clnt, "vs_add call failed"); | |
} | |
printf("vs_add({%li, %li}) = %li\n", vs_add_1_arg.p1, vs_add_1_arg.p2, *result_2); | |
result_3 = vs_concat_1(&vs_concat_1_arg, clnt); | |
if (result_3 == (char **) NULL) { | |
clnt_perror (clnt, "vs_concat call failed"); | |
} | |
printf("vs_concat({\"%s\", \"%s\"}) = \"%s\"\n", vs_concat_1_arg.str1, vs_concat_1_arg.str2, *result_3); | |
result_4 = vs_split_1(&vs_split_1_arg, clnt); | |
if (result_4 == (split_return *) NULL) { | |
clnt_perror (clnt, "vs_split call failed"); | |
} | |
printf("vs_split(\"%s\") = {\"%s\", \"%s\"}\n", vs_split_1_arg, result_4->pre, result_4->post); | |
result_5 = vs_increment_1(&vs_increment_1_arg, clnt); | |
if (result_5 == (void *) NULL) { | |
clnt_perror (clnt, "call failed"); | |
} | |
printf("vs_increment(%li)\n", vs_increment_1_arg); | |
result_6 = vs_shutdown_1((void*)&vs_shutdown_1_arg, clnt); | |
if (result_6 == (void *) NULL) { | |
printf("vs_shutdown seemed to work\n"); | |
// clnt_perror (clnt, "call failed"); | |
} | |
//printf("vs_shutdown_1()\n"); | |
#ifndef DEBUG | |
clnt_destroy (clnt); | |
#endif /* DEBUG */ | |
} | |
int | |
main (int argc, char *argv[]) | |
{ | |
char *host; | |
if (argc < 2) { | |
printf ("usage: %s server_host\n", argv[0]); | |
exit (1); | |
} | |
host = argv[1]; | |
vs11server_1 (host); | |
exit (0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Please do not edit this file. | |
* It was generated using rpcgen. | |
*/ | |
#include <memory.h> /* for memset */ | |
#include "vs.h" | |
/* Default timeout can be changed using clnt_control() */ | |
static struct timeval TIMEOUT = { 25, 0 }; | |
long * | |
vs_square_1(long *argp, CLIENT *clnt) | |
{ | |
static long clnt_res; | |
memset((char *)&clnt_res, 0, sizeof(clnt_res)); | |
if (clnt_call (clnt, vs_square, | |
(xdrproc_t) xdr_long, (caddr_t) argp, | |
(xdrproc_t) xdr_long, (caddr_t) &clnt_res, | |
TIMEOUT) != RPC_SUCCESS) { | |
return (NULL); | |
} | |
return (&clnt_res); | |
} | |
long * | |
vs_add_1(add_params *argp, CLIENT *clnt) | |
{ | |
static long clnt_res; | |
memset((char *)&clnt_res, 0, sizeof(clnt_res)); | |
if (clnt_call (clnt, vs_add, | |
(xdrproc_t) xdr_add_params, (caddr_t) argp, | |
(xdrproc_t) xdr_long, (caddr_t) &clnt_res, | |
TIMEOUT) != RPC_SUCCESS) { | |
return (NULL); | |
} | |
return (&clnt_res); | |
} | |
char ** | |
vs_concat_1(concat_params *argp, CLIENT *clnt) | |
{ | |
static char *clnt_res; | |
memset((char *)&clnt_res, 0, sizeof(clnt_res)); | |
if (clnt_call (clnt, vs_concat, | |
(xdrproc_t) xdr_concat_params, (caddr_t) argp, | |
(xdrproc_t) xdr_wrapstring, (caddr_t) &clnt_res, | |
TIMEOUT) != RPC_SUCCESS) { | |
return (NULL); | |
} | |
return (&clnt_res); | |
} | |
split_return * | |
vs_split_1(char **argp, CLIENT *clnt) | |
{ | |
static split_return clnt_res; | |
memset((char *)&clnt_res, 0, sizeof(clnt_res)); | |
if (clnt_call (clnt, vs_split, | |
(xdrproc_t) xdr_wrapstring, (caddr_t) argp, | |
(xdrproc_t) xdr_split_return, (caddr_t) &clnt_res, | |
TIMEOUT) != RPC_SUCCESS) { | |
return (NULL); | |
} | |
return (&clnt_res); | |
} | |
void * | |
vs_increment_1(long *argp, CLIENT *clnt) | |
{ | |
static char clnt_res; | |
memset((char *)&clnt_res, 0, sizeof(clnt_res)); | |
if (clnt_call (clnt, vs_increment, | |
(xdrproc_t) xdr_long, (caddr_t) argp, | |
(xdrproc_t) xdr_void, (caddr_t) &clnt_res, | |
TIMEOUT) != RPC_SUCCESS) { | |
return (NULL); | |
} | |
return ((void *)&clnt_res); | |
} | |
void * | |
vs_shutdown_1(void *argp, CLIENT *clnt) | |
{ | |
static char clnt_res; | |
memset((char *)&clnt_res, 0, sizeof(clnt_res)); | |
if (clnt_call (clnt, vs_Shutdown, | |
(xdrproc_t) xdr_void, (caddr_t) argp, | |
(xdrproc_t) xdr_void, (caddr_t) &clnt_res, | |
TIMEOUT) != RPC_SUCCESS) { | |
return (NULL); | |
} | |
return ((void *)&clnt_res); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sourcecode by David Schwarzmann, 29.05.17 */ | |
#include "vs.h" | |
#include <rpc/pmap_clnt.h> | |
long * | |
vs_square_1_svc(long *argp, struct svc_req *rqstp) | |
{ | |
long *result = malloc(sizeof(long)); | |
*result = *argp * *argp; | |
return result; | |
} | |
long * | |
vs_add_1_svc(add_params *argp, struct svc_req *rqstp) | |
{ | |
long *result = malloc(sizeof(long)); | |
*result = argp->p1 + argp->p2; | |
return result; | |
} | |
char ** | |
vs_concat_1_svc(concat_params *argp, struct svc_req *rqstp) | |
{ | |
static char * result; | |
result = malloc(strlen(argp->str1)+strlen(argp->str2)+1); | |
strcpy(result, argp->str1); | |
strcat(result, argp->str2); | |
return &result; | |
} | |
split_return * | |
vs_split_1_svc(char **argp, struct svc_req *rqstp) | |
{ | |
static split_return result; | |
int pre, post = 0; | |
for(pre = 0; (*argp)[pre] != '\0'; pre++) { | |
if ((*argp)[pre] == ' ' || | |
(*argp)[pre] == '\t' || | |
(*argp)[pre] == '\r' || | |
(*argp)[pre] == '\n') | |
break; | |
} | |
for(post = pre; (*argp)[post] != '\0'; post++) {} | |
result.pre = calloc(pre, sizeof(char)); | |
result.post = calloc(post, sizeof(char)); | |
int i; | |
for(i = 0; i < pre; i++) { | |
result.pre[i] = (*argp)[i]; | |
} | |
for(i = 0; i < post; i++) { | |
result.post[i] = (*argp)[pre + i]; | |
} | |
return &result; | |
} | |
void * | |
vs_increment_1_svc(long *argp, struct svc_req *rqstp) | |
{ | |
static long v = 0; | |
v += *argp; | |
return NULL; | |
} | |
void * | |
vs_shutdown_1_svc(void *argp, struct svc_req *rqstp) | |
{ | |
pmap_unset (VS11SERVER, VSSERVERVERS); | |
return NULL; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Please do not edit this file. | |
* It was generated using rpcgen. | |
*/ | |
#include "vs.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <rpc/pmap_clnt.h> | |
#include <string.h> | |
#include <memory.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#ifndef SIG_PF | |
#define SIG_PF void(*)(int) | |
#endif | |
static void | |
vs11server_1(struct svc_req *rqstp, register SVCXPRT *transp) | |
{ | |
union { | |
long vs_square_1_arg; | |
add_params vs_add_1_arg; | |
concat_params vs_concat_1_arg; | |
char *vs_split_1_arg; | |
long vs_increment_1_arg; | |
} argument; | |
char *result; | |
xdrproc_t _xdr_argument, _xdr_result; | |
char *(*local)(char *, struct svc_req *); | |
switch (rqstp->rq_proc) { | |
case NULLPROC: | |
(void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL); | |
return; | |
case vs_square: | |
_xdr_argument = (xdrproc_t) xdr_long; | |
_xdr_result = (xdrproc_t) xdr_long; | |
local = (char *(*)(char *, struct svc_req *)) vs_square_1_svc; | |
break; | |
case vs_add: | |
_xdr_argument = (xdrproc_t) xdr_add_params; | |
_xdr_result = (xdrproc_t) xdr_long; | |
local = (char *(*)(char *, struct svc_req *)) vs_add_1_svc; | |
break; | |
case vs_concat: | |
_xdr_argument = (xdrproc_t) xdr_concat_params; | |
_xdr_result = (xdrproc_t) xdr_wrapstring; | |
local = (char *(*)(char *, struct svc_req *)) vs_concat_1_svc; | |
break; | |
case vs_split: | |
_xdr_argument = (xdrproc_t) xdr_wrapstring; | |
_xdr_result = (xdrproc_t) xdr_split_return; | |
local = (char *(*)(char *, struct svc_req *)) vs_split_1_svc; | |
break; | |
case vs_increment: | |
_xdr_argument = (xdrproc_t) xdr_long; | |
_xdr_result = (xdrproc_t) xdr_void; | |
local = (char *(*)(char *, struct svc_req *)) vs_increment_1_svc; | |
break; | |
case vs_Shutdown: | |
_xdr_argument = (xdrproc_t) xdr_void; | |
_xdr_result = (xdrproc_t) xdr_void; | |
local = (char *(*)(char *, struct svc_req *)) vs_shutdown_1_svc; | |
break; | |
default: | |
svcerr_noproc (transp); | |
return; | |
} | |
memset ((char *)&argument, 0, sizeof (argument)); | |
if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { | |
svcerr_decode (transp); | |
return; | |
} | |
result = (*local)((char *)&argument, rqstp); | |
if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) { | |
svcerr_systemerr (transp); | |
} | |
if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { | |
fprintf (stderr, "%s", "unable to free arguments"); | |
exit (1); | |
} | |
return; | |
} | |
int | |
main (int argc, char **argv) | |
{ | |
register SVCXPRT *transp; | |
pmap_unset (VS11SERVER, VSSERVERVERS); | |
transp = svcudp_create(RPC_ANYSOCK); | |
if (transp == NULL) { | |
fprintf (stderr, "%s", "cannot create udp service."); | |
exit(1); | |
} | |
if (!svc_register(transp, VS11SERVER, VSSERVERVERS, vs11server_1, IPPROTO_UDP)) { | |
fprintf (stderr, "%s", "unable to register (VS11SERVER, VSSERVERVERS, udp)."); | |
exit(1); | |
} | |
transp = svctcp_create(RPC_ANYSOCK, 0, 0); | |
if (transp == NULL) { | |
fprintf (stderr, "%s", "cannot create tcp service."); | |
exit(1); | |
} | |
if (!svc_register(transp, VS11SERVER, VSSERVERVERS, vs11server_1, IPPROTO_TCP)) { | |
fprintf (stderr, "%s", "unable to register (VS11SERVER, VSSERVERVERS, tcp)."); | |
exit(1); | |
} | |
svc_run (); | |
fprintf (stderr, "%s", "svc_run returned"); | |
exit (1); | |
/* NOTREACHED */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Please do not edit this file. | |
* It was generated using rpcgen. | |
*/ | |
#include "vs.h" | |
bool_t | |
xdr_add_params (XDR *xdrs, add_params *objp) | |
{ | |
register int32_t *buf; | |
if (!xdr_long (xdrs, &objp->p1)) | |
return FALSE; | |
if (!xdr_long (xdrs, &objp->p2)) | |
return FALSE; | |
return TRUE; | |
} | |
bool_t | |
xdr_concat_params (XDR *xdrs, concat_params *objp) | |
{ | |
register int32_t *buf; | |
if (!xdr_string (xdrs, &objp->str1, ~0)) | |
return FALSE; | |
if (!xdr_string (xdrs, &objp->str2, ~0)) | |
return FALSE; | |
return TRUE; | |
} | |
bool_t | |
xdr_split_return (XDR *xdrs, split_return *objp) | |
{ | |
register int32_t *buf; | |
if (!xdr_string (xdrs, &objp->pre, ~0)) | |
return FALSE; | |
if (!xdr_string (xdrs, &objp->post, ~0)) | |
return FALSE; | |
return TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment