<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_socket_add_memberships(sk, *group):
 """Join groups. https://github.com/thom311/libnl/blob/libnl3_2_25/lib/socket.c#L417 Joins the specified groups using the modern socket option. The list of groups has to be terminated by 0. Make sure to use the correct group definitions as the older bitmask definitions for nl_join_groups() are likely to still be present for backward compatibility reasons. Positional arguments: sk -- Netlink socket (nl_sock class instance). group -- group identifier (integer). Returns: 0 on success or a negative error code. """

    if sk.s_fd == -1:
        return -NLE_BAD_SOCK
    for grp in group:
        if not grp:
            break
        if grp < 0:
            return -NLE_INVAL
        try:
            sk.socket_instance.setsockopt(SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, grp)
        except OSError as exc:
            return -nl_syserr2nlerr(exc.errno)
    return 0