Example #1
0
File: main.c Project: 10jschen/acl
/* 单线程 PING 单个地址的函数入口 */
static void ping_main_sync(const char *dest, int npkt)
{
	ACL_DNS_DB* dns_db;
	int   delay = 1;
	const char* ip;

	/* 创建 ICMP 对象 */
	__chat = icmp_chat_create(NULL, 1);

	/* 由域名解析出 IP 地址 */
	dns_db = acl_gethostbyname(dest, NULL);
	if (dns_db == NULL) {
		acl_msg_warn("Can't find domain %s", dest);
		return;
	}

	ip = acl_netdb_index_ip(dns_db, 0);
	if (ip == NULL || *ip == 0)
		acl_msg_fatal("ip invalid");

	/* 开始 PING 一个 IP 地址 */
	if (strcmp(dest, ip) == 0)
		icmp_ping_one(__chat, NULL, ip, npkt, delay, 1);
	else
		icmp_ping_one(__chat, dest, ip, npkt, delay, 1);

	/* 释放 DNS 查询结果 */
	acl_netdb_free(dns_db);

	/* 显示 PING 结果小结 */
	display_res();
}
Example #2
0
File: main.c Project: 10jschen/acl
static void add_ip_list(ICMP_CHAT *chat, const ACL_ARGV *domain_list,
	int npkt, int delay)
{
	ACL_DNS_DB* dns_db;
	const char* ptr;
	int   i, j;
	char *pdomain, *pip;
	ACL_ARGV* ip_list = acl_argv_alloc(10);

	for (i = 0; i < domain_list->argc; i++) {
		dns_db = acl_gethostbyname(domain_list->argv[i], NULL);
		if (dns_db == NULL) {
			acl_msg_warn("Can't find domain %s", domain_list->argv[i]);
			continue;
		}

		for (j = 0; j < acl_netdb_size(dns_db); j++) {
			ptr = acl_netdb_index_ip(dns_db, j);
			if (ptr == NULL)
				continue;
			acl_argv_add(ip_list, domain_list->argv[i], ptr, NULL);
		}
		acl_netdb_free(dns_db);
	}

	for (i = 0; i < ip_list->argc;) {
		pdomain = ip_list->argv[i++];
		pip = ip_list->argv[i++];

		if (strcmp(pdomain, pip) == 0)
			icmp_ping_one(chat, NULL, pip, npkt, delay, 1);
		else
			icmp_ping_one(chat, pdomain, pip, npkt, delay, 1);
	}
}
Example #3
0
File: main.c Project: 10jschen/acl
static void *ping_thread(void *arg)
{
	const char *ip, *dest = (char *) arg;
	ACL_DNS_DB* dns_db;
	int   delay = 1;
	ICMP_CHAT *chat;

	/* 通过域名解析出IP地址 */
	dns_db = acl_gethostbyname(dest, NULL);
	if (dns_db == NULL) {
		acl_msg_warn("Can't find domain %s", dest);
		return (NULL);
	}

	/* 只取出域名第一个 IP 地址 PING */
	ip = acl_netdb_index_ip(dns_db, 0);
	if (ip == NULL || *ip == 0) {
		acl_msg_error("ip invalid");
		acl_netdb_free(dns_db);
		return (NULL);
	}

	/* 创建 ICMP 对象 */
	chat = icmp_chat_create(NULL, 1);

	/* 开始 PING */
	if (strcmp(dest, ip) == 0)
		icmp_ping_one(chat, NULL, ip, __npkt, delay, 1);
	else
		icmp_ping_one(chat, dest, ip, __npkt, delay, 1);
	acl_netdb_free(dns_db);  /* 释放域名解析对象 */
	display_res2(chat);  /* 显示 PING 结果 */
	icmp_chat_free(chat);  /* 释放 ICMP 对象 */
	return (NULL);
}
Example #4
0
	virtual void run(ipc_client* ipc)
	{
		ACL_DNS_DB* db = acl_gethostbyname(domain_.c_str(), NULL);
		data_.res = NEW dns_res(domain_.c_str());

		if (db != NULL)
		{
			ACL_ITER iter;
			acl_foreach(iter, db)
			{
				ACL_HOSTNAME* hn = (ACL_HOSTNAME*) iter.data;
				data_.res->ips_.push_back(hn->ip);
			}
Example #5
0
bool pop3_client::get_ip()
{
	ACL_DNS_DB* dns_db = acl_gethostbyname(pop3_addr_.c_str(), NULL);
	if (dns_db == NULL)
	{
		logger_error("gethostbyname(%s) failed", pop3_addr_.c_str());
		return false;
	}
	const char* first_ip = acl_netdb_index_ip(dns_db, 0);
	if (first_ip == NULL || *first_ip == 0)
	{
		logger_error("no ip for domain: %s", pop3_addr_.c_str());
		acl_netdb_free(dns_db);
		return false;
	}
	pop3_ip_ = first_ip;
	acl_netdb_free(dns_db);
	return true;
}
Example #6
0
		/* 显示 PING 的结果总结 */
		icmp_stat(chat);
		printf(">>>max pkts: %d\r\n", icmp_chat_seqno(chat));
	}
}

/* PING 线程入口 */
static void fiber_ping(ACL_FIBER *fiber acl_unused, void *arg)
{
	const char *dest = (const char *) arg;
	ACL_DNS_DB* dns_db;
	const char *ip;
	ICMP_CHAT *chat;

	/* 通过域名解析出IP地址 */
	dns_db = acl_gethostbyname(dest, NULL);
	if (dns_db == NULL) {
		acl_msg_warn("Can't find domain %s", dest);
		return;
	}

	/* 只取出域名第一个 IP 地址 PING */
	ip = acl_netdb_index_ip(dns_db, 0);
	if (ip == NULL || *ip == 0) {
		acl_msg_error("ip invalid");
		acl_netdb_free(dns_db);
		return;
	}

	/* 创建 ICMP 对象 */
	chat = icmp_chat_create(NULL, 1);