Changeset 5cd1419 for core


Ignore:
Timestamp:
Feb 28, 2018 5:58:28 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d167b5e
Parents:
f129426e
Message:

Util: Add methods to validate IP addresses

Location:
core/java/src/net/i2p
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/SelfSignedGenerator.java

    rf129426e r5cd1419  
    2929import javax.crypto.spec.DHPublicKeySpec;
    3030import javax.security.auth.x500.X500Principal;
    31 
    32 import org.apache.http.conn.util.InetAddressUtils;
    3331
    3432import static net.i2p.crypto.SigUtil.intToASN1;
     
    579577        for (String n : altNames) {
    580578            int len;
    581             if (InetAddressUtils.isIPv4Address(n))
     579            if (Addresses.isIPv4Address(n))
    582580                len = 4;
    583             else if (InetAddressUtils.isIPv6Address(n))
     581            else if (Addresses.isIPv6Address(n))
    584582                len = 16;
    585583            else
     
    691689        for (String n : altNames) {
    692690            byte[] b;
    693             if (InetAddressUtils.isIPv4Address(n) ||
    694                 InetAddressUtils.isIPv6Address(n)) {
     691            if (Addresses.isIPv4Address(n) ||
     692                Addresses.isIPv6Address(n)) {
    695693                b = Addresses.getIP(n);
    696694                if (b == null)  // shouldn't happen
  • core/java/src/net/i2p/socks/SOCKS4Client.java

    rf129426e r5cd1419  
    1515import java.net.Socket;
    1616
    17 import org.apache.http.conn.util.InetAddressUtils;
    18 
    1917import static net.i2p.socks.SOCKS4Constants.*;
     18import net.i2p.util.Addresses;
    2019
    2120/**
     
    7473            out.writeShort(connPort);
    7574            boolean isIPv4;
    76             if (InetAddressUtils.isIPv4Address(connHostName)) {
     75            if (Addresses.isIPv4Address(connHostName)) {
    7776                isIPv4 = true;
    7877                out.write(InetAddress.getByName(connHostName).getAddress());
    79             } else if (InetAddressUtils.isIPv6Address(connHostName)) {
     78            } else if (Addresses.isIPv6Address(connHostName)) {
    8079                throw new SOCKSException("IPv6 not supported in SOCKS 4");
    8180            } else {
  • core/java/src/net/i2p/socks/SOCKS5Client.java

    rf129426e r5cd1419  
    1515import java.net.Socket;
    1616
    17 import org.apache.http.conn.util.InetAddressUtils;
    18 
    1917import static net.i2p.socks.SOCKS5Constants.*;
     18import net.i2p.util.Addresses;
    2019
    2120/**
     
    153152
    154153            int addressType;
    155             if (InetAddressUtils.isIPv4Address(connHostName))
     154            if (Addresses.isIPv4Address(connHostName))
    156155                addressType = AddressType.IPV4;
    157             else if (InetAddressUtils.isIPv6Address(connHostName))
     156            else if (Addresses.isIPv6Address(connHostName))
    158157                addressType = AddressType.IPV6;
    159158            else
  • core/java/src/net/i2p/util/Addresses.java

    rf129426e r5cd1419  
    344344            try {
    345345                rv = InetAddress.getByName(host).getAddress();
    346                 if (InetAddressUtils.isIPv4Address(host) ||
    347                     InetAddressUtils.isIPv6Address(host)) {
     346                if (isIPAddress(host)) {
    348347                    synchronized (_IPAddress) {
    349348                        _IPAddress.put(host, rv);
     
    380379        }
    381380        if (rv == null) {
    382             if (InetAddressUtils.isIPv4Address(host) ||
    383                 InetAddressUtils.isIPv6Address(host)) {
     381            if (isIPAddress(host)) {
    384382                try {
    385383                    rv = InetAddress.getByName(host).getAddress();
     
    408406        if (host == null)
    409407            return null;
    410         if (InetAddressUtils.isIPv4Address(host) || InetAddressUtils.isIPv6Address(host))
     408        if (isIPAddress(host))
    411409            return getIP(host);
    412410        synchronized(_negativeCache) {
     
    461459        if (host == null)
    462460            return null;
    463         if (InetAddressUtils.isIPv4Address(host) || InetAddressUtils.isIPv6Address(host)) {
     461        if (isIPAddress(host)) {
    464462            byte[] brv = getIP(host);
    465463            if (brv == null)
     
    491489        return null;
    492490    }
     491
     492    /**
     493     *  @since 0.9.34
     494     */
     495    public static boolean isIPv4Address(String host) {
     496        return InetAddressUtils.isIPv4Address(host);
     497    }
     498
     499    /**
     500     *  @since 0.9.34
     501     */
     502    public static boolean isIPv6Address(String host) {
     503        return InetAddressUtils.isIPv6Address(host);
     504    }
     505
     506    /**
     507     *  @return true if either IPv4 or IPv6
     508     *  @since 0.9.34
     509     */
     510    public static boolean isIPAddress(String host) {
     511        return InetAddressUtils.isIPv4Address(host) || InetAddressUtils.isIPv6Address(host);
     512    }
     513
     514
     515
    493516
    494517    //////// IPv6 Cache Utils ///////
Note: See TracChangeset for help on using the changeset viewer.