diff --git a/geoip.c b/geoip.c index df523c7..23a2f15 100644 --- a/geoip.c +++ b/geoip.c @@ -47,6 +47,7 @@ zend_function_entry geoip_functions[] = { PHP_FE(geoip_org_by_name, NULL) PHP_FE(geoip_record_by_name, NULL) PHP_FE(geoip_id_by_name, NULL) + PHP_FE(geoip_name_by_addr, NULL) PHP_FE(geoip_region_by_name, NULL) PHP_FE(geoip_isp_by_name, NULL) PHP_FE(geoip_db_avail, NULL) @@ -526,6 +527,36 @@ PHP_FUNCTION(geoip_id_by_name) } /* }}} */ +/* {{{ proto string geoip_name_by_addr( string hostname ) + Returns the Net Speed found in the GeoIP Database */ +PHP_FUNCTION(geoip_name_by_addr) +{ + GeoIP * gi; + char * hostname = NULL; + int arglen; + char * netspeed; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) { + return; + } + + if (GeoIP_db_avail(GEOIP_NETSPEED_EDITION)) { + gi = GeoIP_open_type(GEOIP_NETSPEED_EDITION, GEOIP_STANDARD); + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_NETSPEED_EDITION]); + return; + } + + netspeed = GeoIP_name_by_addr(gi, hostname); + GeoIP_delete(gi); + + if(netspeed == NULL) { + RETURN_FALSE; + } + RETURN_STRING((char*)netspeed, 1); +} +/* }}} */ + /* {{{ proto array geoip_region_by_name( string hostname ) Returns the Country Code and region found in the GeoIP Database */ PHP_FUNCTION(geoip_region_by_name) diff --git a/php_geoip.h b/php_geoip.h index fc07673..1fcb063 100644 --- a/php_geoip.h +++ b/php_geoip.h @@ -54,6 +54,7 @@ PHP_FUNCTION(geoip_continent_code_by_name); PHP_FUNCTION(geoip_org_by_name); PHP_FUNCTION(geoip_record_by_name); PHP_FUNCTION(geoip_id_by_name); +PHP_FUNCTION(geoip_name_by_addr); PHP_FUNCTION(geoip_region_by_name); PHP_FUNCTION(geoip_isp_by_name); PHP_FUNCTION(geoip_db_avail);