0

I have create, with rpcgen, these two file (.h and .c) with my own two structs (the environment is Linux and the programming language is C).

The two structs are these below (this is the .h file):

/*
 * Please do not edit this file.
 * It was generated using rpcgen.
 */

#ifndef _XDRTYPES_H_RPCGEN
#define _XDRTYPES_H_RPCGEN

#include <rpc/rpc.h>


#ifdef __cplusplus
extern "C" {
#endif


struct Request {
    struct {
        u_int data_len;
        float *data_val;
    } data;
    bool_t last;
};
typedef struct Request Request;

struct Response {
    bool_t error;
    float result;
};
typedef struct Response Response;

/* the xdr functions */

#if defined(__STDC__) || defined(__cplusplus)
extern  bool_t xdr_Request (XDR *, Request*);
extern  bool_t xdr_Response (XDR *, Response*);

#else /* K&R C */
extern bool_t xdr_Request ();
extern bool_t xdr_Response ();

#endif /* K&R C */

#ifdef __cplusplus
}
#endif

#endif /* !_XDRTYPES_H_RPCGEN */

In my main I call #include <rpc/rpc.h> and #include "xdrtypes.h".Then I want send a Request message to the server with a socket (s is the file descriptor s = socket(...)):

stream_socket_w = fdopen(s, "w"); 
xdrstdio_create(&xdrs_w, stream_socket_w, XDR_ENCODE);

x.data.data_len = 5;
x.last = 1;
x.data.data_val[0] = 5.3;
x.data.data_val[1] = 2.7;
x.data.data_val[2] = 8.4;
x.data.data_val[3] = 2.9;
x.data.data_val[4] = 1.7;

xdr_Request(&xdrs_w, &x);   
fflush(stream_socket_w);

The problem is that the execution stop at the line xdr_Request(&xdrs_w, &x) and I obtain "Segmentation Fault". Everybody Can Help me please? Thank you very much.

Mat
  • 202,337
  • 40
  • 393
  • 406
user2467899
  • 583
  • 2
  • 6
  • 19

1 Answers1

2

Are you allocating memory for data_val? x.data.data_val = malloc(x.data.data_len * sizeof(float)); Where xdr_Request function is defined? do you have its API?

Nikolai
  • 1,325
  • 12
  • 24