1 jls.loader.provide('jls.net.InetAddress');
  2 
  3 jls.loader.requireLibrary('jls_net');
  4 
  5 /**
  6  * @class This class represents an Internet Protocol (IP) address.
  7  */
  8 jls.net.InetAddress = jls.lang.Class.create( /** @lends jls.net.InetAddress.prototype */
  9 {
 10     initialize : function(ip) {
 11         this._ip = ip;
 12         this._name = null;
 13     },
 14     /**
 15      * Returns the raw IP address of this InetAddress object. The result is in network byte order: the highest order byte of the address is in getAddress()[0].
 16      * 
 17      * @returns {Array} The raw IP address of this object.
 18      */
 19     getAddress : function() {
 20         return [];
 21     },
 22     /**
 23      * Returns the IP address string in textual presentation.
 24      * 
 25      * @returns {String} The raw IP address in a string format.
 26      */
 27     getHostAddress : function() {
 28         return this._ip;
 29     },
 30     /**
 31      * Gets the host name for this IP address.
 32      * 
 33      * @returns {String} The host name for this IP address.
 34      */
 35     getHostName : function() {
 36         if (this._name == null) {
 37             this._name = _native.net.getHostName(this._ip);
 38         }
 39         return this._name;
 40     }
 41 });
 42 
 43 Object.extend(jls.net.InetAddress,
 44 {
 45     /**
 46      * Given the name of a host, returns an array of InetAddress.
 47      * 
 48      * @param {String} name The host name or address to lookup.
 49      * @returns {Array} An array of its IP addresses.
 50      */
 51     getAllByName : function(name) {
 52         var result = [];
 53         var all = _native.net.getAllByName(name);
 54         for (var i = 0; i < all.length; i++) {
 55             result.push(new jls.net.InetAddress(all[i]));
 56         }
 57         return result;
 58     },
 59     /**
 60      * Given the address of a host, returns the InetAddress.
 61      * 
 62      * @param {String} addr The address to lookup.
 63      * @returns {jls.net.InetAddress} The InetAddress object.
 64      */
 65     getByAddress : function(addr) {
 66         return new jls.net.InetAddress(addr);
 67     },
 68     /**
 69      * Given the name of a host, returns the InetAddress.
 70      * 
 71      * @param {String} name The host name or address to lookup.
 72      * @returns {jls.net.InetAddress} The InetAddress object.
 73      */
 74     getByName : function(name) {
 75         var all = _native.net.getAllByName(name);
 76         return new jls.net.InetAddress(all[0]);
 77     }
 78 });