Transmit Netlink message using socket.sendmsg|sendto|send().

    https://github.com/thom311/libnl/blob/libnl3_2_25/lib/nl.c#L299

    Transmits the message specified in `hdr` over the Netlink socket using Python's socket.sendmsg().

    ATTENTION: The `msg` argument will *not* be used to derive the message payload that is being sent out. The `msg`
    argument is *only* passed on to the `NL_CB_MSG_OUT` callback. The caller is responsible to initialize the `hdr`
    struct properly and have it point to the message payload and socket address.

    This function uses `nlmsg_set_src()` to modify the `msg` argument prior to invoking the `NL_CB_MSG_OUT` callback to
    provide the local port number.

    This function triggers the `NL_CB_MSG_OUT` callback.

    ATTENTION: Think twice before using this function. It provides a low level access to the Netlink socket. Among other
    limitations, it does not add credentials even if enabled or respect the destination address specified in the `msg`
    object.

    Positional arguments:
    sk -- Netlink socket (nl_sock class instance).
    msg -- Netlink message to be sent (nl_msg class instance).
    hdr -- sendmsg() message header (msghdr class instance).

    Returns:
    Number of bytes sent on success or a negative error code.

def nl_sendmsg(sk, msg, hdr):
    """Transmit Netlink message using socket.sendmsg|sendto|send().

    https://github.com/thom311/libnl/blob/libnl3_2_25/lib/nl.c#L299

    Transmits the message specified in `hdr` over the Netlink socket using Python's socket.sendmsg().

    ATTENTION: The `msg` argument will *not* be used to derive the message payload that is being sent out. The `msg`
    argument is *only* passed on to the `NL_CB_MSG_OUT` callback. The caller is responsible to initialize the `hdr`
    struct properly and have it point to the message payload and socket address.

    This function uses `nlmsg_set_src()` to modify the `msg` argument prior to invoking the `NL_CB_MSG_OUT` callback to
    provide the local port number.

    This function triggers the `NL_CB_MSG_OUT` callback.

    ATTENTION: Think twice before using this function. It provides a low level access to the Netlink socket. Among other
    limitations, it does not add credentials even if enabled or respect the destination address specified in the `msg`
    object.

    Positional arguments:
    sk -- Netlink socket (nl_sock class instance).
    msg -- Netlink message to be sent (nl_msg class instance).
    hdr -- sendmsg() message header (msghdr class instance).

    Returns:
    Number of bytes sent on success or a negative error code.
    """
    if sk.s_fd < 0:
        return -NLE_BAD_SOCK
    nlmsg_set_src(msg, sk.s_local)
    cb = sk.s_cb
    if cb.cb_set[NL_CB_MSG_OUT]:
        ret = nl_cb_call(cb, NL_CB_MSG_OUT, msg)
        if ret != NL_OK:
            return ret

    if hdr.msg_name is None:
        address = None
    else:
        address = tuple(hdr.msg_name)
        if address == (0, 0) or address == sk.socket_instance.getsockname:
            address = None

    try:
        if hdr.msg_control:
            ret = sk.socket_instance.sendmsg([hdr.msg_iov], hdr.msg_control, hdr.msg_flags, address)
        elif address:
            ret = sk.socket_instance.sendto(hdr.msg_iov, hdr.msg_flags, address)
        else:
            ret = sk.socket_instance.send(hdr.msg_iov, hdr.msg_flags)
    except OSError as exc:
        return -nl_syserr2nlerr(exc.errno)

    _LOGGER.debug('sent %d bytes', ret)
    return ret