Project

General

Profile

« Previous | Next » 

Revision 2cf35754

Added by Pi Ba over 10 years ago

speedup 'function is_port($port)' speed by skipping calls to getservbyname when possible

View differences:

etc/inc/util.inc
836 836

  
837 837
/* returns true if $port is a valid TCP/UDP port */
838 838
function is_port($port) {
839
	if (ctype_digit($port) && ((intval($port) >= 1) && (intval($port) <= 65535)))
840
		return true;
839 841
	if (getservbyname($port, "tcp") || getservbyname($port, "udp"))
840 842
		return true;
841
	if (!ctype_digit($port))
842
		return false;
843
	else if ((intval($port) < 1) || (intval($port) > 65535))
844
		return false;
845
	return true;
843
	return false;
846 844
}
847 845

  
848 846
/* returns true if $portrange is a valid TCP/UDP portrange ("<port>:<port>") */

Also available in: Unified diff