<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def nl_connect(sk, protocol):
 """Create file descriptor and bind socket. https://github.com/thom311/libnl/blob/libnl3_2_25/lib/nl.c#L96 Creates a new Netlink socket using `socket.socket()` and binds the socket to the protocol and local port specified in the `sk` socket object (if any). Fails if the socket is already connected. Positional arguments: sk -- Netlink socket (nl_sock class instance). protocol -- Netlink protocol to use (integer). Returns: 0 on success or a negative error code. """

    flags = getattr(socket, 'SOCK_CLOEXEC', 0)
    if sk.s_fd != -1:
        return -NLE_BAD_SOCK
    try:
        sk.socket_instance = socket.socket(getattr(socket, 'AF_NETLINK', -1), socket.SOCK_RAW | flags, protocol)
    except OSError as exc:
        return -nl_syserr2nlerr(exc.errno)

    if not sk.s_flags & NL_SOCK_BUFSIZE_SET:
        err = nl_socket_set_buffer_size(sk, 0, 0)
        if err < 0:
            sk.socket_instance.close()
            return err

    try:
        sk.socket_instance.bind((sk.s_local.nl_pid, sk.s_local.nl_groups))
    except OSError as exc:
        sk.socket_instance.close()
        return -nl_syserr2nlerr(exc.errno)
    sk.s_local.nl_pid = sk.socket_instance.getsockname()[0]

    if sk.s_local.nl_family != socket.AF_NETLINK:
        sk.socket_instance.close()
        return -NLE_AF_NOSUPPORT

    sk.s_proto = protocol
    return 0