Looking for understanding...

From: Date: Fri, 28 Jan 2000 21:47:27 +0000
Subject: Looking for understanding...
Groups: php.dev 
Request: Send a blank email to php-dev+get-15003@lists.php.net to get a copy of this message
If anyone has a minute, could you list some of the more obvious problems with the attached code? It's a simple inet_aton()/inet_ntoa() implementation which accepts and returns strings instead of ints. I've been told that an earlier version was not acceptable, but I've fixed a few things and would like to find out what other sorts of things I should watch out for. Thanks for any help. /* {{{ proto string inet_aton(string ip) Converts an dotted-quad IP address to an Internet number The return value is the string representation of the Internet number to circumvent PHP's lack of a uint type. */ PHP_FUNCTION(inet_aton) { pval *arg; struct in_addr in; char *retstr; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(arg); if (!inet_aton(arg->value.str.val, &in)) { php3_error(E_WARNING, "Given IP address could not be converted to Internet number"); RETURN_FALSE; } retstr = (char *) emalloc( MAX_LENGTH_OF_LONG + 1 ); if ( !retstr ) { RETURN_FALSE; } _php3_sprintf( retstr, "%u", in.s_addr ); RETVAL_STRING( retstr, 1 ); efree( retstr ); } /* }}} */ /* {{{ proto string inet_ntoa(int in) Convert an Internet number to dotted-quad notation. */ PHP_FUNCTION(inet_ntoa) { pval *arg; struct in_addr in; char *retstr; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(arg); in.s_addr = strtod( arg->value.str.val, NULL ); if ( !(retstr = inet_ntoa(in)) ) { php3_error( E_WARNING, "Given Internet Number could not be converted to dotted quad notation" ); RETURN_FALSE; } RETURN_STRING( retstr, 1 ); } /* }}} */ -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.dev (#15003) next »