協(xié)議處于網(wǎng)絡(luò)層:
macAddr = arp->getMacAddr(netwAddr);
pkt->setControlInfo(new MacControlInfo(macAddr));

協(xié)議處于應(yīng)用層
方法一:手動收集從網(wǎng)絡(luò)層送達(dá)的數(shù)據(jù)包,并用map記錄之
std::map<int, int> nbrNetwAddrs;
?NetwControlInfo* cInfo;
?cInfo = dynamic_cast<NetwControlInfo*> (msg->removeControlInfo());
?nbrNetwAddrs[src] = cInfo->getNetwAddr(); // 記錄鄰居的網(wǎng)絡(luò)層地址

發(fā)送時使用nbrNetwAddrs中的網(wǎng)絡(luò)層地址信息即可

方法二:使用omnet的層次模型直接可以獲得網(wǎng)絡(luò)層地址,但這樣就假定了應(yīng)用層可以通過某種方法獲得網(wǎng)絡(luò)層地址,而協(xié)議并不關(guān)心
?int netwAddr = simulation.getModule(contact)->getParentModule()->getSubmodule("net")->getId();
?pkt->setControlInfo(new NetwControlInfo(netwAddr));