From ba00a3bb12b417f790e9bb1d59aa72643b922818 Mon Sep 17 00:00:00 2001 From: yuqing Date: Tue, 15 Sep 2015 14:56:29 +0800 Subject: [PATCH] export php function: fastcommon_get_first_local_ip --- HISTORY | 3 +++ libfastcommon.spec | 2 +- php-fastcommon/fastcommon.c | 20 ++++++++++++++++++++ php-fastcommon/fastcommon.h | 1 + src/local_ip_func.c | 4 ++-- src/local_ip_func.h | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index ac027a5..8d108bd 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.22 2015-09-15 + * export php function: fastcommon_get_first_local_ip + Version 1.21 2015-09-14 * ini_file_reader support annotation function * correct PTHREAD_MUTEX_ERRORCHECK define diff --git a/libfastcommon.spec b/libfastcommon.spec index d623a64..085ad5c 100644 --- a/libfastcommon.spec +++ b/libfastcommon.spec @@ -2,7 +2,7 @@ %define LibFastcommonDevel libfastcommon-devel Name: libfastcommon -Version: 1.0.21 +Version: 1.0.22 Release: 1%{?dist} Summary: c common functions library extracted from my open source projects FastDFS License: GPL diff --git a/php-fastcommon/fastcommon.c b/php-fastcommon/fastcommon.c index 6a8fffd..621c076 100644 --- a/php-fastcommon/fastcommon.c +++ b/php-fastcommon/fastcommon.c @@ -42,6 +42,7 @@ const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, N ZEND_FE(fastcommon_time33_hash, NULL) ZEND_FE(fastcommon_simple_hash, NULL) ZEND_FE(fastcommon_get_line_distance_km, NULL) + ZEND_FE(fastcommon_get_first_local_ip, NULL) {NULL, NULL, NULL} /* Must be the last line */ }; @@ -274,3 +275,22 @@ ZEND_FUNCTION(fastcommon_get_line_distance_km) RETURN_DOUBLE(get_line_distance_km(lat1, lon1, lat2, lon2)); } +/* +string fastcommon_get_first_local_ip() +return the first local ip +*/ +ZEND_FUNCTION(fastcommon_get_first_local_ip) +{ + int argc; + + argc = ZEND_NUM_ARGS(); + if (argc != 0) { + logError("file: "__FILE__", line: %d, " + "fastcommon_get_first_local_ip parameters count: %d is invalid", + __LINE__, argc); + RETURN_BOOL(false); + } + + RETURN_STRING(get_first_local_ip(), 1); +} + diff --git a/php-fastcommon/fastcommon.h b/php-fastcommon/fastcommon.h index 6f6b973..08ad44b 100644 --- a/php-fastcommon/fastcommon.h +++ b/php-fastcommon/fastcommon.h @@ -22,6 +22,7 @@ ZEND_FUNCTION(fastcommon_gethostaddrs); ZEND_FUNCTION(fastcommon_time33_hash); ZEND_FUNCTION(fastcommon_simple_hash); ZEND_FUNCTION(fastcommon_get_line_distance_km); +ZEND_FUNCTION(fastcommon_get_first_local_ip); #ifdef __cplusplus } diff --git a/src/local_ip_func.c b/src/local_ip_func.c index 024f304..ecb17aa 100644 --- a/src/local_ip_func.c +++ b/src/local_ip_func.c @@ -58,7 +58,7 @@ int insert_into_local_host_ip(const char *client_ip) return 1; } -static void log_local_host_ip_addrs() +void log_local_host_ip_addrs() { char *p; char *pEnd; @@ -113,7 +113,7 @@ void load_local_host_ip_addrs() insert_into_local_host_ip(ip_addresses[k]); } - log_local_host_ip_addrs(); + //log_local_host_ip_addrs(); //print_local_host_ip_addrs(); } diff --git a/src/local_ip_func.h b/src/local_ip_func.h index 57e9eeb..2ad328e 100644 --- a/src/local_ip_func.h +++ b/src/local_ip_func.h @@ -33,6 +33,7 @@ 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 log_local_host_ip_addrs(); void print_local_host_ip_addrs(); #ifdef __cplusplus