def nl_sendmsg(sk, msg, hdr):
if sk.s_fd < <NUM_LIT:0>:<EOL><INDENT>return -NLE_BAD_SOCK<EOL><DEDENT>nlmsg_set_src(msg, sk.s_local)<EOL>cb = sk.s_cb<EOL>if cb.cb_set[NL_CB_MSG_OUT]:<EOL><INDENT>ret = nl_cb_call(cb, NL_CB_MSG_OUT, msg)<EOL>if ret != NL_OK:<EOL><INDENT>return ret<EOL><DEDENT><DEDENT>if hdr.msg_name is None:<EOL><INDENT>address = None<EOL><DEDENT>else:<EOL><INDENT>address = tuple(hdr.msg_name)<EOL>if address == (<NUM_LIT:0>, <NUM_LIT:0>) or address == sk.socket_instance.getsockname:<EOL><INDENT>address = None<EOL><DEDENT><DEDENT>try:<EOL><INDENT>if hdr.msg_control:<EOL><INDENT>ret = sk.socket_instance.sendmsg([hdr.msg_iov], hdr.msg_control, hdr.msg_flags, address)<EOL><DEDENT>elif address:<EOL><INDENT>ret = sk.socket_instance.sendto(hdr.msg_iov, hdr.msg_flags, address)<EOL><DEDENT>else:<EOL><INDENT>ret = sk.socket_instance.send(hdr.msg_iov, hdr.msg_flags)<EOL><DEDENT><DEDENT>except OSError as exc:<EOL><INDENT>return -nl_syserr2nlerr(exc.errno)<EOL><DEDENT>_LOGGER.debug('<STR_LIT>', ret)<EOL>return ret<EOL>
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.