HBase might crash when the network card has a IPv6 address
In order to avoid the problem,
I modify a method in class: org.apache.hadoop.net.DNS

The following is the modified code of this method, it would not return IPv6
address now.

/**
   * Returns all the IPs associated with the provided interface, if any, in
   * textual form.
   * 
   * @param strInterface
   *            The name of the network interface to query (e.g. eth0)
   * @return A string vector of all the IPs associated with the provided
   *         interface
   * @throws UnknownHostException
   *             If an UnknownHostException is encountered in querying the
   *             default interface
   * 
   */
  public static String[] getIPs(String strInterface)
  throws UnknownHostException {
            try {
              NetworkInterface netIF = NetworkInterface.getByName(strInterface);
              if (netIF == null)
                return new String[] { InetAddress.getLocalHost()
                                      .getHostAddress() };
              else {
                Vector<String> ips = new Vector<String>();
                Enumeration e = netIF.getInetAddresses();
                while (e.hasMoreElements())
                                                {
                        String addr=((InetAddress) 
e.nextElement()).getHostAddress();
                        if(addr.length()<=15)//only when it is a IPv4 address
                                ips.add(addr);
                        //ips.add(((InetAddress) 
e.nextElement()).getHostAddress());
                                                }
                return ips.toArray(new String[] {});
              }
            } catch (SocketException e) {
              return new String[] { InetAddress.getLocalHost().getHostAddress() 
};
            }
  }

Reply via email to