How can I print a string received as XDR?

367 views Asked by At

I have a client and a server which communicate eache other with a socket using the XDR notation. Unix environment. The server send a string to client correctly (I checked the number of bytes sended, it is correct), the client receive the string but it is not correct, because the printf print NULL.

Code server: b is a (char **)

xdrmem_create (&xdrs_w, buffer, MAXBUFL, XDR_ENCODE);
xdr_string(&xdrs_w, &b, 32);
strcpy(b, "ciaociao");
printf("I am sending: %s\n", b);
Writen (socketID2, b, strlen(b));
xdr_destroy(&xdrs_w);

Instead, this is the client code:

xdrmem_create(&xdrs_r, buffer, MAXBUFL, XDR_DECODE);
Read (socketID, buffer, 8);    
xdr_string(&xdrs_r, &bf, 32);
buffer[8]='\0';
printf("Result: %s\n",bf);  /NULL?!?!
xdr_destroy(&xdrs_r);

Any idea? Thank you in advice

0

There are 0 answers