Exemplo n.º 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
*/
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;
}
Exemplo n.º 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
*/
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;
}