cvs: pear /PECL/netools netools.c netools.php php_netools.h

From: Date: Fri, 13 Dec 2002 10:02:55 +0000
Subject: cvs: pear /PECL/netools netools.c netools.php php_netools.h
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-7870@lists.php.net to get a copy of this message
tal Fri Dec 13 05:02:55 2002 EDT Modified files: /pear/PECL/netools php_netools.h netools.c netools.php Log: - Added netools_ip_to_mac and netools_hostname_to_mac Index: pear/PECL/netools/php_netools.h diff -u pear/PECL/netools/php_netools.h:1.2 pear/PECL/netools/php_netools.h:1.3 --- pear/PECL/netools/php_netools.h:1.2 Thu Dec 12 06:57:34 2002 +++ pear/PECL/netools/php_netools.h Fri Dec 13 05:02:54 2002 @@ -15,7 +15,7 @@ | Author: Tal Peer <tal@php.net> | +----------------------------------------------------------------------+ - $Id: php_netools.h,v 1.2 2002/12/12 11:57:34 tal Exp $ + $Id: php_netools.h,v 1.3 2002/12/13 10:02:54 tal Exp $ */ #ifndef PHP_NETOOLS_H @@ -41,6 +41,8 @@ PHP_MINFO_FUNCTION(netools); PHP_FUNCTION(netools_device_enum); +PHP_FUNCTION(netools_ip_to_mac); +PHP_FUNCTION(netools_hostname_to_mac); PHP_FUNCTION(netools_device); PHP_NAMED_FUNCTION(netools_device_get_mtu); Index: pear/PECL/netools/netools.c diff -u pear/PECL/netools/netools.c:1.5 pear/PECL/netools/netools.c:1.6 --- pear/PECL/netools/netools.c:1.5 Thu Dec 12 07:12:09 2002 +++ pear/PECL/netools/netools.c Fri Dec 13 05:02:54 2002 @@ -15,7 +15,7 @@ | Author: Tal Peer <tal@php.net> | +----------------------------------------------------------------------+ - $Id: netools.c,v 1.5 2002/12/12 12:12:09 tal Exp $ + $Id: netools.c,v 1.6 2002/12/13 10:02:54 tal Exp $ */ #ifdef HAVE_CONFIG_H @@ -36,6 +36,8 @@ /* only general functions here, not class methods */ function_entry netools_functions[] = { PHP_FE(netools_device_enum, NULL) + PHP_FE(netools_ip_to_mac, NULL) + PHP_FE(netools_hostname_to_mac, NULL) {NULL, NULL, NULL} }; /* }}} */ @@ -112,6 +114,101 @@ } /* }}} */ +/* {{{ proto mixed netools_ip_to_mac(string ip [, bool arr]) +*/ +PHP_FUNCTION(netools_ip_to_mac) +{ + int argc = ZEND_NUM_ARGS(); + char *ip = NULL; + long ip_len; + int err; + zend_bool arr = 0; + + if (zend_parse_parameters(argc TSRMLS_CC, "s|b", &ip, &ip_len, &arr) == FAILURE) { + return; + } + + if (!arr) { + lcrzo_eths mac; + + err = lcrzo_eths_init_ips(ip, mac); + if (err == LCRZO_ERR_OKUNRESOLVED) { + RETURN_FALSE; + } else { + RETURN_STRING(mac, 1); + } + } else { + lcrzo_etha mac; + + err = lcrzo_etha_init_ips(ip, mac); + if (err == LCRZO_ERR_OKUNRESOLVED) { + RETURN_FALSE; + } else { + char *hex[6]; + int i = 0; + + array_init(return_value); + while (i <= 5) { + spprintf(&hex[i], 2, "%02X", mac[i]); + add_next_index_string(return_value, hex[i], 0); + i++; + } + } + } +} +/* }}} */ + +/* {{{ proto mixed netools_hostname_to_mac(string hostname [, bool arr]) +*/ +PHP_FUNCTION(netools_hostname_to_mac) +{ + int argc = ZEND_NUM_ARGS(); + char *hs; + long hs_len; + int err; + zend_bool arr = 0; + lcrzo_hs hostname; + + if (zend_parse_parameters(argc TSRMLS_CC, "s|b", &hs, &hs_len, &arr) == FAILURE) { + return; + } + + if (!arr) { + lcrzo_eths mac; + lcrzo_ipl ip; + + lcrzo_hs_init(hs, hostname); + lcrzo_ipl_init_hs(hostname, &ip); + err = lcrzo_eths_init_ipl(ip, mac); + if (err == LCRZO_ERR_OKUNRESOLVED) { + RETURN_FALSE; + } else { + RETURN_STRING(mac, 1); + } + } else { + lcrzo_etha mac; + lcrzo_ipl ip; + + lcrzo_hs_init(hs, hostname); + lcrzo_ipl_init_hs(hostname, &ip); + err = lcrzo_etha_init_ipl(ip, mac); + if (err == LCRZO_ERR_OKUNRESOLVED) { + RETURN_FALSE; + } else { + char *hex[6]; + int i = 0; + + array_init(return_value); + while (i <= 5) { + spprintf(&hex[i], 2, "%02X", mac[i]); + add_next_index_string(return_value, hex[i], 0); + i++; + } + } + } +} +/* }}} */ + /* {{{ proto array netools_device_enum() */ PHP_FUNCTION(netools_device_enum) @@ -299,19 +396,13 @@ char *hex[6]; lcrzo_etha_init_eths(Z_STRVAL_PP(mac), etha); - + + array_init(return_value); while (i <= 5) { spprintf(&hex[i], 2, "%02X", etha[i]); + add_next_index_string(return_value, hex[i], 0); i++; } - - array_init(return_value); - add_next_index_string(return_value, hex[0], 0); - add_next_index_string(return_value, hex[1], 0); - add_next_index_string(return_value, hex[2], 0); - add_next_index_string(return_value, hex[3], 0); - add_next_index_string(return_value, hex[4], 0); - add_next_index_string(return_value, hex[5], 0); } } else { RETURN_NULL(); Index: pear/PECL/netools/netools.php diff -u pear/PECL/netools/netools.php:1.3 pear/PECL/netools/netools.php:1.4 --- pear/PECL/netools/netools.php:1.3 Thu Dec 12 07:03:12 2002 +++ pear/PECL/netools/netools.php Fri Dec 13 05:02:54 2002 @@ -17,5 +17,10 @@ echo $device->get_mask()."\n"; echo $device->get_mac()."\n"; echo "\n"; + echo netools_ip_to_mac($device->get_ip())."\n"; + echo netools_hostname_to_mac($device->get_hostname())."\n"; + var_dump(netools_ip_to_mac($device->get_ip(), true))."\n"; + var_dump(netools_hostname_to_mac($device->get_hostname(), true))."\n"; + echo "\n"; } ?>

« previous php.pear.cvs (#7870) next »