PROCESS_THREAD(test, ev, data) { static struct etimer et; PROCESS_BEGIN(); myaddr = init_l2addr_154_char("45:67"); l2 = startL2_154( myaddr, CHANNEL, PANID); dest = l2addr_154_broadcast; setMTU(l2, MTU); while(1) { test_send (l2, dest) ; test_recv (l2) ; printf("\n"); printf("*************************************************************************"); printf("\n"); etimer_set(&et,5*CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); } PROCESS_END(); }
devEthernet::devEthernet(const std::string& newName /* = "" */, const CE_DLL* newDLLPtr /* = 0 */): CE_Device(newName, newDLLPtr), _ifaceName(""), _ifaceNameSetting(CEcfg::instance()->getOrAddString(cfgKey("ifaceName"), _ifaceName)), _vendor(""), _model(""), _packetSocket(ACE_INVALID_HANDLE), _netlinkSocket(0), _snapLen(CEcfg::instance()->getOrAddInt(cfgKey("snapLen"), 0)), _activateOnLoad(CEcfg::instance()->getOrAddBool(cfgKey("activateOnLoad"), true)), _noArpSetting(CEcfg::instance()->getOrAddBool(cfgKey("flagNoARP"), false)), _promiscSetting(CEcfg::instance()->getOrAddBool(cfgKey("flagPromisc"), false)) { CEcfg::instance()->getOrAddString(cfgKey("devType")) = "Ethernet"; if ( strcmp(_ifaceNameSetting.c_str(), "") == 0) { MOD_INFO("Getting interface name from Device name (%s).", newName.c_str()); setIfaceName(newName); } else { MOD_INFO("Getting interface name from config file (%s).", _ifaceNameSetting.c_str()); _ifaceName = static_cast<const char*>(_ifaceNameSetting); } if ( ! _ifaceName.empty() ) { if ( isProtected() ) throw IsProtected("Device " + getIfaceName() + " is marked 'protected' and cannot be managed by the CE."); // IOCtlFailed is thrown if there's an error try { _ioctl(SIOCGIFFLAGS, _savedFlags, "Error getting flags for interface " + getIfaceName() + " via SIOCGIFFLAGS: "); } catch (...) { MOD_ERROR("Could not read flags to restore later."); } try { if (getActivateOnLoad()) activate(); } catch (...) { MOD_ERROR("Unable to activate at this time."); } if ( CEcfg::instance()->exists(cfgKey("MTU")) ) setMTU(static_cast<unsigned int>(CEcfg::instance()->get(cfgKey("MTU")))); } if ( getSnapLen() == 0 ) { MOD_DEBUG("Automatically setting snapLen."); setSnapLen(static_cast<int>(getMTU() + 30)); MOD_DEBUG("SnapLen set to %d.", getSnapLen()); } MOD_DEBUG("Connecting netlink socket."); _netlinkSocket = Linux::nl_socket_alloc(); if (Linux::nl_connect(_netlinkSocket, NETLINK_ROUTE) < 0) { ND_ERROR("[%s] Unable to connect netlink socket: %s\n", nl_geterror(errno)); Linux::nl_socket_free(_netlinkSocket); } MOD_DEBUG("Ethernet constructor complete."); }