add function is_loopback_ip

use_iouring
YuQing 2024-03-05 16:28:04 +08:00
parent 226fd0d378
commit f4fef93061
2 changed files with 8 additions and 3 deletions

View File

@ -160,9 +160,7 @@ const char *get_next_local_ip(const char *previous_ip)
IP_ADDRESS_SIZE * g_local_host_ip_count;
for (p=g_local_host_ip_addrs; p<pEnd; p+=IP_ADDRESS_SIZE)
{
if (strcmp(p, LOCAL_LOOPBACK_IPv4) != 0 &&
strcmp(p, LOCAL_LOOPBACK_IPv6) != 0 &&
strcasecmp(p, "fe80::1") != 0)
if (!is_loopback_ip(p))
{
if (found)
{

View File

@ -42,6 +42,13 @@ extern char g_if_alias_prefix[FAST_IF_ALIAS_PREFIX_MAX_SIZE];
void load_local_host_ip_addrs();
bool is_local_host_ip(const char *client_ip);
static inline bool is_loopback_ip(const char *ip_addr)
{
return (strcmp(ip_addr, LOCAL_LOOPBACK_IPv4) == 0 ||
strcmp(ip_addr, LOCAL_LOOPBACK_IPv6) == 0 ||
strcasecmp(ip_addr, "fe80::1") == 0);
}
void stat_local_host_ip(int *ipv4_count, int *ipv6_count);
const char *get_first_local_ip();