{
char *addr;
int addr_len;
+#ifdef HAVE_INET_PTON
+ struct in_addr ip;
+#else
unsigned long int ip;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) == FAILURE) {
return;
}
+#ifdef HAVE_INET_PTON
+ if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) {
+ RETURN_FALSE;
+ }
+ RETURN_LONG(ntohl(ip.s_addr));
+#else
if (addr_len == 0 || (ip = inet_addr(addr)) == INADDR_NONE) {
/* The only special case when we should return -1 ourselves,
* because inet_addr() considers it wrong. We return 0xFFFFFFFF and
RETURN_FALSE;
}
RETURN_LONG(ntohl(ip));
+#endif
}
/* }}} */
*** Testing ip2long() : usage variation ***
--int 0--
-int(0)
+bool(false)
--int 1--
-int(1)
+bool(false)
--int 12345--
-int(12345)
+bool(false)
--int -12345--
bool(false)
--float 10.5--
-int(167772165)
+bool(false)
--float -10.5--
bool(false)
bool(false)
--float .5--
-int(5)
+bool(false)
--empty array--
Error: 2 - ip2long() expects parameter 1 to be binary string, array given, %s(%d)
bool(false)
--lowercase true--
-int(1)
+bool(false)
--lowercase false--
bool(false)
--uppercase TRUE--
-int(1)
+bool(false)
--uppercase FALSE--
bool(false)