Who sent the message?

QNX SDP8.0Getting Started with the QNX OSDeveloperUser

Often a server will need to know who sent it a message. There are a number of reasons for this.

  • accounting
  • access control
  • context association
  • class of service
  • compatibility
It would be cumbersome (and a security hole) to have the client provide this information with each and every message sent. Therefore, there's a structure filled in by the kernel whenever the MsgReceive() function unblocks because it got a message. This structure is of type struct _msg_info, and contains at least the following:
struct _msg_info
{
    pid_t     pid;
    int32_t   tid;
    int32_t   chid;
    int32_t   scoid;
    int32_t   coid;
    int16_t   priority;
    int16_t   flags;
    ssize64_t msglen;
    ssize64_t srcmsglen;
    ssize64_t dstmsglen;
};

You pass it to the MsgReceive() function as the last argument. If you pass a NULL, then nothing happens. (The information can be retrieved later via the MsgInfo() call, so it's not gone forever!)

Let's look at the fields:

pid, and tid
Process ID, and thread ID of the client.
priority
The priority of the sending thread.
chid, coid
Channel ID that the message was sent to, and the connection ID used.
scoid
Server Connection ID. This is an internal identifier used by the kernel to route the message from the server back to the client. You don't need to know about it, except for the interesting fact that it will be a small integer that uniquely represents the client.
flags
Contains a variety of flag bits, including the following:
msglen
Number of bytes received.
srcmsglen
The length of the source message, in bytes, as sent by the client. This may be greater than the value in msglen, as would be the case when receiving less data than what was sent.
dstmsglen
The length of the client's reply buffer, in bytes.
Page updated: