Rpc

This is a discussion on Rpc within the C Programming forums, part of the General Programming Boards category; I am currently working on a RPC program, and I have it working, but the function (see below) I want ...

  1. #1
    Unregistered
    Guest

    Rpc

    I am currently working on a RPC program, and I have it working, but the function (see below) I want it to be broken up into multiple functions. For each case - I want a function to be called instead. How can I do that?


    char **rpcalls_1_svc(int *req, struct svc_req *arg2)
    {
    int menu_request;
    static char *start;
    char command[20];
    char buffer[100];
    static char buf[10000];
    FILE *fp;
    menu_request = *req;

    switch(menu_request)
    {
    case 1:
    strcpy(command, "date");
    break;
    case 2:
    strcpy(command, "uptime");
    break;
    case 3:
    strcpy(command, "free");
    break;
    case 4:
    strcpy(command, "netstat");
    break;
    case 5:
    strcpy(command, "who");
    break;
    case 6:
    strcpy(command, "ps");
    break;
    default:
    printf("Invalid selection\n");
    } // end switch

    printf("Client requested %s\n", command);

    if((fp = popen(command, "r")) == NULL)
    {
    printf("popen error - exiting\n");
    exit(0);
    }

    bzero((void *) buffer, sizeof(buffer));
    bzero((void *) buf, sizeof(buf));

    start = buf;

    while ((fgets(buffer, 100, fp)) != NULL)
    {
    strcat(buf, buffer);
    bzero((void *) buffer, sizeof(buffer));
    }

    pclose(fp);
    bzero((void *) command, sizeof(command));

    return(&start);
    }


    Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > For each case - I want a function to be called instead.
    I don't get it - you are calling a function - it's strcpy

    Write your own function, and just call it?

    How about
    Code:
    if ( menu_request >= 1 && menu_request <= 6 ) {
        char *cmds[] = { "date", "uptime", "free", "netstat", "who", "ps" };
        strcpy( commands, cmds[menu_request-1] );
    } else {
        printf("Invalid selection\n"); 
        return NULL;
    }
    And what's with all the bzero calls?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RPC concurrent server in C...???
    By mr_m4x in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 11:10 PM
  2. RPC and IOCP tutorial?
    By George2 in forum Windows Programming
    Replies: 1
    Last Post: 07-17-2008, 07:39 PM
  3. Help in RPC please
    By Duckzilla in forum Networking/Device Communication
    Replies: 1
    Last Post: 11-26-2007, 09:54 PM
  4. RPC probe explosion.
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 08-13-2003, 09:08 PM
  5. Rpc
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 11-10-2001, 06:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21