From 229a26a4977cc341cf78a21af5a3ede7532565cb Mon Sep 17 00:00:00 2001 From: Evan Klinger Date: Tue, 2 Nov 1999 03:47:09 +0000 Subject: [PATCH] (PHP getprotoby{name,number}) New Functions @- Implemented getprotoby{name,number} (Evan) --- ext/standard/basic_functions.c | 51 ++++++++++++++++++++++++++++++++++ ext/standard/basic_functions.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index e03d8417a96..25434e3a86f 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -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) diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 996d7e5493d..4ac9eb195df 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -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 {