code: def close_multicast_socket(sock, address):
      
      if sock is None:
          return
  
      if address:
          # Prepare the mreq structure to join the group
          mreq = make_mreq(sock.family, address)
  
          # Quit group
          if sock.family == socket.AF_INET:
              # IPv4
              sock.setsockopt(socket.IPPROTO_IP, socket.IP_DROP_MEMBERSHIP, mreq)
  
          elif sock.family == socket.AF_INET6:
              # IPv6
              sock.setsockopt(ipproto_ipv6(), socket.IPV6_LEAVE_GROUP, mreq)
  
      # Close the socket
      sock.close()
docs: Cleans up the given multicast socket.
      Unregisters it of the multicast group.
  
      Parameters should be the result of create_multicast_socket
  
      :param sock: A multicast socket
      :param address: The multicast address used by the socket