示例#1
0
/* the real action:
	- increment the forced update times counter
	- detect current IP
		- connect to an HTTP server 
		- parse the response for IP addr

	- for all the names that have to be maintained
		- get the current DYN DNS address from DYN DNS server
		- compare and update if neccessary
*/
RC_TYPE dyn_dns_update_ip(DYN_DNS_CLIENT *p_self)
{
	RC_TYPE rc;

	if (p_self == NULL)
	{
		return RC_INVALID_POINTER;
	}

	do
	{
		/*ask IP server something so he will respond and give me my IP */
		rc = do_ip_server_transaction(p_self);
		if (rc != RC_OK)
		{
			DBG_PRINTF((LOG_WARNING,"W: DYNDNS: Error '%s' (0x%x) when talking to IP server\n",
				errorcode_get_name(rc), rc));
			break;
		}
		if (p_self->dbg.level > 1)
		{
			DBG_PRINTF((LOG_DEBUG,"DYNDNS: IP server response: %s\n", p_self->p_work_buffer));		
		}

		/*extract my IP, check if different than previous one*/
		rc = do_parse_my_ip_address(p_self);
		if (rc != RC_OK)
		{	
			break;
		}
		
		if (p_self->dbg.level > 1)
		{
			DBG_PRINTF((LOG_WARNING,"W: DYNDNS: My IP address: %s\n", p_self->info.my_ip_address.name));		
		}

		/*step through aliases list, resolve them and check if they point to my IP*/
		rc = do_check_alias_update_table(p_self);
		if (rc != RC_OK)
		{	
			break;
		}

		/*update IPs marked as not identical with my IP*/
		rc = do_update_alias_table(p_self);
		if (rc != RC_OK)
		{	
			break;
		}
	}
	while(0);

	return rc;
}
示例#2
0
/** the real action:
    - increment the forced update times counter
    - detect current IP
    - connect to an HTTP server
    - parse the response for IP addr

    - for all the names that have to be maintained
    - get the current DYN DNS address from DYN DNS server
    - compare and update if neccessary
*/
int dyn_dns_update_ip(ddns_t *ctx)
{
	int servernum = 0;	/* server to use for requesting IP */
	/*use server 0 by default, should be always exist */
	int rc;

	if (!ctx)
		return RC_INVALID_POINTER;

	do {
		if (ctx->check_interface) {
			rc = do_ip_check_interface(ctx);
			if (rc != 0)
				break;
		} else {
			/* Ask IP server something so he will respond and give me my IP */
			rc = do_ip_server_transaction(ctx, servernum);
			if (rc != 0)
				break;

			if (ctx->dbg.level > 1) {
				logit(LOG_DEBUG, "IP server response:");
				logit(LOG_DEBUG, "%s", ctx->work_buf);
			}

			/* Extract our IP, check if different than previous one */
			rc = do_parse_my_ip_address(ctx, servernum);
			if (rc != 0)
				break;

			if (ctx->dbg.level > 1)
				logit(LOG_INFO, "Current public IP# %s",
				      ctx->info[servernum].my_ip_address.name);
		}
		/* Step through aliases list, resolve them and check if they point to my IP */
		rc = do_check_alias_update_table(ctx);
		if (rc != 0)
			break;

		/* Update IPs marked as not identical with my IP */
		rc = do_update_alias_table(ctx);
		if (rc != 0)
			break;
	}
	while (0);

	return rc;
}
示例#3
0
文件: dyndns.c 项目: eckyecky/rt-n56u
/** the real action:
    - increment the forced update times counter
    - detect current IP
    - connect to an HTTP server
    - parse the response for IP addr

    - for all the names that have to be maintained
    - get the current DYN DNS address from DYN DNS server
    - compare and update if neccessary
*/
RC_TYPE dyn_dns_update_ip(DYN_DNS_CLIENT *p_self)
{
	int servernum = 0; /* server to use for requesting IP */
		     /*use server 0 by default, should be always exist */
	RC_TYPE rc;

	if (p_self == NULL)
	{
		return RC_INVALID_POINTER;
	}

	do
	{
		if (p_self->check_interface)
		{
			rc = do_ip_check_interface(p_self);
			if (rc != RC_OK)
			{
				break;
			}
		}
		else
		{
			/* Ask IP server something so he will respond and give me my IP */
			rc = do_ip_server_transaction(p_self, servernum);
			if (rc != RC_OK)
			{
				break;
			}
			if (p_self->dbg.level > 1)
			{
				logit(LOG_DEBUG, MODULE_TAG "IP server response:");
				logit(LOG_DEBUG, MODULE_TAG "%s", p_self->p_work_buffer);
			}
	
			/* Extract our IP, check if different than previous one */
			rc = do_parse_my_ip_address(p_self, servernum);
			if (rc != RC_OK)
			{
				break;
			}
	
			if (p_self->dbg.level > 1)
			{
				logit(LOG_INFO, MODULE_TAG "Current public IP# %s", p_self->info[servernum].my_ip_address.name);
			}
		}
		/* Step through aliases list, resolve them and check if they point to my IP */
		rc = do_check_alias_update_table(p_self);
		if (rc != RC_OK)
		{
			break;
		}

		/* Update IPs marked as not identical with my IP */
		rc = do_update_alias_table(p_self);
		if (rc != RC_OK)
		{
			break;
		}
	}
	while (0);

	return rc;
}
示例#4
0
/* the real action:
	- increment the forced update times counter
	- detect current IP
		- connect to an HTTP server 
		- parse the response for IP addr

	- for all the names that have to be maintained
		- get the current DYN DNS address from DYN DNS server
		- compare and update if neccessary
*/
RC_TYPE dyn_dns_update_ip(DYN_DNS_CLIENT *p_self)
{
	RC_TYPE rc = RC_OK;

	if (p_self == NULL)
	{
		return RC_INVALID_POINTER;
	}

	do
	{
		if (nvram_match("ddns_wan_ip","1"))
		{
		char new_ip_str[32];
		int wan_link = check_wan_link(0);
		char *wan_ipaddr = NULL;
		if (nvram_match("wan_proto", "pptp")) {
			wan_ipaddr =
			    wan_link ? nvram_safe_get("pptp_get_ip") :
			    nvram_safe_get("wan_ipaddr");
		} else if (!strcmp(nvram_safe_get("wan_proto"), "pppoe")) {
			wan_ipaddr =
			    wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0";
		} else if (!strcmp(nvram_safe_get("wan_proto"), "3g")) {
			wan_ipaddr =
			    wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0";
		} else if (nvram_match("wan_proto", "l2tp")) {
			wan_ipaddr =
			    wan_link ? nvram_safe_get("l2tp_get_ip") :
			    nvram_safe_get("wan_ipaddr");
		} else if (nvram_match("wan_proto", "disabled")) {
			wan_ipaddr = "0.0.0.0";
		} else {
			wan_ipaddr = nvram_safe_get("wan_ipaddr");
		}
		if (!strcmp(wan_ipaddr,"0.0.0.0")) {
			DBG_PRINTF((LOG_WARNING,"W: DYNDNS: Error: device has no WAN Address\n"));
			rc = RC_ERROR; 
			break;
		    }
		strcpy(new_ip_str,wan_ipaddr);
		p_self->info.my_ip_has_changed = (strcmp(new_ip_str, p_self->info.my_ip_address.name) != 0);
		strcpy(p_self->info.my_ip_address.name, new_ip_str);
		rc = RC_OK;
		}else{
		/*ask IP server something so he will respond and give me my IP */
		rc = do_ip_server_transaction(p_self);
		if (rc != RC_OK)
		{
			DBG_PRINTF((LOG_WARNING,"W: DYNDNS: Error '%s' (0x%x) when talking to IP server\n",
				errorcode_get_name(rc), rc));
			break;
		}
		if (p_self->dbg.level > 1)
		{
			DBG_PRINTF((LOG_DEBUG,"DYNDNS: IP server response: %s\n", p_self->p_work_buffer));		
		}

		/*extract my IP, check if different than previous one*/
		rc = do_parse_my_ip_address(p_self);
		if (rc != RC_OK)
		{	
			break;
		}
		
		}
		if (p_self->dbg.level > 1)
		{
			DBG_PRINTF((LOG_WARNING,"W: DYNDNS: My IP address: %s\n", p_self->info.my_ip_address.name));		
		}
		/*step through aliases list, resolve them and check if they point to my IP*/
		rc = do_check_alias_update_table(p_self);
		if (rc != RC_OK)
		{	
			break;
		}

		/*update IPs marked as not identical with my IP*/
		rc = do_update_alias_table(p_self);
		if (rc != RC_OK)
		{	
			break;
		}
	}
	while(0);

	return rc;
}