예제 #1
0
 /**
  * Create a binding for a local address
  *
  * @param lAddr
  * @param lPort
  */
 public TCPControlBlock bind(IPv4Address lAddr, int lPort) throws BindException {
   return (TCPControlBlock) controlBlocks.bind(lAddr, lPort);
 }
예제 #2
0
  /** @see org.jnode.net.TransportLayer#receive(org.jnode.net.SocketBuffer) */
  public void receive(SocketBuffer skbuf) throws SocketException {

    // Increment stats
    stat.ipackets.inc();

    // Get the IP header
    final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();

    // Read the TCP header
    final TCPHeader hdr = new TCPHeader(skbuf);

    // Set the TCP header in the buffer-field
    skbuf.setTransportLayerHeader(hdr);
    // Remove the TCP header from the head of the buffer
    skbuf.pull(hdr.getLength());
    // Trim the buffer up to the length in the TCP header
    skbuf.trim(hdr.getDataLength());

    if (!hdr.isChecksumOk()) {
      if (DEBUG) {
        if (log.isDebugEnabled()) {
          log.debug("Receive: badsum: " + hdr);
        }
      }
      stat.badsum.inc();
    } else {
      if (DEBUG) {
        if (log.isDebugEnabled()) {
          log.debug("Receive: " + hdr);
        }
      }

      // Find the corresponding control block
      final TCPControlBlock cb =
          (TCPControlBlock)
              controlBlocks.lookup(
                  ipHdr.getSource(),
                  hdr.getSrcPort(),
                  ipHdr.getDestination(),
                  hdr.getDstPort(),
                  true);
      if (cb == null) {
        final boolean ack = hdr.isFlagAcknowledgeSet();
        final boolean rst = hdr.isFlagResetSet();

        stat.noport.inc();

        // Port unreachable
        if (ack && rst) {
          // the source is also unreachable
          log.debug(
              "Dropping segment due to: connection refused as the source is also unreachable");
        } else {
          processPortUnreachable(ipHdr, hdr);
        }
      } else {
        // Let the cb handle the receive
        cb.receive(hdr, skbuf);
      }
    }
  }