예제 #1
0
  void Arp::arp_respond(header* hdr_in) {
    debug2("\t IP Match. Constructing ARP Reply\n");

    // Stat increment replies sent
    replies_tx_++;

    // Populate ARP-header
    auto res = static_unique_ptr_cast<PacketArp>(inet_.create_packet(sizeof(header)));
    res->init(mac_, inet_.ip_addr());

    res->set_dest_mac(hdr_in->shwaddr);
    res->set_dest_ip(hdr_in->sipaddr);
    res->set_opcode(H_reply);

    debug2("\t My IP: %s belongs to My Mac: %s\n",
           res->source_ip().str().c_str(), res->source_mac().str().c_str());

    linklayer_out_(std::move(res));
  }
예제 #2
0
  void Arp::arp_respond(header* hdr_in, IP4::addr ack_ip) {
    PRINT("\t IP Match. Constructing ARP Reply\n");

    // Stat increment replies sent
    replies_tx_++;

    // Populate ARP-header
    auto res = static_unique_ptr_cast<PacketArp>(inet_.create_packet());
    res->init(mac_, ack_ip, hdr_in->sipaddr);

    res->set_dest_mac(hdr_in->shwaddr);
    res->set_opcode(H_reply);

    PRINT("\t IP: %s is at My Mac: %s\n",
           res->source_ip().str().c_str(), res->source_mac().str().c_str());

    MAC::Addr dest = hdr_in->shwaddr;
    PRINT("<ARP -> physical> Sending response to %s. Linklayer begin: buf + %i \n",
          dest.str().c_str(), res->layer_begin() - res->buf() );

    linklayer_out_(std::move(res), dest, Ethertype::ARP);
  }