Exemplo n.º 1
0
Arquivo: net.c Projeto: DomChey/ptpd
static Boolean getInterfaceInfo(char* ifaceName, InterfaceInfo* ifaceInfo)
{

    int res;

    res = interfaceExists(ifaceName);

    if (res == -1) {

	return FALSE;

    } else if (res == 0) {

	ERROR("Interface %s does not exist.\n", ifaceName);
	return FALSE;
    }

    res = getInterfaceAddress(ifaceName, ifaceInfo->addressFamily, &ifaceInfo->afAddress);

    if (res == -1) {

	return FALSE;

    }

    ifaceInfo->hasAfAddress = res;

    res = getHwAddress(ifaceName, (unsigned char*)ifaceInfo->hwAddress, 6);

    if (res == -1) {

	return FALSE;

    }

    ifaceInfo->hasHwAddress = res;

    res = getInterfaceFlags(ifaceName, &ifaceInfo->flags);

    if (res == -1) {

	return FALSE;

    }

    return TRUE;

}
Exemplo n.º 2
0
void ScriptingSystem::addInterface(const std::string& name, const IScriptInterfacePtr& iface) {
	// Check if exists
	if (interfaceExists(name)) {
		rError() << "Cannot add script interface " << name
			<< ", this interface is already registered." << std::endl;
		return;
	}

	// Try to insert
	_interfaces.push_back(NamedInterface(name, iface));

	if (_initialised) 
	{
		// Add the interface at once, all the others are already added
		iface->registerInterface(PythonModule::GetModule(), PythonModule::GetGlobals());
	}
}
int MultiRouterController::doMultiRouterCommands(const char *intIface,const char *extIface, bool add) {
    char cmd[255];
    char prop_value[32] ;

  /*
	 property_get("ro.operator.optr", prop_value, NULL);
   	 if(strcmp(prop_value, "op03") != 0 && strcmp(prop_value, "OP03") != 0 )
   	 {
       ALOGE("ERR:Call MultiRouterCommands In No-Orange Building" );
	   return -1;
	 }*/

	ALOGD("doMultiRouterCommands:downstreaminterface: %s, upstreaminterface: %s, add = %d, MultiRouterCount =%d ",intIface,extIface,add,MultiRouterCount );
    if (add == false) {
        if (MultiRouterCount <= 0) {
            int ret = setDefaults();
            if (ret == 0) {
                MultiRouterCount=0;
            }
            return ret;
        }
    }

    if (!interfaceExists(extIface)||!interfaceExists(intIface) ) {
        ALOGE("Invalid interface specified");
        errno = ENODEV;
        return -1;
    }
    
//add table -> add route entry to talbe -> delete  route entry  -> delete table
if (add) {

   snprintf(cmd, sizeof(cmd), "rule %s iif %s table 71",
             (add ? "add" : "del"),intIface);
    if (runIpCmd(cmd)) {
		 ALOGE("run %s fail",cmd );
		 setDefaults();
        MultiRouterCount = 0;
        return -1;
      }
    }
	
    ALOGD("run cmd %s successfully ", cmd);
	
    /*
    snprintf(cmd, sizeof(cmd), "ip route %s default dev %s table 71", (add ? "add" : "del"),
            intIface);
    if (runIpCmd(cmd)) {
        ALOGE("run %s fail",cmd );
        return -1;
    } */
  
  if( ((0 == MultiRouterCount)&& add) ||((1 == MultiRouterCount)&& !add) )
   {
	if (add) {
         snprintf(cmd, sizeof(cmd), "route %s default dev %s table 71",  "add" ,
            extIface);
   
    } else {
              snprintf(cmd, sizeof(cmd), "route flush table 71" );
           }
	 if (runIpCmd(cmd)) {
        ALOGE("run %s fail",cmd );
        setDefaults();
        MultiRouterCount = 0;
        return -1;
      }
   ALOGD(" run cmd %s successfully ", cmd);
   }else
   {
     ALOGD(" skip add default route to 71 "); 
   }


   
   
    if (add) {
        MultiRouterCount++;
    } else {
        MultiRouterCount--;
    }
    return 0;
}