From 08fe0c6e015c2c9b2948c6224d4171dfdab6abf0 Mon Sep 17 00:00:00 2001 From: yuqing Date: Wed, 14 Jan 2015 12:58:08 +0800 Subject: [PATCH] support php extension --- php-ext/fastcommon.c | 28 ++++++++++++++++++++++------ php-ext/fastcommon.h | 1 + php-ext/fastcommon.spec.in | 2 +- php-ext/test.php | 5 +++++ 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 php-ext/test.php diff --git a/php-ext/fastcommon.c b/php-ext/fastcommon.c index 2695ba1..7566b0e 100644 --- a/php-ext/fastcommon.c +++ b/php-ext/fastcommon.c @@ -36,6 +36,7 @@ const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, N // Every user visible function must have an entry in fastcommon_functions[]. zend_function_entry fastcommon_functions[] = { ZEND_FE(fastcommon_version, NULL) + ZEND_FE(fastcommon_gethostaddrs, NULL) {NULL, NULL, NULL} /* Must be the last line */ }; @@ -114,9 +115,12 @@ ZEND_FUNCTION(fastcommon_gethostaddrs) char *if_alias_prefix; int if_prefix_len; int count; + int uniq_count; + int i; int k; int alias_count; char ip_addresses[FAST_MAX_LOCAL_IP_ADDRS][IP_ADDRESS_SIZE]; + char *uniq_ips[FAST_MAX_LOCAL_IP_ADDRS]; char *if_alias_prefixes[1]; argc = ZEND_NUM_ARGS(); @@ -137,8 +141,7 @@ ZEND_FUNCTION(fastcommon_gethostaddrs) } - if (if_alias_prefix == NULL || if_prefix_len == 0) - { + if (if_alias_prefix == NULL || if_prefix_len == 0) { alias_count = 0; if_alias_prefixes[0] = NULL; } @@ -148,16 +151,29 @@ ZEND_FUNCTION(fastcommon_gethostaddrs) if_alias_prefixes[0] = if_alias_prefix; } - if (gethostaddrs(if_alias_prefixes, alias_count, ip_addresses, \ + count = 0; + if (gethostaddrs(if_alias_prefixes, alias_count, ip_addresses, FAST_MAX_LOCAL_IP_ADDRS, &count) != 0) { RETURN_BOOL(false); } + uniq_count = 0; + for (k=0; k