man pages section 9: DDI and DKI Kernel Functions

Exit Print View

Updated: July 2014
 
 

sof_mblk_msghdr(9F)

Name

sof_mblk_msghdr, sof_mblk_create - access and create control messages

Synopsis

#include <sys/sockfilter.h>

boolean_t sof_mblk_msghdr(sof_handle_t hdl, mblk_t *mp,
     struct msghdr *msg, int flags);
mblk_t *sof_mblk_create(sof_handle_t hdl, struct msghdr *msg,
     int flags);

Parameters

hdl

per-socket filter handle

msg

pointer to a message header structure, as defined in socket.h(3HEAD)

mp

pointer to a msgb(9S) structure

flags

either 0 or SOF_MBLK_CMSG

Description

The sof_mblk_msghdr() function is used to obtain message header information from a message block. On success, msg_name will point to a location within the message block containing address information, and msg_namelen will reflect the size of the address. Any changes made to the content pointed to by msg_name will be made to the underlying message block. The content pointed to by msg_control should be treated as opaque data unless SOF_MBLK_CMSG is specified. If SOF_MBLK_CMSG is specified, then the caller must also provide a buffer, pointed to by msg_control, where ancillary data will be stored. msg_controllen is updated on return to reflect the amount of ancillary data. If there is not enough room in the provided buffer to copy out all control data, then none of it will be copied, and MSG_CTRUNC will be set on msg_flags.

The sof_mblk_create() function tries to allocate a message block that is large enough to contain the address and control data provided in the message header, and copies the information into the newly created message block. If SOF_MBLK_CMSG is not specified, then msg_control should either be NULL, or point to the opaque data returned in msg_control by a previous call to sof_mblk_msghdr(). If SOF_MBLK_CMSG is specified, then msg_control points to a buffer containing cmsghdr structures.

Return Values

The sof_mblk_msghdr() function returns B_TRUE if a message header was found, and B_FALSE otherwise.

If successful, sof_mblk_create() returns a pointer to the allocated message block. On failure, sof_mblk_create() returns a null pointer.

Examples

Example 1 Access and modify address information
mblk_t *xx_data_in(sof_handle_t hdl, void *cookie, mblk_t *mp)
{
     xxpriv_t *priv = cookie;
     struct msghdr msg;

     /*
      * Extract name information.  The filter is not interested in
      * control data.
      */
     if (sof_mblk_msghdr(hdl, mp, &msg, 0)) {
         (void) strncpy(msg.msg_name, priv->xx_addr,
             msg.msg_namelen);
     }

     return (mp);
}
Example 2 Update ancillary data
mblk_t *xx_data_in(sof_handle_t hdl, void *cookie, mblk_t *mp)
{
     xxpriv_t *priv = cookie;
     struct msghdr msg;
     char buf[XX_BUFLEN];

     msg.msg_control = buf;
     msg.msg_controllen = sizeof (buf);

     /* Process any ancillary data. */
     if (sof_mblk_msghdr(hdl, mp, &msg, SOF_MBLK_CMSG)) {
         mblk_t *nmp;

         xx_proc_ctrl(&msg);

         /* msghdr has cmsghdr control data. */
         nmp = sof_mblk_create(hdl, &msg, SOF_MBLK_CMSG);
         if (nmp != NULL) {
             nmp->b_cont = mp->b_cont;
             freeb(mp);
             mp = nmp;

         }
     }

     return (mp);
}

Context

The sof_mblk_msghdr() and sof_mblk_create() functions can be called from any context.

Attributes

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Availability
system/kernel
Interface Stability
Uncommitted

See Also

socket.h(3HEAD), attributes(5) , sofop_data_in(9E), sof_inject_data_in(9F), msgb(9S)