コード例 #1
0
ファイル: DHCPC.java プロジェクト: Darkkey/javaNetSim
  /**
   * This method processes a DHCPC sending by client
   *
   * @param data to send
   * @param server host
   * @param server port
   * @author key
   * @version v0.01
   */
  public void StartDHCPC(String inIface, String WantedIP)
      throws CommunicationException, LowLinkException, InvalidNetworkLayerDeviceException,
          TransportLayerException {
    if (running) {
      Close();
    }

    running = true;
    completed = false;
    iface = inIface;

    Listen();

    DHCPPacket d = new DHCPPacket();
    d.op = 1;
    xid = d.xid;
    d.WantedIP = WantedIP;
    d.ciaddr = mParentStack.getIPAddress(iface);
    d.chaddr = mParentStack.getMACAddress(iface);
    d.msgType = 1;

    if (d.ciaddr == null) {
      d.ciaddr = "";
    }

    String Data = d.toBytes();

    resend = Data;
    resendings = 0;

    LayerInfo protInfo = new LayerInfo(getClass().getName());
    protInfo.setObjectName(mParentStack.getParentNodeName());
    protInfo.setDataType("DHCP client");
    protInfo.setLayer("Application ");
    protInfo.setDescription(
        "Starting DHCP discover process on interface "
            + iface
            + "... Transaction ID is "
            + xid
            + ".");
    Simulation.addLayerInfo(protInfo);

    protInfo = new LayerInfo(getClass().getName());
    protInfo.setObjectName(mParentStack.getParentNodeName());
    protInfo.setDataType("DHCP client");
    protInfo.setLayer("Application ");
    protInfo.setDescription(
        "Sending DHCPDISCOVER packet to 255.255.255.255 with op=1 chaddr='"
            + d.chaddr
            + "' ciaddr='"
            + d.ciaddr
            + "' preferred IP='"
            + WantedIP
            + "'.");
    Simulation.addLayerInfo(protInfo);

    mParentStack.getParentNode().startTimerTask(this, 5000);

    SendData(appSock, "255.255.255.255", 67, Data);
  }