From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Praktikum2/loesung/Makefile.telbuch | 46 +++++++++ .../Verteilte Systeme/Praktikum2/loesung/telbuch | 9 ++ .../Verteilte Systeme/Praktikum2/loesung/telbuch.h | 73 ++++++++++++++ .../Verteilte Systeme/Praktikum2/loesung/telbuch.x | 24 +++++ .../Praktikum2/loesung/telbuch_client.c | 108 +++++++++++++++++++++ .../Praktikum2/loesung/telbuch_clnt.c | 40 ++++++++ .../Praktikum2/loesung/telbuch_server.c | 78 +++++++++++++++ .../Praktikum2/loesung/telbuch_svc.c | 98 +++++++++++++++++++ .../Praktikum2/loesung/telbuch_xdr.c | 45 +++++++++ 9 files changed, 521 insertions(+) create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/Makefile.telbuch create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch.h create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch.x create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_client.c create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_clnt.c create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_server.c create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_svc.c create mode 100644 Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_xdr.c (limited to 'Bachelor/Verteilte Systeme/Praktikum2/loesung') diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/Makefile.telbuch b/Bachelor/Verteilte Systeme/Praktikum2/loesung/Makefile.telbuch new file mode 100644 index 0000000..b744044 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/Makefile.telbuch @@ -0,0 +1,46 @@ + +# This is a template Makefile generated by rpcgen + +# Parameters + +CLIENT = telbuch_client +SERVER = telbuch_server + +SOURCES_CLNT.c = +SOURCES_CLNT.h = +SOURCES_SVC.c = +SOURCES_SVC.h = +SOURCES.x = telbuch.x + +TARGETS_SVC.c = telbuch_svc.c telbuch_server.c telbuch_xdr.c +TARGETS_CLNT.c = telbuch_clnt.c telbuch_client.c telbuch_xdr.c +TARGETS = telbuch.h telbuch_xdr.c telbuch_clnt.c telbuch_svc.c telbuch_client.c telbuch_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) + diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch new file mode 100644 index 0000000..d94773b --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch @@ -0,0 +1,9 @@ +Napp Kall 123456 +Meyer Petra 56789 +Schuster Willi 1234567 +Mueller Klaus 987654 +Schmidt Sabine 122112 +Meyer Klaus 08154711 +Schill Alfred 47110815 +Lopez Jenifer 0815 +Schmitz Frida 1234567 diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch.h b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch.h new file mode 100644 index 0000000..3938bfc --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch.h @@ -0,0 +1,73 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#ifndef _TELBUCH_H_RPCGEN +#define _TELBUCH_H_RPCGEN + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct addStruct { + char Name[45]; + char TelNr[45]; +}; +typedef struct addStruct addStruct; + +struct searchStruct { + char Name[45]; +}; +typedef struct searchStruct searchStruct; + +struct Ergebnis { + char Eintrag[80]; +}; +typedef struct Ergebnis Ergebnis; + +#define TELBUCH_VERWALTUNG 1234567 +#define ONE 1 + +#if defined(__STDC__) || defined(__cplusplus) +#define addEntry 1 +extern Ergebnis * addentry_1(addStruct *, CLIENT *); +extern Ergebnis * addentry_1_svc(addStruct *, struct svc_req *); +#define searchEntry 2 +extern Ergebnis * searchentry_1(searchStruct *, CLIENT *); +extern Ergebnis * searchentry_1_svc(searchStruct *, struct svc_req *); +extern int telbuch_verwaltung_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t); + +#else /* K&R C */ +#define addEntry 1 +extern Ergebnis * addentry_1(); +extern Ergebnis * addentry_1_svc(); +#define searchEntry 2 +extern Ergebnis * searchentry_1(); +extern Ergebnis * searchentry_1_svc(); +extern int telbuch_verwaltung_1_freeresult (); +#endif /* K&R C */ + +/* the xdr functions */ + +#if defined(__STDC__) || defined(__cplusplus) +extern bool_t xdr_addStruct (XDR *, addStruct*); +extern bool_t xdr_searchStruct (XDR *, searchStruct*); +extern bool_t xdr_Ergebnis (XDR *, Ergebnis*); + +#else /* K&R C */ +extern bool_t xdr_addStruct (); +extern bool_t xdr_searchStruct (); +extern bool_t xdr_Ergebnis (); + +#endif /* K&R C */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_TELBUCH_H_RPCGEN */ diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch.x b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch.x new file mode 100644 index 0000000..e28bc97 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch.x @@ -0,0 +1,24 @@ +struct addStruct +{ + char Name[45]; + char TelNr[45]; +}; + +struct searchStruct +{ + char Name[45]; +}; + +struct Ergebnis +{ + char Eintrag[80]; +}; + +program TELBUCH_VERWALTUNG +{ + version ONE + { + Ergebnis addEntry(addStruct eintrag) = 1; + Ergebnis searchEntry(searchStruct eintrag) = 2; + } = 1; +} = 1234567; diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_client.c b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_client.c new file mode 100644 index 0000000..cc846e2 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_client.c @@ -0,0 +1,108 @@ +/* + * This is sample code generated by rpcgen. + * These are only templates and you can use them + * as a guideline for developing your own functions. + */ + +#include "telbuch.h" + + +void +telbuch_verwaltung_1(char *host) +{ + CLIENT *clnt; + +#ifndef DEBUG + clnt = clnt_create (host, TELBUCH_VERWALTUNG, ONE, "udp"); + if (clnt == NULL) { + clnt_pcreateerror (host); + exit (1); + } +#endif /* DEBUG */ + + + /* my code START */ + addStruct addentry_1_arg; + searchStruct searchentry_1_arg; + Ergebnis* result; + void* erg; + int w; + char name[41]; + char nname[20]; + char vname[20]; + char telnr[20]; + + printf("\nOptionen:"); + printf("\n1. Eintrag suchen"); + printf("\n2. Eintrag eintragen"); + printf("\n0. Beenden"); + printf("\n\nWahl: "); + scanf("%d",&w); + + switch (w) + { + case 1: // Nach Eintrag suchen + printf("\nName: "); + scanf("%s %s",nname, vname); // Suchnamen lesen + + strcpy(name,nname); + strcat(name, " "); + strcat(name, vname); + strcpy(searchentry_1_arg.Name,name); // Parameter für Suche füllen + + result = searchentry_1(&searchentry_1_arg, clnt); // Suche durchführen + if (result == (Ergebnis *) NULL) + clnt_perror (clnt, "call failed"); + else + printf("%s\n",result->Eintrag); + break; + case 2: // Eintrag eintragen + printf("\nName: "); + scanf("%s %s",nname, vname); // Name lesen + printf("Nummer: "); + scanf("%s",telnr); // Nummer lesen + + strcpy(name, nname); + strcat(name, " "); + strcat(name, vname); + strcpy(addentry_1_arg.Name,name); // Parameter für Eintrag + strcpy(addentry_1_arg.TelNr,telnr); + result = addentry_1(&addentry_1_arg, clnt); // Eintragen durchführen + if (result == (Ergebnis *) NULL) + clnt_perror (clnt, "call failed"); + else + printf("%s\n",result->Eintrag); + break; + case 0: exit(0); + default: printf("Falsche Eingabe\n"); break; + } + /* my code END */ + + + /*result_1 = addentry_1(&addentry_1_arg, clnt); + if (result_1 == (Ergebnis *) NULL) { + clnt_perror (clnt, "call failed"); + } + result_2 = searchentry_1(&searchentry_1_arg, clnt); + if (result_2 == (Ergebnis *) NULL) { + clnt_perror (clnt, "call failed"); + }*/ +#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]; + telbuch_verwaltung_1 (host); +exit (0); +} diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_clnt.c b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_clnt.c new file mode 100644 index 0000000..a867ddb --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_clnt.c @@ -0,0 +1,40 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include /* for memset */ +#include "telbuch.h" + +/* Default timeout can be changed using clnt_control() */ +static struct timeval TIMEOUT = { 25, 0 }; + +Ergebnis * +addentry_1(addStruct *argp, CLIENT *clnt) +{ + static Ergebnis clnt_res; + + memset((char *)&clnt_res, 0, sizeof(clnt_res)); + if (clnt_call (clnt, addEntry, + (xdrproc_t) xdr_addStruct, (caddr_t) argp, + (xdrproc_t) xdr_Ergebnis, (caddr_t) &clnt_res, + TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&clnt_res); +} + +Ergebnis * +searchentry_1(searchStruct *argp, CLIENT *clnt) +{ + static Ergebnis clnt_res; + + memset((char *)&clnt_res, 0, sizeof(clnt_res)); + if (clnt_call (clnt, searchEntry, + (xdrproc_t) xdr_searchStruct, (caddr_t) argp, + (xdrproc_t) xdr_Ergebnis, (caddr_t) &clnt_res, + TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&clnt_res); +} diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_server.c b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_server.c new file mode 100644 index 0000000..6710998 --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_server.c @@ -0,0 +1,78 @@ +/* + * This is sample code generated by rpcgen. + * These are only templates and you can use them + * as a guideline for developing your own functions. + */ + +#include "telbuch.h" + +Ergebnis * +addentry_1_svc(addStruct *argp, struct svc_req *rqstp) +{ + static Ergebnis result; + + /* my code START */ + + FILE* out; + + if ((out = fopen("telbuch", "a")) == NULL) // Datei zum Schreiben öffnen + { + strcpy(result.Eintrag,"Oeffnen der Telefonbuchdatei fehgeschlagen"); + return &result; + } + fseek(out,0,SEEK_END); // Dateizeiger an Ende setzen + + // neuen Eintrag reinschreiben + fprintf(out, "%s %s\n", argp->Name, argp->TelNr); + + fclose(out); + + strcpy(result.Eintrag,"Eintrag erfolgreich"); + + /* my code END */ + + return &result; +} + +Ergebnis * +searchentry_1_svc(searchStruct *argp, struct svc_req *rqstp) +{ + static Ergebnis result; + + /* my code START */ + char name[41]; + char nname[20]; + char vname[20]; + char telnr[20]; + + FILE* in; + + if ((in = fopen("telbuch", "r")) == NULL) // Datei zum Lesen öffnen + { + strcpy(result.Eintrag,"Oeffnen der Telefonbuchdatei fehgeschlagen"); + return &result; + } + + while (!feof(in)) // Nach dem Eintrag suchen + { + fscanf(in, "%s %s %s", nname, vname, telnr); + strcpy(name, nname); + strcat(name, " "); + strcat(name, vname); + if (strcmp(argp->Name, name) == 0) // Eintrag gefunden + { + strcpy(result.Eintrag, "gefunden: "); + strcat(result.Eintrag, name); + strcat(result.Eintrag, " "); + strcat(result.Eintrag, telnr); + return &result; + } + } + + // soweit kommt die Funktion nur, wenn kein Eintrag gefunden wurde. + strcpy(result.Eintrag, "Eintrag nicht gefunden"); + + /* my code END */ + + return &result; +} diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_svc.c b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_svc.c new file mode 100644 index 0000000..f14df2a --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_svc.c @@ -0,0 +1,98 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "telbuch.h" +#include +#include +#include +#include +#include +#include +#include + +#ifndef SIG_PF +#define SIG_PF void(*)(int) +#endif + +static void +telbuch_verwaltung_1(struct svc_req *rqstp, register SVCXPRT *transp) +{ + union { + addStruct addentry_1_arg; + searchStruct searchentry_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 addEntry: + _xdr_argument = (xdrproc_t) xdr_addStruct; + _xdr_result = (xdrproc_t) xdr_Ergebnis; + local = (char *(*)(char *, struct svc_req *)) addentry_1_svc; + break; + + case searchEntry: + _xdr_argument = (xdrproc_t) xdr_searchStruct; + _xdr_result = (xdrproc_t) xdr_Ergebnis; + local = (char *(*)(char *, struct svc_req *)) searchentry_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 (TELBUCH_VERWALTUNG, ONE); + + transp = svcudp_create(RPC_ANYSOCK); + if (transp == NULL) { + fprintf (stderr, "%s", "cannot create udp service."); + exit(1); + } + if (!svc_register(transp, TELBUCH_VERWALTUNG, ONE, telbuch_verwaltung_1, IPPROTO_UDP)) { + fprintf (stderr, "%s", "unable to register (TELBUCH_VERWALTUNG, 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, TELBUCH_VERWALTUNG, ONE, telbuch_verwaltung_1, IPPROTO_TCP)) { + fprintf (stderr, "%s", "unable to register (TELBUCH_VERWALTUNG, ONE, tcp)."); + exit(1); + } + + svc_run (); + fprintf (stderr, "%s", "svc_run returned"); + exit (1); + /* NOTREACHED */ +} diff --git a/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_xdr.c b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_xdr.c new file mode 100644 index 0000000..89ea2ad --- /dev/null +++ b/Bachelor/Verteilte Systeme/Praktikum2/loesung/telbuch_xdr.c @@ -0,0 +1,45 @@ +/* + * Please do not edit this file. + * It was generated using rpcgen. + */ + +#include "telbuch.h" + +bool_t +xdr_addStruct (XDR *xdrs, addStruct *objp) +{ + register int32_t *buf; + + int i; + if (!xdr_vector (xdrs, (char *)objp->Name, 45, + sizeof (char), (xdrproc_t) xdr_char)) + return FALSE; + if (!xdr_vector (xdrs, (char *)objp->TelNr, 45, + sizeof (char), (xdrproc_t) xdr_char)) + return FALSE; + return TRUE; +} + +bool_t +xdr_searchStruct (XDR *xdrs, searchStruct *objp) +{ + register int32_t *buf; + + int i; + if (!xdr_vector (xdrs, (char *)objp->Name, 45, + sizeof (char), (xdrproc_t) xdr_char)) + return FALSE; + return TRUE; +} + +bool_t +xdr_Ergebnis (XDR *xdrs, Ergebnis *objp) +{ + register int32_t *buf; + + int i; + if (!xdr_vector (xdrs, (char *)objp->Eintrag, 80, + sizeof (char), (xdrproc_t) xdr_char)) + return FALSE; + return TRUE; +} -- cgit v1.2.3