summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Lopes <glopes@nebm.ist.utl.pt>2013-02-17 13:23:07 +0100
committerGustavo Lopes <glopes@nebm.ist.utl.pt>2013-02-17 22:42:58 +0100
commit91538e4e13908a8cfcb25c5286e4222ef4077a7e (patch)
tree56c2b4ca20b40c9aaedbaf405a2daca5fdfaf744
parent17c6389e9e3e5f138872c696a80acc78e923da68 (diff)
downloadphp-git-91538e4e13908a8cfcb25c5286e4222ef4077a7e.tar.gz
Cleanup some multicast code; fix for mac os x?
When I moved some stuff from sockets.c to multicast.c, I did not copy some conditional defines for systems without the RFC 3678 API. I moved such defines to multicast.h so both sockets.c and multicast.c can benefit from them and I prefixed them with PHP_ so that it's less confusing: now PHP_MCAST_* are defined to either the MCAST_* RFC 3678 APIs or to legacy APIs and MCAST_* always mean the (possibly undefined) system definitions.
-rw-r--r--ext/sockets/multicast.c36
-rw-r--r--ext/sockets/multicast.h24
-rw-r--r--ext/sockets/sockets.c23
3 files changed, 45 insertions, 38 deletions
diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c
index c6de3198e4..94f845d662 100644
--- a/ext/sockets/multicast.c
+++ b/ext/sockets/multicast.c
@@ -152,10 +152,10 @@ static int php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval *
#endif
switch (optname) {
- case MCAST_JOIN_GROUP:
+ case PHP_MCAST_JOIN_GROUP:
mcast_req_fun = &php_mcast_join;
goto mcast_req_fun;
- case MCAST_LEAVE_GROUP:
+ case PHP_MCAST_LEAVE_GROUP:
{
php_sockaddr_storage group = {0};
socklen_t glen;
@@ -180,16 +180,16 @@ mcast_req_fun:
}
#ifdef HAS_MCAST_EXT
- case MCAST_BLOCK_SOURCE:
+ case PHP_MCAST_BLOCK_SOURCE:
mcast_sreq_fun = &php_mcast_block_source;
goto mcast_sreq_fun;
- case MCAST_UNBLOCK_SOURCE:
+ case PHP_MCAST_UNBLOCK_SOURCE:
mcast_sreq_fun = &php_mcast_unblock_source;
goto mcast_sreq_fun;
- case MCAST_JOIN_SOURCE_GROUP:
+ case PHP_MCAST_JOIN_SOURCE_GROUP:
mcast_sreq_fun = &php_mcast_join_source;
goto mcast_sreq_fun;
- case MCAST_LEAVE_SOURCE_GROUP:
+ case PHP_MCAST_LEAVE_SOURCE_GROUP:
{
php_sockaddr_storage group = {0},
source = {0};
@@ -248,13 +248,13 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock,
int retval;
switch (optname) {
- case MCAST_JOIN_GROUP:
- case MCAST_LEAVE_GROUP:
+ case PHP_MCAST_JOIN_GROUP:
+ case PHP_MCAST_LEAVE_GROUP:
#ifdef HAS_MCAST_EXT
- case MCAST_BLOCK_SOURCE:
- case MCAST_UNBLOCK_SOURCE:
- case MCAST_JOIN_SOURCE_GROUP:
- case MCAST_LEAVE_SOURCE_GROUP:
+ case PHP_MCAST_BLOCK_SOURCE:
+ case PHP_MCAST_UNBLOCK_SOURCE:
+ case PHP_MCAST_JOIN_SOURCE_GROUP:
+ case PHP_MCAST_LEAVE_SOURCE_GROUP:
#endif
if (php_do_mcast_opt(php_sock, level, optname, arg4 TSRMLS_CC) == FAILURE) {
return FAILURE;
@@ -316,13 +316,13 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock,
int retval;
switch (optname) {
- case MCAST_JOIN_GROUP:
- case MCAST_LEAVE_GROUP:
+ case PHP_MCAST_JOIN_GROUP:
+ case PHP_MCAST_LEAVE_GROUP:
#ifdef HAS_MCAST_EXT
- case MCAST_BLOCK_SOURCE:
- case MCAST_UNBLOCK_SOURCE:
- case MCAST_JOIN_SOURCE_GROUP:
- case MCAST_LEAVE_SOURCE_GROUP:
+ case PHP_MCAST_BLOCK_SOURCE:
+ case PHP_MCAST_UNBLOCK_SOURCE:
+ case PHP_MCAST_JOIN_SOURCE_GROUP:
+ case PHP_MCAST_LEAVE_SOURCE_GROUP:
#endif
if (php_do_mcast_opt(php_sock, level, optname, arg4 TSRMLS_CC) == FAILURE) {
return FAILURE;
diff --git a/ext/sockets/multicast.h b/ext/sockets/multicast.h
index 1ad4673feb..3614306bbb 100644
--- a/ext/sockets/multicast.h
+++ b/ext/sockets/multicast.h
@@ -19,12 +19,30 @@
/* $Id$ */
#if defined(MCAST_JOIN_GROUP) && !defined(__APPLE__)
-#define RFC3678_API 1
+# define RFC3678_API 1
/* has block/unblock and source membership, in this case for both IPv4 and IPv6 */
-#define HAS_MCAST_EXT 1
+# define HAS_MCAST_EXT 1
#elif defined(IP_ADD_SOURCE_MEMBERSHIP) && !defined(__APPLE__)
/* has block/unblock and source membership, but only for IPv4 */
-#define HAS_MCAST_EXT 1
+# define HAS_MCAST_EXT 1
+#endif
+
+#ifndef RFC3678_API
+# define PHP_MCAST_JOIN_GROUP IP_ADD_MEMBERSHIP
+# define PHP_MCAST_LEAVE_GROUP IP_DROP_MEMBERSHIP
+# ifdef HAS_MCAST_EXT
+# define PHP_MCAST_BLOCK_SOURCE IP_BLOCK_SOURCE
+# define PHP_MCAST_UNBLOCK_SOURCE IP_UNBLOCK_SOURCE
+# define PHP_MCAST_JOIN_SOURCE_GROUP IP_ADD_SOURCE_MEMBERSHIP
+# define PHP_MCAST_LEAVE_SOURCE_GROUP IP_DROP_SOURCE_MEMBERSHIP
+# endif
+#else
+# define PHP_MCAST_JOIN_GROUP MCAST_JOIN_GROUP
+# define PHP_MCAST_LEAVE_GROUP MCAST_LEAVE_GROUP
+# define PHP_MCAST_BLOCK_SOURCE MCAST_BLOCK_SOURCE
+# define PHP_MCAST_UNBLOCK_SOURCE MCAST_UNBLOCK_SOURCE
+# define PHP_MCAST_JOIN_SOURCE_GROUP MCAST_JOIN_SOURCE_GROUP
+# define PHP_MCAST_LEAVE_SOURCE_GROUP MCAST_LEAVE_SOURCE_GROUP
#endif
int php_do_setsockopt_ip_mcast(php_socket *php_sock,
diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c
index 5636cd3cdc..7f5d49e76c 100644
--- a/ext/sockets/sockets.c
+++ b/ext/sockets/sockets.c
@@ -688,24 +688,13 @@ PHP_MINIT_FUNCTION(sockets)
REGISTER_LONG_CONSTANT("PHP_NORMAL_READ", PHP_NORMAL_READ, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PHP_BINARY_READ", PHP_BINARY_READ, CONST_CS | CONST_PERSISTENT);
-#ifndef RFC3678_API
-#define MCAST_JOIN_GROUP IP_ADD_MEMBERSHIP
-#define MCAST_LEAVE_GROUP IP_DROP_MEMBERSHIP
+ REGISTER_LONG_CONSTANT("MCAST_JOIN_GROUP", PHP_MCAST_JOIN_GROUP, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MCAST_LEAVE_GROUP", PHP_MCAST_LEAVE_GROUP, CONST_CS | CONST_PERSISTENT);
#ifdef HAS_MCAST_EXT
-#define MCAST_BLOCK_SOURCE IP_BLOCK_SOURCE
-#define MCAST_UNBLOCK_SOURCE IP_UNBLOCK_SOURCE
-#define MCAST_JOIN_SOURCE_GROUP IP_ADD_SOURCE_MEMBERSHIP
-#define MCAST_LEAVE_SOURCE_GROUP IP_DROP_SOURCE_MEMBERSHIP
-#endif
-#endif
-
- REGISTER_LONG_CONSTANT("MCAST_JOIN_GROUP", MCAST_JOIN_GROUP, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("MCAST_LEAVE_GROUP", MCAST_LEAVE_GROUP, CONST_CS | CONST_PERSISTENT);
-#ifdef HAS_MCAST_EXT
- REGISTER_LONG_CONSTANT("MCAST_BLOCK_SOURCE", MCAST_BLOCK_SOURCE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("MCAST_UNBLOCK_SOURCE", MCAST_UNBLOCK_SOURCE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("MCAST_JOIN_SOURCE_GROUP", MCAST_JOIN_SOURCE_GROUP, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("MCAST_LEAVE_SOURCE_GROUP", MCAST_LEAVE_SOURCE_GROUP, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MCAST_BLOCK_SOURCE", PHP_MCAST_BLOCK_SOURCE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MCAST_UNBLOCK_SOURCE", PHP_MCAST_UNBLOCK_SOURCE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MCAST_JOIN_SOURCE_GROUP", PHP_MCAST_JOIN_SOURCE_GROUP, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MCAST_LEAVE_SOURCE_GROUP", PHP_MCAST_LEAVE_SOURCE_GROUP, CONST_CS | CONST_PERSISTENT);
#endif
REGISTER_LONG_CONSTANT("IP_MULTICAST_IF", IP_MULTICAST_IF, CONST_CS | CONST_PERSISTENT);