Hey, i'm writing a client-server, so far i've got this:

my structure

typedef struct mesg{
  long type;
  pid_t pid;
  char data[64];
} MSG;

the client

int main(int argc, char *argv[]){
  int MSGid, msglen, mpid;
  MSG m;
  
  MSGid = msgget(KEY, 0600);

  while(1){
    memset(&m, 0, MSGLEN + sizeof(long));
    m.type = 1;
    mpid = m.pid = getpid();
    scanf("%s", m.data);
    msglen = strlen(m.data);
    
    if(msglen == 0) break;
    msgsnd(MSGid, &m, MSGLEN, 0);
    printf("send:: %d : %d : %s\n", m.type, m.pid, m.data);
    
    msgrcv(MSGid, &m, MSGLEN, mpid, 0);
    printf("recv:: %d : %d : %s\n", m.type, m.pid, m.data);
  }
  return 0;
}

and the server

int MSGid;
void cleanserv(int sig){
  msgctl(MSGid,IPC_RMID,(struct msqid_ds*)0);
  exit(0);
}

int main(){
  MSG m;
  int i;
  
  MSGid = msgget(KEY, 0600 | IPC_CREAT);
  signal(SIGINT, cleanserv);
  while(1){
    msgrcv(MSGid, &m, MSGLEN, 1, 0);
    printf("recv:: %d : %d : %s\n", m.type, m.pid, m.data);
    i = 0;
    while(m.data[i]){
      if(m.data[i] >= 'a' && m.data[i] <= 'z') m.data[i] -= 32; 
			else if(m.data[i] >= 'A' && m.data[i] <= 'Z') m.data[i] += 32;
      i++;
    }
    m.type = m.pid;
    msgsnd(MSGid, &m, MSGLEN, 0);
    printf("send:: %d : %d : %s\n", m.type, m.pid, m.data);
   }    
}

Now, i'd like to alter this a bit, so that what client sends is iterpreted as a file name by the server. Then server would run "ls" on that file, and send the data about it back to client.
So, i thought i'd go with

execv("ls", "-l", "m.data", NULL));

right after msgrcv(). Now, how do i send the output of the "ls" back to client?

Ah, pipes = I'm lost :/
I should read the output of the "ls" or w/e with the popen(), put it in a string/char and then send it, but how? Can I send simple strings with "msgsnd"? Usually I'm sending &<struct>.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.