cvs: /php4/ext/standard basic_functions.c basic_functions.h

From: Date: Mon, 01 Nov 1999 01:08:22 +0000
Subject: cvs: /php4/ext/standard basic_functions.c basic_functions.h
Groups: php.version4 
Request: Send a blank email to php-version4+get-5816@lists.php.net to get a copy of this message
evan Sun Oct 31 20:08:22 1999 EDT Modified files: /php4/ext/standard basic_functions.c basic_functions.h Log: (PHP getservby{name,port}) New functions. Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.111 php4/ext/standard/basic_functions.c:1.112 --- php4/ext/standard/basic_functions.c:1.111 Wed Oct 27 18:06:05 1999 +++ php4/ext/standard/basic_functions.c Sun Oct 31 20:07:51 1999 @@ -28,6 +28,7 @@ #include <math.h> #include <time.h> #include <stdio.h> +#include <netdb.h> #if HAVE_UNISTD_H #include <unistd.h> #endif @@ -208,7 +209,8 @@ PHP_FE(mt_rand, NULL) PHP_FE(mt_srand, NULL) PHP_FE(mt_getrandmax, NULL) - + PHP_FE(getservbyname, NULL) + PHP_FE(getservbyport, NULL) PHP_FE(gethostbyaddr, NULL) PHP_FE(gethostbyname, NULL) PHP_FE(gethostbynamel, NULL) @@ -3107,10 +3109,54 @@ } /* }}} */ +/* {{{ proto int getservbyname(string service, string protocol) + Returns port associated with service. protocol must be "tcp" or "udp". */ +PHP_FUNCTION(getservbyname) +{ + pval **name,**proto; + struct servent *serv; + + if(ARG_COUNT(ht) != 2 || getParametersEx(2,&name,&proto) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(name); + convert_to_string_ex(proto); + + serv = getservbyname((*name)->value.str.val,(*proto)->value.str.val); + + if(serv == NULL) + RETURN_FALSE; + + RETURN_LONG(ntohs(serv->s_port)); +} +/* }}} */ + +/* {{{ proto string getservbyport(int port, string protocol) + Returns service name associated with port. Protocol must be "tcp" or "udp". */ +PHP_FUNCTION(getservbyport) +{ + pval **port,**proto; + struct servent *serv; + + if(ARG_COUNT(ht) != 2 || getParametersEx(2,&port,&proto) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long_ex(port); + convert_to_string_ex(proto); + + serv = getservbyport(htons((*port)->value.lval),(*proto)->value.str.val); + + if(serv == NULL) + RETURN_FALSE; + + RETURN_STRING(serv->s_name,1); +} +/* }}} */ + /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: - */ + */ Index: php4/ext/standard/basic_functions.h diff -u php4/ext/standard/basic_functions.h:1.26 php4/ext/standard/basic_functions.h:1.27 --- php4/ext/standard/basic_functions.h:1.26 Wed Oct 27 14:30:41 1999 +++ php4/ext/standard/basic_functions.h Sun Oct 31 20:07:51 1999 @@ -29,7 +29,7 @@ */ -/* $Id: basic_functions.h,v 1.26 1999/10/27 18:30:41 thies Exp $ */ +/* $Id: basic_functions.h,v 1.27 1999/11/01 01:07:51 evan Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H @@ -132,6 +132,9 @@ PHP_FUNCTION(array_values); PHP_FUNCTION(array_count_values); PHP_FUNCTION(array_reverse); + +PHP_FUNCTION(getservbyname); +PHP_FUNCTION(getservbyport); #if HAVE_PUTENV typedef struct {

« previous php.version4 (#5816) next »