Logo Search packages:      
Sourcecode: libnl version File versions  Download package

int nl_send ( struct nl_handle *  handle,
struct nl_msg *  msg 
)

Send netlink message.

  • handle Netlink handle
  • msg Netlink message to be sent.
    See also:
    nl_sendmsg()
    Returns:
    Number of characters sent on success or a negative error code.

Definition at line 325 of file nl.c.

References sockaddr_nl::nl_family, and nl_sendmsg().

Referenced by nl_send_auto_complete().

{
      struct sockaddr_nl *dst;
      struct ucred *creds;
      
      struct msghdr hdr = {
            .msg_name = (void *) &handle->h_peer,
            .msg_namelen = sizeof(struct sockaddr_nl),
      };

      /* Overwrite destination if specified in the message itself, defaults
       * to the peer address of the handle.
       */
      dst = nlmsg_get_dst(msg);
      if (dst->nl_family == AF_NETLINK)
            hdr.msg_name = dst;

      /* Add credentials if present. */
      creds = nlmsg_get_creds(msg);
      if (creds != NULL) {
            char buf[CMSG_SPACE(sizeof(struct ucred))];
            struct cmsghdr *cmsg;

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

            cmsg = CMSG_FIRSTHDR(&hdr);
            cmsg->cmsg_level = SOL_SOCKET;
            cmsg->cmsg_type = SCM_CREDENTIALS;
            cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
            memcpy(CMSG_DATA(cmsg), creds, sizeof(struct ucred));
      }

      return nl_sendmsg(handle, msg, &hdr);
}


Generated by  Doxygen 1.6.0   Back to index