bugfix: fixed bug in acl_ifconf_search function.

This commit is contained in:
zsx 2017-12-12 16:33:46 +08:00
parent f0c52f92f1
commit c10ef0b4d5
3 changed files with 8 additions and 5 deletions

View File

@ -3,6 +3,7 @@
------------------------------------------------------------------------
616) 2017.12.12
616.1) feature: acl_mbox.c 支持采用 eventfd 句柄进行 IO 通知
616.2) bugfix: acl_ifconf_search 配置地址时有误
615) 2017.12.10
615.1) feature: acl_udp_server.c 支持绑定 UNIX 域套接口

View File

@ -5,7 +5,7 @@ int main(void)
ACL_IFCONF *ifconf; /* 网卡查询结果对象 */
ACL_IFADDR *ifaddr; /* 每个网卡信息对象 */
ACL_ITER iter; /* 遍历对象 */
const char *pattern = "127.*.*.*:8290, 192.168.*.*:8290";
const char *pattern = "127.*.*.*:8290, 192.168.*.*:8290, 172.16.*.*.:8290, 172.17.*.*.:8290";
ACL_ARGV *addrs;
/* 查询本机所有网卡信息 */
@ -32,6 +32,8 @@ int main(void)
printf("acl_ifconf_search error\r\n");
return 1;
}
printf("pattern=%s\r\n", pattern);
acl_foreach(iter, addrs) {
const char *addr = (const char *)iter.data;
printf(">>>ip: %s\r\n", addr);

View File

@ -367,13 +367,13 @@ static unsigned match(const ACL_ARGV *tokens, const char *ip)
return 1;
}
static unsigned search(ACL_IFCONF *ifconf, const char *addr, ACL_ARGV *addrs)
static int search(ACL_IFCONF *ifconf, const char *addr, ACL_ARGV *addrs)
{
ACL_ARGV *tokens = NULL;
char buf[256], *colon;
int port;
ACL_ITER iter;
unsigned naddr = 0;
int naddr = 0;
/* xxx.xxx.xxx.xxx:port, xxx.xxx.xxx.*:port ...*/
snprintf(buf, sizeof(buf), "%s", addr);
@ -388,7 +388,7 @@ static unsigned search(ACL_IFCONF *ifconf, const char *addr, ACL_ARGV *addrs)
tokens = acl_argv_split(buf, ".");
if (tokens->argc != 4) {
acl_argv_free(tokens);
return 0;
return -1; /* not a valid IPV4 addr */
}
acl_foreach(iter, ifconf) {
@ -431,7 +431,7 @@ ACL_ARGV *acl_ifconf_search(const char *pattern)
|| (*addr == ':' && acl_alldig(addr + 1))) {
acl_argv_add(addrs, addr, NULL);
} else if (search(ifconf, addr, addrs) == 0)
} else if (search(ifconf, addr, addrs) == -1)
acl_argv_add(addrs, addr, NULL);
}