Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.voytechs.jnetstream.primitive.address
Class IpAddress  view IpAddress download IpAddress.java

java.lang.Object
  extended bycom.voytechs.jnetstream.primitive.address.Address
      extended bycom.voytechs.jnetstream.primitive.address.IpAddress

public class IpAddress
extends Address

A Class for storing IP Addresses Currently is only designed to utilize IPv4 (32bit) addresses. Class also contains utility methods for DNS lookups. There are various functions for converting the IP address to a LONG. Why would you want to use a long for storage of an IP address, in my case I store IP address in a database as an UNSIGNED INT, java does not have unsigned numbers so you have to go to next bigger primitive type to store it or do like other implementations do store the address in a byte array.


Field Summary
private  java.lang.String domainname
           
private  java.lang.String hostname
           
private  java.net.InetAddress inetAddress
           
 
Fields inherited from class com.voytechs.jnetstream.primitive.address.Address
address, debug, DEFAULT_NUMBER_BASE, format, separator
 
Constructor Summary
IpAddress(byte[] address)
          Main constructor taking the array of bytes as the address.
IpAddress(java.lang.String hostname)
          Constructor taking a hostname.
 
Method Summary
 java.lang.String getDomainname()
          Do a domain name lookup by use of DNS reverse lookup on the IP addresses
 java.lang.String getHostname()
          Do a DNS lookup on our IP address by use of DNS reverse lookup.
static void main(java.lang.String[] args)
          Test function for IpAddress
 java.lang.String toString()
          Convert to dot notation string representation of the address.
 
Methods inherited from class com.voytechs.jnetstream.primitive.address.Address
AND, AND, byteArrayValue, compare, compare, compareTo, EOR, EOR, equals, getByte, getByte, getRadix, INVERT, INVERT, longToByteArray, OR, OR, parseByteArray, setAddress, setByteArrayAddress, setFormat, setFormat, setRadix, setSeparator, stringValue, toByteArray, toString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inetAddress

private java.net.InetAddress inetAddress

hostname

private java.lang.String hostname

domainname

private java.lang.String domainname
Constructor Detail

IpAddress

public IpAddress(byte[] address)
Main constructor taking the array of bytes as the address. Automatically sets the separator token between '.' and ':' depending on number of bytes in the address. 4 bytes IPv4 address with '.' separator and 32 bytes for IPv6 address with ':' as separator.


IpAddress

public IpAddress(java.lang.String hostname)
          throws java.net.UnknownHostException
Constructor taking a hostname. This is a conveniece constructor which converts the hostname to numerical format internally. Currently only IPv4 addresses can be initialized this way due to java.net library limitations.

Method Detail

getHostname

public java.lang.String getHostname()
Do a DNS lookup on our IP address by use of DNS reverse lookup.


getDomainname

public java.lang.String getDomainname()
Do a domain name lookup by use of DNS reverse lookup on the IP addresses


toString

public java.lang.String toString()
Convert to dot notation string representation of the address. If hostname is known then hostname.domain is returned other wise the appropriate numerical representation of the numerical address is returned as a String.

Overrides:
toString in class Address

main

public static void main(java.lang.String[] args)
Test function for IpAddress