(PHP getprotoby{name,number}) New Functions

@- Implemented getprotoby{name,number} (Evan)
This commit is contained in:
Evan Klinger 1999-11-02 03:47:09 +00:00
parent 3ab5606732
commit 229a26a497
2 changed files with 53 additions and 0 deletions

View File

@ -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)

View File

@ -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 {