禁用ARP

作者: 小超超爱超超 | 来源:发表于2017-11-01 17:32 被阅读0次
    参考一

    PopulateArpCache ()

    {

    Ptr arp = CreateObject ();

    arp->SetAliveTimeout (Seconds(3600 * 24 * 365));

    for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)

    {

    Ptr ip = (*i)->GetObject ();

    // NS_ASSERT(ip !=0);

    ObjectVectorValue interfaces;

    ip->GetAttribute("InterfaceList", interfaces);

    for(ObjectVectorValue::Iterator j = interfaces.Begin(); j != interfaces.End (); j ++)

    {

    Ptr ipIface = (*j)->GetObject ();

    // NS_ASSERT(ipIface != 0);

    Ptr device = ipIface->GetDevice();

    // NS_ASSERT(device != 0);

    Mac48Address addr = Mac48Address::ConvertFrom(device->GetAddress());

    for(uint32_t k = 0; k < ipIface->GetNAddresses (); k ++)

    {

    Ipv4Address ipAddr = ipIface->GetAddress (k).GetLocal();

    if(ipAddr == Ipv4Address::GetLoopback())

    continue;

    ArpCache::Entry * entry = arp->Add(ipAddr);

    entry->MarkWaitReply(0);

    entry->MarkAlive(addr);

    }

    }

    }

    for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i)

    {

    Ptr ip = (*i)->GetObject ();

    NS_ASSERT(ip !=0);

    ObjectVectorValue interfaces;

    ip->GetAttribute("InterfaceList", interfaces);

    for(ObjectVectorValue::Iterator j = interfaces.Begin(); j != interfaces.End (); j ++)

    {

    Ptr ipIface = (*j)->GetObject ();

    ipIface->SetAttribute("ArpCache", PointerValue(arp));

    }

    }

    }

    相关文章

      网友评论

          本文标题:禁用ARP

          本文链接:https://www.haomeiwen.com/subject/ilmgpxtx.html