Get the name of the local host. The property <prefix>.localhost overrides <prefix>.localaddress, which overrides what InetAddress would tell us. @return the name of the local host
()
| 652 | * @return the name of the local host |
| 653 | */ |
| 654 | protected synchronized String getLocalHost() { |
| 655 | // get our hostname and cache it for future use |
| 656 | if (localHostName == null || localHostName.length() <= 0) |
| 657 | localHostName = |
| 658 | props.getProperty(prefix + ".localhost"); |
| 659 | if (localHostName == null || localHostName.length() <= 0) |
| 660 | localHostName = |
| 661 | props.getProperty(prefix + ".localaddress"); |
| 662 | try { |
| 663 | if (localHostName == null || localHostName.length() <= 0) { |
| 664 | InetAddress localHost = InetAddress.getLocalHost(); |
| 665 | localHostName = localHost.getCanonicalHostName(); |
| 666 | // if we can't get our name, use local address literal |
| 667 | if (localHostName == null) |
| 668 | // XXX - not correct for IPv6 |
| 669 | localHostName = "[" + localHost.getHostAddress() + "]"; |
| 670 | } |
| 671 | } catch (UnknownHostException uhex) { |
| 672 | } |
| 673 | |
| 674 | // last chance, try to get our address from our socket |
| 675 | if (localHostName == null || localHostName.length() <= 0) { |
| 676 | if (socket != null && socket.isBound()) { |
| 677 | InetAddress localHost = socket.getLocalAddress(); |
| 678 | localHostName = localHost.getCanonicalHostName(); |
| 679 | // if we can't get our name, use local address literal |
| 680 | if (localHostName == null) |
| 681 | // XXX - not correct for IPv6 |
| 682 | localHostName = "[" + localHost.getHostAddress() + "]"; |
| 683 | } |
| 684 | } |
| 685 | if (TextUtils.isEmpty(localHostName)) |
| 686 | localHostName = "localhost"; |
| 687 | return localHostName; |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Is protocol tracing enabled? |
no test coverage detected