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