diff --git a/HISTORY b/HISTORY index d6db330..2cdf82f 100644 --- a/HISTORY +++ b/HISTORY @@ -1,9 +1,10 @@ -Version 1.21 2015-09-05 +Version 1.21 2015-09-08 * ini_file_reader support annotation function * correct PTHREAD_MUTEX_ERRORCHECK define * support 32 bit OS * allow_ips support CIDR addresses such as 172.16.12.0/22 + * add function get_first_local_ip Version 1.20 2015-08-06 * add GEO function get_line_distance_km diff --git a/src/local_ip_func.c b/src/local_ip_func.c index d2829fb..024f304 100644 --- a/src/local_ip_func.c +++ b/src/local_ip_func.c @@ -14,6 +14,8 @@ #include "shared_func.h" #include "local_ip_func.h" +#define LOCAL_LOOPBACK_IP "127.0.0.1" + int g_local_host_ip_count = 0; char g_local_host_ip_addrs[FAST_MAX_LOCAL_IP_ADDRS * \ IP_ADDRESS_SIZE]; @@ -83,7 +85,7 @@ void load_local_host_ip_addrs() char *if_alias_prefixes[STORAGE_MAX_ALIAS_PREFIX_COUNT]; int alias_count; - insert_into_local_host_ip("127.0.0.1"); + insert_into_local_host_ip(LOCAL_LOOPBACK_IP); memset(if_alias_prefixes, 0, sizeof(if_alias_prefixes)); if (*g_if_alias_prefix == '\0') @@ -132,3 +134,26 @@ void print_local_host_ip_addrs() printf("\n"); } +const char *get_first_local_ip() +{ + char *p; + char *pEnd; + + if (g_local_host_ip_count == 0) + { + load_local_host_ip_addrs(); + } + + pEnd = g_local_host_ip_addrs + \ + IP_ADDRESS_SIZE * g_local_host_ip_count; + for (p=g_local_host_ip_addrs; p