public static TransportPair getTransportPair()

in kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/ClientUtil.java [115:175]


    public static TransportPair getTransportPair(
            KrbSetting setting, String kdcString) throws KrbException, IOException {
        TransportPair result = new TransportPair();
        int tcpPort = setting.checkGetKdcTcpPort();
        int udpPort = setting.checkGetKdcUdpPort();

        int port = 0;
        String kdc;
        String portStr = null;

        // Explicit IPv6 in []
        if (kdcString.charAt(0) == '[') {
            int pos = kdcString.indexOf(']', 1);
            if (pos == -1) {
                throw new IOException("Illegal KDC: " + kdcString);
            }
            kdc = kdcString.substring(1, pos);
            // with port number
            if (pos != kdcString.length() - 1) {
                if (kdcString.charAt(pos + 1) != ':') {
                    throw new IOException("Illegal KDC: " + kdcString);
                }
                portStr = kdcString.substring(pos + 2);
            }
        } else {
            int colon = kdcString.indexOf(':');
            // Hostname or IPv4 host only
            if (colon == -1) {
                kdc = kdcString;
            } else {
                int nextColon = kdcString.indexOf(':', colon + 1);
                // >=2 ":", IPv6 with no port
                if (nextColon > 0) {
                    kdc = kdcString;
                } else {
                    // 1 ":", hostname or IPv4 with port
                    kdc = kdcString.substring(0, colon);
                    portStr = kdcString.substring(colon + 1);
                }
            }
        }
        if (portStr != null) {
            int tempPort = parsePositiveIntString(portStr);
            if (tempPort > 0) {
                port = tempPort;
            }
        }
        if (port != 0) {
            tcpPort = port;
            udpPort = port;
        }
        if (tcpPort > 0) {
            result.tcpAddress = new InetSocketAddress(
                    kdc, tcpPort);
        }
        if (udpPort > 0) {
            result.udpAddress = new InetSocketAddress(
                    kdc, udpPort);
        }
        return result;
    }