diff --git a/HISTORY b/HISTORY index 865427d..dc410f8 100644 --- a/HISTORY +++ b/HISTORY @@ -1,9 +1,10 @@ -Version 1.22 2015-10-09 +Version 1.22 2015-10-10 * export php function: fastcommon_get_first_local_ip * add function is_private_ip * add function get_next_local_ip * export php function: fastcommon_get_next_local_ip + * export php function: fastcommon_is_private_ip Version 1.21 2015-09-14 * ini_file_reader support annotation function diff --git a/php-fastcommon/fastcommon.c b/php-fastcommon/fastcommon.c index e932a02..b5df63e 100644 --- a/php-fastcommon/fastcommon.c +++ b/php-fastcommon/fastcommon.c @@ -44,6 +44,7 @@ const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, N ZEND_FE(fastcommon_get_line_distance_km, NULL) ZEND_FE(fastcommon_get_first_local_ip, NULL) ZEND_FE(fastcommon_get_next_local_ip, NULL) + ZEND_FE(fastcommon_is_private_ip, NULL) {NULL, NULL, NULL} /* Must be the last line */ }; @@ -335,3 +336,32 @@ ZEND_FUNCTION(fastcommon_get_next_local_ip) RETURN_STRING(next_ip , 1); } +/* +string fastcommon_is_private_ip(string ip) +return true for private ip, otherwise false +*/ +ZEND_FUNCTION(fastcommon_is_private_ip) +{ + int argc; + int ip_len; + char *ip; + + argc = ZEND_NUM_ARGS(); + if (argc != 1) { + logError("file: "__FILE__", line: %d, " + "fastcommon_is_private_ip parameters count: %d is invalid", + __LINE__, argc); + RETURN_BOOL(false); + } + + if (zend_parse_parameters(argc TSRMLS_CC, "s", &ip, + &ip_len) == FAILURE) + { + logError("file: "__FILE__", line: %d, " + "zend_parse_parameters fail!", __LINE__); + RETURN_BOOL(false); + } + + RETURN_BOOL(is_private_ip(ip)); +} + diff --git a/php-fastcommon/fastcommon.h b/php-fastcommon/fastcommon.h index bb7f6ae..8458c3d 100644 --- a/php-fastcommon/fastcommon.h +++ b/php-fastcommon/fastcommon.h @@ -24,6 +24,7 @@ ZEND_FUNCTION(fastcommon_simple_hash); ZEND_FUNCTION(fastcommon_get_line_distance_km); ZEND_FUNCTION(fastcommon_get_first_local_ip); ZEND_FUNCTION(fastcommon_get_next_local_ip); +ZEND_FUNCTION(fastcommon_is_private_ip); #ifdef __cplusplus }