public static Inet4Address convertToIpv4(InetAddress value) {
        if (value == null || value instanceof Inet4Address) {
            return (Inet4Address) value;
        }

        byte[] bytes = value.getAddress();
        boolean invalid = false;
        for (int i = 0; i < 10; i++) {
            if (bytes[i] != (byte) 0) {
                invalid = true;
                break;
            }
        }

        if (!invalid) {
            invalid = bytes[10] != 0xFF || bytes[11] != 0xFF;
        }

        if (invalid) {
            throw new IllegalArgumentException("Failed to convert IPv6 to IPv4");
        }

        byte[] addr = new byte[4];
        System.arraycopy(bytes, 12, addr, 0, 4);
        try {
            return (Inet4Address) InetAddress.getByAddress(addr);
        } catch (UnknownHostException e) {
            throw new IllegalArgumentException(e);
        }
    }
Converts IPv6 address to IPv4 address if applicable.

@param value IPv6 address
@return IPv4 address
@throws IllegalArgumentException when failed to convert to IPv4 address
client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/InetAddressConverter.java