示例#1
0
/*****************************************************************************
 函 数 名  : ws__setDnsmasq
 功能描述  : 防火墙设备:配置Dnsmasq
 输入参数  : ws_env         ---- web service执行环境
             dnsmasq        ---- 是否启用DNS代理:dnsmasq
 输出参数  : result         ---- 返回结果
 返 回 值  : ERR_OK         ---- 执行成功
             ws_new_soap_fault---- 执行失败
 -----------------------------------------------------------------------------
 最近一次修改记录:
 修改作者: zhangjiefeng
 修改目的: 生成新函数
 修改日期: 2010年01月19日
*****************************************************************************/
int ws__setDnsmasq(WS_ENV* ws_env, xsd__int dnsmasq, xsd__int* ret)
{
    s32 result = ERROR_SUCCESS;
    s8 *value = NULL;
    CONFIG * cfg = NULL;

    if(1 == dnsmasq)
    {
        result = startdnsmasq();
        value = "enable";
        if(ERROR_SUCCESS != result)
           return ws_send_soap_error(ws_env, "Start dnsmasq failed.");  
    }
    else if(0 == dnsmasq)
    {
        result = stopdnsmasq();
        value = "disable";
        if(ERROR_SUCCESS != result)
           return ws_send_soap_error(ws_env, "Stop dnsmasq failed.");
    }
    cfg = config_load(CFG_DNS_PATH);
    if(NULL == cfg)
    {
        return ws_send_soap_error(ws_env, "Open dns config file failed.");
    }
    cfg = config_setint(cfg, "dnsmasq_switch", dnsmasq);
    config_store(cfg, CFG_DNS_PATH);
    config_free(cfg);
    
    *ret = 0;
    return WS_OK;
}
int main(int argc, char *argv[]) {
	if (argc != 2) {
		fprintf(stderr, "Usage: tether <start|stop>\n");
		return -1;
	}

	// Reading config-files
	readlanconfig();

	// Remove old Logfile
	file_unlink((char*)"/data/data/android.tether.usb/var/tether.log");

	// Open Logfile
	log = fopen ("/data/data/android.tether.usb/var/tether.log","w");

	if (strcmp(argv[1],"start") == 0) {
	 	startint();
	  	startipt();
	  	startipfw();
	  	startdnsmasq();
	}
	else if (strcmp(argv[1],"stop") == 0) {
	    stopdnsmasq();
	    stopint();
	    stopipfw();
	    stopipt();
	}

	if (log != NULL) {
		fclose (log);
	}
	return 0;
}