diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Verteilte Systeme/Praktikum2/loesung_neu/phonebook_svc.c | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Bachelor/Verteilte Systeme/Praktikum2/loesung_neu/phonebook_svc.c')
| -rw-r--r-- | Bachelor/Verteilte Systeme/Praktikum2/loesung_neu/phonebook_svc.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung_neu/phonebook_svc.c b/Bachelor/Verteilte Systeme/Praktikum2/loesung_neu/phonebook_svc.c new file mode 100644 index 0000000..0af71dd --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung_neu/phonebook_svc.c @@ -0,0 +1,98 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "phonebook.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 +phonebook_1(struct svc_req *rqstp, register SVCXPRT *transp) +{ + union { + phonebookEntry add_1_arg; + str_name search_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 add: + _xdr_argument = (xdrproc_t) xdr_phonebookEntry; + _xdr_result = (xdrproc_t) xdr_int; + local = (char *(*)(char *, struct svc_req *)) add_1_svc; + break; + + case search: + _xdr_argument = (xdrproc_t) xdr_str_name; + _xdr_result = (xdrproc_t) xdr_str_number; + local = (char *(*)(char *, struct svc_req *)) search_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 (Phonebook, ONE); + + transp = svcudp_create(RPC_ANYSOCK); + if (transp == NULL) { + fprintf (stderr, "%s", "cannot create udp service."); + exit(1); + } + if (!svc_register(transp, Phonebook, ONE, phonebook_1, IPPROTO_UDP)) { + fprintf (stderr, "%s", "unable to register (Phonebook, ONE, 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, Phonebook, ONE, phonebook_1, IPPROTO_TCP)) { + fprintf (stderr, "%s", "unable to register (Phonebook, ONE, tcp)."); + exit(1); + } + + svc_run (); + fprintf (stderr, "%s", "svc_run returned"); + exit (1); + /* NOTREACHED */ +} |
