A
download NetworkInterface.java
Language: Java
LOC: 74
Project Info
Teaseme Java Virtual Machine(teaseme)
Server: SourceForge
Type: cvs
...sspath\jos\system\net\jeps\
   ARP.java
   ARPPacket.java
   ARPTableEntry.java
   DatagramPacket.java
   DatagramSocket.java
   DummyNetworkInterface.java
   EtherHostDriver.java
   ...etNetworkInterface.java
   EtherPacket.java
   HWAddr.java
   ICMP.java
   ICMPPacket.java
   IllegalRouteException.java
   InetAddress.java
   IP.java
   IPAddr.java
   IPPacket.java
   Main.java
   ...medPacketException.java
   NetworkInterface.java
   NetworkInterfaceCard.java
   NoRouteException.java
   Packet.java
   Protocol.java
   QuoteServerThread.java
   RoutingTableEntry.java
   StackPanic.java
   TCP.java
   UDP.java
   UDPPacket.java
   UDPQueue.java

package jos.system.net.jeps;

/*
 * The Network Interface class unites the basic functionality of all
 * network devices including ethernet cards, loopbacks and
 * dummy devices.
 *
 * NOTE: The protocol list is currently handled with a linked list, but 
 *       this does not yield enough configurational freedom to bind protocols
 *	 differently to different interfaces. Expect a change here.
 */

abstract class NetworkInterface extends Thread
{

  protected boolean blocking;   // Does it use blocking io?
  protected boolean hasARP; 	// Does it use ARP?
  protected boolean up;		// Is the interface up?
  protected IPAddr ipaddr;	// The interface's protocol address.
  protected IPAddr netmask;	// The Netmask.
  protected IPAddr broadcast; 	// Broadcast Address.
  protected Protocol firstProtocol;

  abstract public boolean init();
  abstract Packet readPacket();
  abstract void writeIPPacket(IPAddr dest,IPPacket ipp);
  /* Used in gateway routes. */
  
  NetworkInterface()
  {
    up = false;
    firstProtocol = null;	
  }
  
  public void setIPAddr(IPAddr ipaddr)
  {
    this.ipaddr=ipaddr;
  }
  
  public void addProtocol(Protocol p)
  {
    if (firstProtocol == null)
    { firstProtocol = p; }
    else 
    {
      p.setNextProtocol(firstProtocol);
      firstProtocol = p;
    }
  }
  
  public boolean up()
  {
    start();
    return true;
  }

  public void down()
  {
    up=false;
  }
  
  public void run()
  {
    up=true;
    if (blocking) demux();
  }
  
  /*
   * This method it the "heart" of a blocking io device, as it sits in
   * a loop and demultiplexes all the packets.
   * Non-blocking interrupt-driven or event-driven interfaces will
   * have similar methods. This may/will cause further subclassing
   * at a later point in time.
   */
  
  protected void demux()
  {
    System.out.println("Demuxing!");
    boolean handled;
    Protocol currentProtocol;
    Packet p;
    while (up)
    {
      p = readPacket();  // Block here.
      handled = false;
      currentProtocol = firstProtocol;
      while ((currentProtocol != null) && !handled)
      {
        if (currentProtocol.getProtocolNumber() == p.protocol)
	{
	  currentProtocol.Handle(p);
	  handled = true;
	}
	currentProtocol=currentProtocol.getNextProtocol();
      }
      if (!handled) {System.out.println("Unknown Proto: "+p.protocol);}
    }
  } 
  
  void writeIPPacket(IPPacket ipp)
  {
    writeIPPacket(ipp.dest,ipp);
  }
};


About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us