add function get_first_local_ip
parent
69c8970e2d
commit
29451eaf49
3
HISTORY
3
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
|
||||
|
|
|
|||
|
|
@ -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<pEnd; p+=IP_ADDRESS_SIZE)
|
||||
{
|
||||
if (strcmp(p, LOCAL_LOOPBACK_IP) != 0)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return LOCAL_LOOPBACK_IP;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ 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);
|
||||
const char *get_first_local_ip();
|
||||
int insert_into_local_host_ip(const char *client_ip);
|
||||
void print_local_host_ip_addrs();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue