title: Sending buffer through message queue
body: <p>Hi I'm writing a program that sends a set of bytes through a message queue like so ...</p>
  
  <pre><code>#include &lt;sys/msg.h&gt;
  #include &lt;stddef.h&gt;
  
  key_t key;
  int msqid;
  struct pirate_msgbuf pmb = {2, { "L'Olonais", 'S', 80, 10, 12035 } };
  
  key = ftok("/home/beej/somefile", 'b');
  msqid = msgget(key, 0666 | IPC_CREAT);
  
  /* stick him on the queue */
  msgsnd(msqid, &amp;pmb, sizeof(struct pirate_msgbuf) - sizeof(long), 0);
  </code></pre>
  
  <p>The above example is a simple program from beejs website that resembles mine.</p>
  
  <p>What I'm doing however is sending a message with a struct like so ...</p>
  
  <pre><code>struct msg_queue{
  
      long message_type;
      char * buffer;
  
  }
  </code></pre>
  
  <p>Now before I send my msg_queue, I created some alternative buffer that contains all sorts of information including null characters and such. Now when I do something like this ...</p>
  
  <pre><code>struct msg_queue my_queue;
  my_queue.message_type = 1;
  my_queue.buffer = "My message";
  msgsnd(mysqid, &amp;pmb, sizeof(struct msg_queue) - sizeof(long), 0);
  </code></pre>
  
  <p>I have no problems receiving the pointer and reading the values stored at that string. However if I were to do something similar like ...</p>
  
  <pre><code>struct msg_queue my_queue;
  my_queue.message_type = 1;
  my_queue.buffer = sum_buffer_with_lots_of_weird_values; // of type char *
  msgsnd(mysqid, &amp;pmb, sizeof(struct msg_queue) - sizeof(long), 0);
  </code></pre>
  
  <p>The pointer I pass through my queue to my other process will read garbage and not the values stored. I tried making my arbitrary array as a static char *, but that doesn't help either. How do I properly pass in my buffer through the queue? Thanks.</p>