1

I saw this question but it doesn't seem to apply.

Heres my function which does most the heavy lifting in the client code:

void
database_1(char *host, char *action, char *message)
{
    printf("Action: %s\n", action);
    printf("Message: %s\n", message);
    CLIENT *clnt;
    rpc_args  *result_1;
    //struct rpc_args  action_1_arg;

    //rpc arguments struct to pass to server
    struct rpc_args *args = malloc(sizeof(struct rpc_args));

    char *id = generate_id();
    if (strcmp(action, "GET") == 0) {
        printf("Client: GET request\n");
        strcpy(args->action, action);
        strcpy(args->id, id);
    } else if(strcmp(action, "PUT") == 0) {
        printf("Client: PUT request\n");
        strcpy(args->action, action);
        strcpy(args->id, id);
        strcpy(args->message.content, message);
    }

#ifndef DEBUG
    clnt = clnt_create (host, DATABASE, ASSIGNMENT_7, "udp");
    if (clnt == NULL) {
        clnt_pcreateerror (host);
        exit (1);
    }
#endif  /* DEBUG */

    result_1 = action_1(args, clnt);
    if (result_1 == (rpc_args *) NULL) {
        clnt_perror (clnt, "call failed");
    }
    free(args);
#ifndef DEBUG
    clnt_destroy (clnt);
#endif   /* DEBUG */
}

Here's my output:

./database_client eecslinab3.case.edu GET 
running client, main
Action: GET
Message: (null)
hostname is eecslinab3
The process id is 24697
The unique id is eecslinab324697
Client: GET request
call failed: RPC: Can't encode arguments

Database.x

struct message {
    char content[2000];
};

struct rpc_args {
    char action[20];
    char id[1024];
    struct message message;
};

program DATABASE {
    version ASSIGNMENT_7 {
        rpc_args ACTION(struct rpc_args) = 1;
    } = 1;
} = 0x20fff100;
Community
  • 1
  • 1
Daniel Kobe
  • 9,376
  • 15
  • 62
  • 109
  • What does your XDR look like? Could it something like this post: http://stackoverflow.com/q/29710501/4072843 – Castaglia Apr 28 '16 at 03:33
  • @Castaglia added the file. I think I have the correct number of digits though. – Daniel Kobe Apr 28 '16 at 03:41
  • Your `GET` request doesn't populate the `message.content` field, and since you use `malloc()`, that `message.content` field has random/junk values. Perhaps, for `GET`, `message.content` needs to be explicitly zeroed. – Castaglia Apr 28 '16 at 03:45
  • In the `GET` section, after calling `strcpy(args->action, action)` and `strcpy(args->id, id)`, add `memset(args->message, 0, sizeof(struct message))`. – Castaglia Apr 28 '16 at 03:49
  • @Castaglia I got this error `/usr/include/string.h:65:14: note: expected 'void *' but argument is of type 'struct message'` so I used `&args->action` and then it compiled but Im still getting the same error – Daniel Kobe Apr 28 '16 at 03:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/110454/discussion-between-castaglia-and-daniel-kobe). – Castaglia Apr 28 '16 at 05:32

1 Answers1

1

A friend helped me solve the problem but didn't give me much details about why or how the fix works. Basically I reduced the char array sizes in my struct and it worked. Has something to do with the limit of data you can send over UDP.

struct rpc_args {
    char action[20];
    char id[80];
    char message[80];
};

program DATABASE {
    version ASSIGNMENT_7 {
        rpc_args ACTION(struct rpc_args) = 1;
    } = 1;
} = 0x20fff100;
Daniel Kobe
  • 9,376
  • 15
  • 62
  • 109