package i1;

import e1.AbstractC0453a;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import l1.AbstractC0621d;

/* JADX INFO: loaded from: classes.dex */
public final class g {

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    static final InetAddress[] f4458l = AbstractC0453a.c("jcifs.netbios.wins", ",", new InetAddress[0]);

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private static final e f4459m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private static final int f4460n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private static int f4461o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private static final HashMap f4462p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private static final HashMap f4463q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    static final C0548b f4464r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    static final g f4465s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    static final byte[] f4466t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    static g f4467u;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    C0548b f4468a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    int f4469b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    int f4470c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    boolean f4471d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    boolean f4472e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    boolean f4473f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    boolean f4474g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    boolean f4475h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    boolean f4476i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    byte[] f4477j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    String f4478k;

    static final class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        C0548b f4479a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        g f4480b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        long f4481c;

        a(C0548b c0548b, g gVar, long j2) {
            this.f4479a = c0548b;
            this.f4480b = gVar;
            this.f4481c = j2;
        }
    }

    static {
        e eVar = new e();
        f4459m = eVar;
        f4460n = AbstractC0453a.d("jcifs.netbios.cachePolicy", 30);
        f4461o = 0;
        HashMap map = new HashMap();
        f4462p = map;
        f4463q = new HashMap();
        C0548b c0548b = new C0548b("0.0.0.0", 0, null);
        f4464r = c0548b;
        g gVar = new g(c0548b, 0, false, 0);
        f4465s = gVar;
        f4466t = new byte[]{0, 0, 0, 0, 0, 0};
        map.put(c0548b, new a(c0548b, gVar, -1L));
        InetAddress byName = eVar.f4427b0;
        if (byName == null) {
            try {
                try {
                    byName = InetAddress.getLocalHost();
                } catch (UnknownHostException unused) {
                    byName = InetAddress.getByName("127.0.0.1");
                }
            } catch (UnknownHostException unused2) {
            }
        }
        String strH = AbstractC0453a.h("jcifs.netbios.hostname", null);
        if (strH == null || strH.length() == 0) {
            byte[] address = byName.getAddress();
            strH = "JCIFS" + (address[2] & 255) + "_" + (address[3] & 255) + "_" + AbstractC0621d.c((int) (Math.random() * 255.0d), 2);
        }
        C0548b c0548b2 = new C0548b(strH, 0, AbstractC0453a.h("jcifs.netbios.scope", null));
        g gVar2 = new g(c0548b2, byName.hashCode(), false, 0, false, false, true, false, f4466t);
        f4467u = gVar2;
        b(c0548b2, gVar2, -1L);
    }

    g(C0548b c0548b, int i2, boolean z2, int i3) {
        this.f4468a = c0548b;
        this.f4469b = i2;
        this.f4471d = z2;
        this.f4470c = i3;
    }

    static void a(C0548b c0548b, g gVar) {
        int i2 = f4460n;
        if (i2 == 0) {
            return;
        }
        b(c0548b, gVar, i2 != -1 ? System.currentTimeMillis() + ((long) (i2 * 1000)) : -1L);
    }

    static void b(C0548b c0548b, g gVar, long j2) {
        if (f4460n == 0) {
            return;
        }
        HashMap map = f4462p;
        synchronized (map) {
            try {
                a aVar = (a) map.get(c0548b);
                if (aVar == null) {
                    map.put(c0548b, new a(c0548b, gVar, j2));
                } else {
                    aVar.f4480b = gVar;
                    aVar.f4481c = j2;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    static void c(g[] gVarArr) {
        int i2 = f4460n;
        if (i2 == 0) {
            return;
        }
        long jCurrentTimeMillis = i2 != -1 ? System.currentTimeMillis() + ((long) (i2 * 1000)) : -1L;
        synchronized (f4462p) {
            for (int i3 = 0; i3 < gVarArr.length; i3++) {
                try {
                    HashMap map = f4462p;
                    a aVar = (a) map.get(gVarArr[i3].f4468a);
                    if (aVar == null) {
                        g gVar = gVarArr[i3];
                        map.put(gVarArr[i3].f4468a, new a(gVar.f4468a, gVar, jCurrentTimeMillis));
                    } else {
                        aVar.f4480b = gVarArr[i3];
                        aVar.f4481c = jCurrentTimeMillis;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
    }

    private static Object e(C0548b c0548b) {
        HashMap map;
        HashMap map2 = f4463q;
        synchronized (map2) {
            try {
                if (!map2.containsKey(c0548b)) {
                    map2.put(c0548b, c0548b);
                    return null;
                }
                while (true) {
                    map = f4463q;
                    if (!map.containsKey(c0548b)) {
                        break;
                    }
                    try {
                        map.wait();
                    } catch (InterruptedException unused) {
                    }
                }
                g gVarM = m(c0548b);
                if (gVarM == null) {
                    synchronized (map) {
                        map.put(c0548b, c0548b);
                    }
                }
                return gVarM;
            } finally {
            }
        }
    }

    static g g(C0548b c0548b, InetAddress inetAddress) throws UnknownHostException {
        if (c0548b.f4408c == 29 && inetAddress == null) {
            inetAddress = f4459m.f4428c0;
        }
        c0548b.f4409d = inetAddress != null ? inetAddress.hashCode() : 0;
        g gVarM = m(c0548b);
        if (gVarM == null) {
            gVarM = (g) e(c0548b);
            try {
                if (gVarM == null) {
                    try {
                        gVarM = f4459m.b(c0548b, inetAddress);
                    } catch (UnknownHostException unused) {
                        gVarM = f4465s;
                    }
                }
            } finally {
                a(c0548b, gVarM);
                z(c0548b);
            }
        }
        if (gVarM != f4465s) {
            return gVarM;
        }
        throw new UnknownHostException(c0548b.toString());
    }

    public static g[] i(g gVar) throws UnknownHostException {
        String str;
        try {
            g[] gVarArrD = f4459m.d(gVar);
            c(gVarArrD);
            return gVarArrD;
        } catch (UnknownHostException unused) {
            StringBuilder sb = new StringBuilder();
            sb.append("no name with type 0x");
            sb.append(AbstractC0621d.c(gVar.f4468a.f4408c, 2));
            String str2 = gVar.f4468a.f4407b;
            if (str2 == null || str2.length() == 0) {
                str = " with no scope";
            } else {
                str = " with scope " + gVar.f4468a.f4407b;
            }
            sb.append(str);
            sb.append(" for host ");
            sb.append(gVar.n());
            throw new UnknownHostException(sb.toString());
        }
    }

    public static g j(String str) {
        return k(str, 0, null);
    }

    public static g k(String str, int i2, String str2) {
        return l(str, i2, str2, null);
    }

    public static g l(String str, int i2, String str2, InetAddress inetAddress) {
        if (str == null || str.length() == 0) {
            return q();
        }
        if (!Character.isDigit(str.charAt(0))) {
            return g(new C0548b(str, i2, str2), inetAddress);
        }
        char[] charArray = str.toCharArray();
        int i3 = 0;
        int i4 = 0;
        int i5 = 0;
        while (i3 < charArray.length) {
            char c2 = charArray[i3];
            if (c2 < '0' || c2 > '9') {
                return g(new C0548b(str, i2, str2), inetAddress);
            }
            int i6 = 0;
            while (c2 != '.') {
                if (c2 < '0' || c2 > '9') {
                    return g(new C0548b(str, i2, str2), inetAddress);
                }
                i6 = ((i6 * 10) + c2) - 48;
                i3++;
                if (i3 >= charArray.length) {
                    break;
                }
                c2 = charArray[i3];
            }
            if (i6 > 255) {
                return g(new C0548b(str, i2, str2), inetAddress);
            }
            i5 = (i5 << 8) + i6;
            i4++;
            i3++;
        }
        return (i4 != 4 || str.endsWith(".")) ? g(new C0548b(str, i2, str2), inetAddress) : new g(f4464r, i5, false, 0);
    }

    static g m(C0548b c0548b) {
        g gVar;
        if (f4460n == 0) {
            return null;
        }
        HashMap map = f4462p;
        synchronized (map) {
            try {
                a aVar = (a) map.get(c0548b);
                if (aVar != null && aVar.f4481c < System.currentTimeMillis() && aVar.f4481c >= 0) {
                    aVar = null;
                }
                gVar = aVar != null ? aVar.f4480b : null;
            } finally {
            }
        }
        return gVar;
    }

    public static g q() {
        return f4467u;
    }

    public static C0548b r() {
        return f4467u.f4468a;
    }

    public static InetAddress t() {
        InetAddress[] inetAddressArr = f4458l;
        if (inetAddressArr.length == 0) {
            return null;
        }
        return inetAddressArr[f4461o];
    }

    public static boolean w(InetAddress inetAddress) {
        int i2 = 0;
        while (inetAddress != null) {
            InetAddress[] inetAddressArr = f4458l;
            if (i2 >= inetAddressArr.length) {
                break;
            }
            if (inetAddress.hashCode() == inetAddressArr[i2].hashCode()) {
                return true;
            }
            i2++;
        }
        return false;
    }

    static InetAddress y() {
        int i2 = f4461o;
        int i3 = i2 + 1;
        InetAddress[] inetAddressArr = f4458l;
        int i4 = i3 < inetAddressArr.length ? i2 + 1 : 0;
        f4461o = i4;
        if (inetAddressArr.length == 0) {
            return null;
        }
        return inetAddressArr[i4];
    }

    private static void z(C0548b c0548b) {
        HashMap map = f4463q;
        synchronized (map) {
            map.remove(c0548b);
            map.notifyAll();
        }
    }

    void d() throws UnknownHostException {
        if (this.f4468a == f4464r) {
            i(this);
        }
    }

    public boolean equals(Object obj) {
        return obj != null && (obj instanceof g) && ((g) obj).f4469b == this.f4469b;
    }

    void f() throws UnknownHostException {
        if (this.f4476i) {
            return;
        }
        i(this);
    }

    public String h() {
        String str = this.f4468a.f4406a;
        this.f4478k = str;
        int i2 = 0;
        if (!Character.isDigit(str.charAt(0))) {
            switch (this.f4468a.f4408c) {
                case 27:
                case 28:
                case 29:
                    this.f4478k = "*SMBSERVER     ";
                    break;
            }
        } else {
            int length = this.f4478k.length();
            char[] charArray = this.f4478k.toCharArray();
            int i3 = 0;
            while (true) {
                if (i2 >= length) {
                    break;
                }
                int i4 = i2 + 1;
                if (!Character.isDigit(charArray[i2])) {
                    break;
                }
                if (i4 == length && i3 == 3) {
                    this.f4478k = "*SMBSERVER     ";
                    break;
                }
                if (i4 >= length || charArray[i4] != '.') {
                    i2 = i4;
                } else {
                    i3++;
                    i2 += 2;
                }
            }
        }
        return this.f4478k;
    }

    public int hashCode() {
        return this.f4469b;
    }

    public String n() {
        return ((this.f4469b >>> 24) & 255) + "." + ((this.f4469b >>> 16) & 255) + "." + ((this.f4469b >>> 8) & 255) + "." + (this.f4469b & 255);
    }

    public String o() {
        C0548b c0548b = this.f4468a;
        return c0548b == f4464r ? n() : c0548b.f4406a;
    }

    public InetAddress p() {
        return InetAddress.getByName(n());
    }

    public int s() {
        return this.f4468a.f4408c;
    }

    public String toString() {
        return this.f4468a.toString() + "/" + n();
    }

    public boolean u() throws UnknownHostException {
        f();
        return this.f4474g;
    }

    public boolean v() throws UnknownHostException {
        d();
        return this.f4471d;
    }

    public String x() {
        String str = this.f4478k;
        if (str == this.f4468a.f4406a) {
            this.f4478k = "*SMBSERVER     ";
        } else if (str == "*SMBSERVER     ") {
            try {
                g[] gVarArrD = f4459m.d(this);
                C0548b c0548b = this.f4468a;
                if (c0548b.f4408c == 29) {
                    for (g gVar : gVarArrD) {
                        C0548b c0548b2 = gVar.f4468a;
                        if (c0548b2.f4408c == 32) {
                            return c0548b2.f4406a;
                        }
                    }
                    return null;
                }
                if (this.f4476i) {
                    this.f4478k = null;
                    return c0548b.f4406a;
                }
            } catch (UnknownHostException unused) {
                this.f4478k = null;
            }
        } else {
            this.f4478k = null;
        }
        return this.f4478k;
    }

    g(C0548b c0548b, int i2, boolean z2, int i3, boolean z3, boolean z4, boolean z5, boolean z6, byte[] bArr) {
        this.f4468a = c0548b;
        this.f4469b = i2;
        this.f4471d = z2;
        this.f4470c = i3;
        this.f4472e = z3;
        this.f4473f = z4;
        this.f4474g = z5;
        this.f4475h = z6;
        this.f4477j = bArr;
        this.f4476i = true;
    }
}
