Bonjour,
- problème : mon code compile, tourne, mais n'affiche pas le résultat escompté
- code :
J'ai eu beau chercher, je ne vois pas... mon filtre xdr_noeud est a priori bon, non?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203 index.h #include <rpc/types.h> #define RPCSUCCESS 0 #define PROC_REC 10 #define PROC_AJ 11 #define PROC_AF 12 #define PROC_LIST 13 #define PROC_KILL 14 #define NB_PROG 20000000 #define NB_VERS 1 struct ligne { char *nom; int tel; }; struct Noeud { char *nom; int tel; struct Noeud * ptr; }; typedef struct ligne ligne; typedef struct Noeud Noeud; extern void * affiche_1(); extern ligne * recherche_1(); extern int * ajout_1(); extern bool_t xdr_ligne(); extern bool_t xdr_noeud(); extern Noeud * lister(); extern void affiche_elt(); extern void * stop_1(); index.c #include <stdio.h> #include "index.h" menu(){ printf ( "\n Menu:\n"); printf ( "1) Rechercher un nom\n"); printf ( "2) Ajouter un nom\n"); printf ( "3) Faire afficher au srv\n"); printf ( "4) lister les noms\n"); printf ( "8) Quiter\n\n"); printf ( "Faites votre choix + Enter: "); } main (int argc, char ** argv) { char *chaine = (char *)malloc(256), telephone[256]; ligne *resultat, nouvelle; Noeud * noeud; menu(); while ( gets(chaine) ) { switch ( chaine[0] ) { [...] case '4': /* Liste de noms... */ printf ( "Liste de(s) nom(s)...\n"); affiche_elt( lister() ); printf ("\n"); break; case '8': /* quitter le client */ exit(0); break; default: printf ("Option non (encore) implémenté..."); } menu(); } } index_clnt.c #include <stdio.h> #include <rpc/types.h> #include <rpc/xdr.h> #include <rpc/clnt.h> #include <string.h> #include "index.h" int d; char nom_machine[] = "localhost"; char liste[256]; struct ligne ligne_retour; struct Noeud noeud_retour; [...] Noeud * lister(){ int rep; if ( ( rep = callrpc(nom_machine,NB_PROG,NB_VERS,PROC_LIST,xdr_void,NULL,xdr_noeud,&noeud_retour) ) != 0) { clnt_perrno(rep); puts("\n"); } } void affiche_elt(Noeud * N) { if ( N != NULL ) { printf("%s %d\n",N->nom,N->tel); affiche_elt( N->ptr ); } } index_svc.c #include <stdio.h> #include <rpc/types.h> #include <rpc/xdr.h> #include <rpc/clnt.h> #include "index.h" main(){ [...] if ( registerrpc(NB_PROG, NB_VERS, PROC_LIST, lister, xdr_void, xdr_noeud) != RPCSUCCESS ) { perror("Echec Recherche"); exit(2); } svc_run(); } index_local.c #include <stdio.h> #include <errno.h> #include <stdlib.h> #include <string.h> #include "index.h" #define NOM_FICHIER "index.data" /* Recherche de la ligne contenant le nom correspondant... */ static ligne entree; static ligne * l = NULL; static char buf[256]; Noeud * ajout; [...] Noeud * lister() { FILE *f; int t; Noeud * tete = NULL; if ((f = fopen (NOM_FICHIER, "r")) == NULL) perror ("svc: fopen "); else { if ( fscanf(f,"%s%d", buf, &t ) > 0 ) { ajout = malloc( sizeof(struct Noeud) ); tete = ajout; ajout->nom = strdup( buf ); ajout->tel = t; while ( fscanf(f,"%s%d", buf, &t ) != EOF ) { ajout->ptr = malloc( sizeof(struct Noeud) ); ajout = ajout->ptr; ajout->nom = strdup( buf ); ajout->tel = t; } } ajout->ptr = NULL; fclose ( f ); } /* DEBUG */ printf("\nListe de(s) nom(s) :\n"); affiche_elt(tete); return tete; } void affiche_elt(Noeud * N) { if ( N != NULL ) { printf("%s %d\n",N->nom,N->tel); affiche_elt( N->ptr ); } } index_xdr.c #include <stdio.h> #include <rpc/types.h> #include <rpc/xdr.h> #include <rpc/rpc.h> #include "index.h" [...] bool_t xdr_noeud(XDR * flot,struct Noeud * n) { return xdr_wrapstring(flot, &n->nom) && xdr_int(flot, &n->tel) && xdr_pointer(flot,(char **)&n->ptr,sizeof(struct Noeud),xdr_noeud); }
Pourtant, j'obtiens ce résultat...
Ma liste de noms est donc correctement créée mais n'est pas ou mal retournée a mon client...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 Client : [Iloyo@localhost XDR-RPC]$ ./index Menu: 1) Rechercher un nom 2) Ajouter un nom 3) Faire afficher au srv 4) lister les noms 8) Quiter Faites votre choix + Enter: 4 Liste de(s) nom(s)... Menu: 1) Rechercher un nom 2) Ajouter un nom 3) Faire afficher au srv 4) lister les noms 8) Quiter Serveur : [root@localhost XDR-RPC]# ./index_svc Liste de(s) nom(s) : toto 5432 titi 3456789 tutu 2345678
quelqu'un aurait-il une explication? une solution??
Merci
Partager