net.sourceforge.jpcap.net
Class IPAddress

java.lang.Object
  extended bynet.sourceforge.jpcap.net.IPAddress

public class IPAddress
extends java.lang.Object

IP address.

This class doesn't store IP addresses. There's a java class for that, and it is too big and cumbersome for our purposes.

This class contains a utility method for extracting an IP address from a big-endian byte array.


Field Summary
static int WIDTH
          The width in bytes of an IP address.
 
Constructor Summary
IPAddress()
           
 
Method Summary
static java.lang.String extract(int offset, byte[] bytes)
          Extract a string describing an IP address from an array of bytes.
static void main(java.lang.String[] args)
          Unit test.
static int random()
          Generate a random IP number between 0.0.0.0 and 255.255.255.255.
static int random(int network, int mask)
          Generate a random IP address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WIDTH

public static final int WIDTH
The width in bytes of an IP address.

See Also:
Constant Field Values
Constructor Detail

IPAddress

public IPAddress()
Method Detail

extract

public static java.lang.String extract(int offset,
                                       byte[] bytes)
Extract a string describing an IP address from an array of bytes.

Parameters:
offset - the offset of the address data.
bytes - an array of bytes containing the IP address.
Returns:
a string of the form "255.255.255.255"

random

public static int random()
Generate a random IP number between 0.0.0.0 and 255.255.255.255.


random

public static int random(int network,
                         int mask)
Generate a random IP address.

Parameters:
network - the network number. i.e. 0x0a000000.
mask - the network mask. i.e. 0xffffff00.
Returns:
a random IP address on the specified network.

main

public static void main(java.lang.String[] args)
Unit test.