Exemplo n.º 1
0
ACE_HANDLE devEthernet::openSocket() {
	MOD_DEBUG("Initializing packet socket.");
	checkProtection("initialize packet socket");

	ACE_HANDLE packetSocketFd = ACE_OS::socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

	if ( packetSocketFd < 0 ) {
		MOD_ERROR("openSocket(): socket() error: %s.", ACE_OS::strerror(errno));
		return ACE_INVALID_HANDLE;
	}

	sockaddr_ll skAddr;
	socklen_t sockaddr_ll_len = sizeof(struct sockaddr_ll);
	skAddr.sll_family = AF_PACKET;
	skAddr.sll_protocol = htons(ETH_P_ALL);
	skAddr.sll_ifindex = index();

	if ( ACE_OS::bind(packetSocketFd, (struct sockaddr*) &skAddr, sockaddr_ll_len) < 0 ) {
		MOD_ERROR("openSocket(): bind() error: %s.", ACE_OS::strerror(errno));
		return ACE_INVALID_HANDLE;
	}

	MOD_DEBUG("Socket successfully bound.");

	return (_packetSocket = packetSocketFd);
}
Exemplo n.º 2
0
void devEthernet::activate(const bool setupSocket /* = true */, const bool setFlags /* = true */) {
	ACE_TRACE("devEthernet::activate");
	MOD_DEBUG("Activating interface %s.", getIfaceName().c_str());

	checkProtection("activate");

	if ( _checkFlag(up) ) {
		MOD_WARNING("devEthernet::activate(): Device is already up.");
	}
	else {
		_setFlag(up, true); // IOCtlFailed is thrown if there's an error

		if ( ! _checkFlag(up) )
			throw OperationFailed("Failed to activate network interface " + getIfaceName() + ".");
	}

	if (setupSocket) openSocket();

	if (setFlags) _applyFlagsFromSettings();

	/*
	if ( static_cast<bool>(_promiscSetting) ) enablePromiscuous();
	else disablePromiscuous();

	if ( static_cast<bool>(_noArpSetting) ) disableARP();
	else enableARP();
	*/

}
Exemplo n.º 3
0
void printFunctions(std::wstringstream& str,const UDT::Functions& functions,int depth,CV_access_e& protection)
{
  for(UDT::Functions::const_iterator it = functions.begin(); it != functions.end(); ++it)
  {
    std::wstring name = it->getName();
    if(!name.empty())
    {
      str << checkProtection(it->protection(),protection,depth);
      printDepth(str,depth+1);
      if(it->reservedName())
        str << L"// ";
      if(it->isCompilerGenerated())
        str << L"/* compiler generated */ ";
      if(it->isStatic())
        str << L"static ";
      if(it->isVirtual())
        str << L"virtual ";
      str << it->returnType() << L" ";
      str << it->callingConvention();
      str << name;
      str << L"(";
      std::list<std::wstring> args = it->getArgs();
      bool first = true;
      for(std::list<std::wstring>::iterator it2 = args.begin(); it2 != args.end(); ++it2)
      {
        if(!first)str << L", ";
        first = false;
        str << *it2;
      }
      str << L")";
      if(it->isPure())
        str << L" = 0";
      if(it->isConst())
        str << L" const";

      unsigned int rva = it->getRVA();
      if(rva)
        str << L" //" << rva;

      std::list<std::wstring> localVars = it->getLocalVars();
      if(localVars.empty())
      {
        str << L";" << std::endl;
      }
      else
      {
        str << L"\n";
        printDepth(str,depth+1);
        str << L"{\n";
        for(std::list<std::wstring>::iterator it3 = localVars.begin(); it3 != localVars.end(); ++it3)
        {
          printDepth(str,depth+2);
          str << *it3 << std::endl;
        }
        printDepth(str,depth+1);
        str << L"}\n";
      }
    }
  }
}
Exemplo n.º 4
0
void devEthernet::deactivate() {
	ACE_TRACE("devEthernet::deactivate");

	if ( ! isInitialized() ) return;

	checkProtection("de-activate");

	closeSocket();

	_setFlag(up, false); // IOCtlFailed is thrown if there's an error

	if ( _checkFlag(up) )
		throw OperationFailed("Failed to deactivate network interface " +
			getIfaceName() + ".");
}
Exemplo n.º 5
0
void printMembers(std::wstringstream& str, const UDT::DataMembers& dataMembers,int depth,CV_access_e& protection)
{
  for(UDT::DataMembers::const_iterator it = dataMembers.begin(); it != dataMembers.end(); ++it)
  {
    str << checkProtection(it->protection(),protection,depth);
    printDepth(str,depth+1);
    if(it->isStatic())
      str << L"static ";
    if(it->pointerToFunction())
    {
      str << it->type() << L";" << std::endl;
    }
    else
    {
      str << it->type() << L" ";
      str << it->getName();
      str << L";" << std::endl;
    }
  }
}
Exemplo n.º 6
0
bool devEthernet::setFlag(const ACE_UINT32 flag, const bool newSetting) {
	ACE_TRACE("devEthernet::setFlag");

	checkProtection("change " + _devEthernetFlagNames[flag] + " flag setting on");
/*
	if ( isNew() )
		throw IsUnitialized("Cannot change " + _devEthernetFlagNames[flag] +
			" flag setting on uninitialized interface " +
			getIfaceName() + ".");

	if ( ! isUp() )
		throw IsDown("Cannot change " + _devEthernetFlagNames[flag] +
			" flag on deactivated interface " +	getIfaceName() + ".");
*/
	_setFlag(flag, newSetting);

	// Put the change in the configuration.
	CEcfg::instance()->getOrAddBool(cfgKey("flag" + _devEthernetFlagNames[flag]), newSetting );

	return _checkFlag(flag);
}