mirror of
https://github.com/php/php-src.git
synced 2024-11-26 11:23:47 +08:00
(PHP getprotoby{name,number}) New Functions
@- Implemented getprotoby{name,number} (Evan)
This commit is contained in:
parent
3ab5606732
commit
229a26a497
@ -212,6 +212,8 @@ function_entry basic_functions[] = {
|
||||
PHP_FE(mt_getrandmax, NULL)
|
||||
PHP_FE(getservbyname, NULL)
|
||||
PHP_FE(getservbyport, NULL)
|
||||
PHP_FE(getprotobyname, NULL)
|
||||
PHP_FE(getprotobynumber, NULL)
|
||||
PHP_FE(gethostbyaddr, NULL)
|
||||
PHP_FE(gethostbyname, NULL)
|
||||
PHP_FE(gethostbynamel, NULL)
|
||||
@ -3161,6 +3163,55 @@ PHP_FUNCTION(getservbyport)
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ proto int getprotobyname(string name)
|
||||
Returns protocol number associated with name as per /etc/protocols. */
|
||||
PHP_FUNCTION(getprotobyname)
|
||||
{
|
||||
pval **name;
|
||||
struct protoent *ent;
|
||||
|
||||
if(ARG_COUNT(ht) != 1 || getParametersEx(1, &name) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_string_ex(name);
|
||||
|
||||
ent = getprotobyname((*name)->value.str.val);
|
||||
|
||||
if(ent == NULL) {
|
||||
return_value->value.lval = -1;
|
||||
return_value->type = IS_LONG;
|
||||
return;
|
||||
}
|
||||
|
||||
RETURN_LONG(ent->p_proto);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ proto string getprotobynumber(int proto)
|
||||
Returns protocol name associated with protocol number proto. */
|
||||
PHP_FUNCTION(getprotobynumber)
|
||||
{
|
||||
pval **proto;
|
||||
struct protoent *ent;
|
||||
|
||||
if(ARG_COUNT(ht) != 1 || getParametersEx(1, &proto) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_long_ex(proto);
|
||||
|
||||
ent = getprotobynumber((*proto)->value.lval);
|
||||
|
||||
if(ent == NULL)
|
||||
RETURN_FALSE;
|
||||
|
||||
RETURN_STRING(ent->p_name,1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ proto array array_pad(array input, int pad_size, mixed pad_value)
|
||||
Returns a copy of input array padded with pad_value to size pad_size */
|
||||
PHP_FUNCTION(array_pad)
|
||||
|
@ -137,6 +137,8 @@ PHP_FUNCTION(array_pad);
|
||||
|
||||
PHP_FUNCTION(getservbyname);
|
||||
PHP_FUNCTION(getservbyport);
|
||||
PHP_FUNCTION(getprotobyname);
|
||||
PHP_FUNCTION(getprotobynumber);
|
||||
|
||||
#if HAVE_PUTENV
|
||||
typedef struct {
|
||||
|
Loading…
Reference in New Issue
Block a user