Skip to content

Commit 91538e4

Browse files
committed
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.
1 parent 17c6389 commit 91538e4

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

ext/sockets/multicast.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ static int php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval *
152152
#endif
153153

154154
switch (optname) {
155-
case MCAST_JOIN_GROUP:
155+
case PHP_MCAST_JOIN_GROUP:
156156
mcast_req_fun = &php_mcast_join;
157157
goto mcast_req_fun;
158-
case MCAST_LEAVE_GROUP:
158+
case PHP_MCAST_LEAVE_GROUP:
159159
{
160160
php_sockaddr_storage group = {0};
161161
socklen_t glen;
@@ -180,16 +180,16 @@ static int php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval *
180180
}
181181

182182
#ifdef HAS_MCAST_EXT
183-
case MCAST_BLOCK_SOURCE:
183+
case PHP_MCAST_BLOCK_SOURCE:
184184
mcast_sreq_fun = &php_mcast_block_source;
185185
goto mcast_sreq_fun;
186-
case MCAST_UNBLOCK_SOURCE:
186+
case PHP_MCAST_UNBLOCK_SOURCE:
187187
mcast_sreq_fun = &php_mcast_unblock_source;
188188
goto mcast_sreq_fun;
189-
case MCAST_JOIN_SOURCE_GROUP:
189+
case PHP_MCAST_JOIN_SOURCE_GROUP:
190190
mcast_sreq_fun = &php_mcast_join_source;
191191
goto mcast_sreq_fun;
192-
case MCAST_LEAVE_SOURCE_GROUP:
192+
case PHP_MCAST_LEAVE_SOURCE_GROUP:
193193
{
194194
php_sockaddr_storage group = {0},
195195
source = {0};
@@ -248,13 +248,13 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock,
248248
int retval;
249249

250250
switch (optname) {
251-
case MCAST_JOIN_GROUP:
252-
case MCAST_LEAVE_GROUP:
251+
case PHP_MCAST_JOIN_GROUP:
252+
case PHP_MCAST_LEAVE_GROUP:
253253
#ifdef HAS_MCAST_EXT
254-
case MCAST_BLOCK_SOURCE:
255-
case MCAST_UNBLOCK_SOURCE:
256-
case MCAST_JOIN_SOURCE_GROUP:
257-
case MCAST_LEAVE_SOURCE_GROUP:
254+
case PHP_MCAST_BLOCK_SOURCE:
255+
case PHP_MCAST_UNBLOCK_SOURCE:
256+
case PHP_MCAST_JOIN_SOURCE_GROUP:
257+
case PHP_MCAST_LEAVE_SOURCE_GROUP:
258258
#endif
259259
if (php_do_mcast_opt(php_sock, level, optname, arg4 TSRMLS_CC) == FAILURE) {
260260
return FAILURE;
@@ -316,13 +316,13 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock,
316316
int retval;
317317

318318
switch (optname) {
319-
case MCAST_JOIN_GROUP:
320-
case MCAST_LEAVE_GROUP:
319+
case PHP_MCAST_JOIN_GROUP:
320+
case PHP_MCAST_LEAVE_GROUP:
321321
#ifdef HAS_MCAST_EXT
322-
case MCAST_BLOCK_SOURCE:
323-
case MCAST_UNBLOCK_SOURCE:
324-
case MCAST_JOIN_SOURCE_GROUP:
325-
case MCAST_LEAVE_SOURCE_GROUP:
322+
case PHP_MCAST_BLOCK_SOURCE:
323+
case PHP_MCAST_UNBLOCK_SOURCE:
324+
case PHP_MCAST_JOIN_SOURCE_GROUP:
325+
case PHP_MCAST_LEAVE_SOURCE_GROUP:
326326
#endif
327327
if (php_do_mcast_opt(php_sock, level, optname, arg4 TSRMLS_CC) == FAILURE) {
328328
return FAILURE;

ext/sockets/multicast.h

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,30 @@
1919
/* $Id$ */
2020

2121
#if defined(MCAST_JOIN_GROUP) && !defined(__APPLE__)
22-
#define RFC3678_API 1
22+
# define RFC3678_API 1
2323
/* has block/unblock and source membership, in this case for both IPv4 and IPv6 */
24-
#define HAS_MCAST_EXT 1
24+
# define HAS_MCAST_EXT 1
2525
#elif defined(IP_ADD_SOURCE_MEMBERSHIP) && !defined(__APPLE__)
2626
/* has block/unblock and source membership, but only for IPv4 */
27-
#define HAS_MCAST_EXT 1
27+
# define HAS_MCAST_EXT 1
28+
#endif
29+
30+
#ifndef RFC3678_API
31+
# define PHP_MCAST_JOIN_GROUP IP_ADD_MEMBERSHIP
32+
# define PHP_MCAST_LEAVE_GROUP IP_DROP_MEMBERSHIP
33+
# ifdef HAS_MCAST_EXT
34+
# define PHP_MCAST_BLOCK_SOURCE IP_BLOCK_SOURCE
35+
# define PHP_MCAST_UNBLOCK_SOURCE IP_UNBLOCK_SOURCE
36+
# define PHP_MCAST_JOIN_SOURCE_GROUP IP_ADD_SOURCE_MEMBERSHIP
37+
# define PHP_MCAST_LEAVE_SOURCE_GROUP IP_DROP_SOURCE_MEMBERSHIP
38+
# endif
39+
#else
40+
# define PHP_MCAST_JOIN_GROUP MCAST_JOIN_GROUP
41+
# define PHP_MCAST_LEAVE_GROUP MCAST_LEAVE_GROUP
42+
# define PHP_MCAST_BLOCK_SOURCE MCAST_BLOCK_SOURCE
43+
# define PHP_MCAST_UNBLOCK_SOURCE MCAST_UNBLOCK_SOURCE
44+
# define PHP_MCAST_JOIN_SOURCE_GROUP MCAST_JOIN_SOURCE_GROUP
45+
# define PHP_MCAST_LEAVE_SOURCE_GROUP MCAST_LEAVE_SOURCE_GROUP
2846
#endif
2947

3048
int php_do_setsockopt_ip_mcast(php_socket *php_sock,

ext/sockets/sockets.c

+6-17
Original file line numberDiff line numberDiff line change
@@ -688,24 +688,13 @@ PHP_MINIT_FUNCTION(sockets)
688688
REGISTER_LONG_CONSTANT("PHP_NORMAL_READ", PHP_NORMAL_READ, CONST_CS | CONST_PERSISTENT);
689689
REGISTER_LONG_CONSTANT("PHP_BINARY_READ", PHP_BINARY_READ, CONST_CS | CONST_PERSISTENT);
690690

691-
#ifndef RFC3678_API
692-
#define MCAST_JOIN_GROUP IP_ADD_MEMBERSHIP
693-
#define MCAST_LEAVE_GROUP IP_DROP_MEMBERSHIP
691+
REGISTER_LONG_CONSTANT("MCAST_JOIN_GROUP", PHP_MCAST_JOIN_GROUP, CONST_CS | CONST_PERSISTENT);
692+
REGISTER_LONG_CONSTANT("MCAST_LEAVE_GROUP", PHP_MCAST_LEAVE_GROUP, CONST_CS | CONST_PERSISTENT);
694693
#ifdef HAS_MCAST_EXT
695-
#define MCAST_BLOCK_SOURCE IP_BLOCK_SOURCE
696-
#define MCAST_UNBLOCK_SOURCE IP_UNBLOCK_SOURCE
697-
#define MCAST_JOIN_SOURCE_GROUP IP_ADD_SOURCE_MEMBERSHIP
698-
#define MCAST_LEAVE_SOURCE_GROUP IP_DROP_SOURCE_MEMBERSHIP
699-
#endif
700-
#endif
701-
702-
REGISTER_LONG_CONSTANT("MCAST_JOIN_GROUP", MCAST_JOIN_GROUP, CONST_CS | CONST_PERSISTENT);
703-
REGISTER_LONG_CONSTANT("MCAST_LEAVE_GROUP", MCAST_LEAVE_GROUP, CONST_CS | CONST_PERSISTENT);
704-
#ifdef HAS_MCAST_EXT
705-
REGISTER_LONG_CONSTANT("MCAST_BLOCK_SOURCE", MCAST_BLOCK_SOURCE, CONST_CS | CONST_PERSISTENT);
706-
REGISTER_LONG_CONSTANT("MCAST_UNBLOCK_SOURCE", MCAST_UNBLOCK_SOURCE, CONST_CS | CONST_PERSISTENT);
707-
REGISTER_LONG_CONSTANT("MCAST_JOIN_SOURCE_GROUP", MCAST_JOIN_SOURCE_GROUP, CONST_CS | CONST_PERSISTENT);
708-
REGISTER_LONG_CONSTANT("MCAST_LEAVE_SOURCE_GROUP", MCAST_LEAVE_SOURCE_GROUP, CONST_CS | CONST_PERSISTENT);
694+
REGISTER_LONG_CONSTANT("MCAST_BLOCK_SOURCE", PHP_MCAST_BLOCK_SOURCE, CONST_CS | CONST_PERSISTENT);
695+
REGISTER_LONG_CONSTANT("MCAST_UNBLOCK_SOURCE", PHP_MCAST_UNBLOCK_SOURCE, CONST_CS | CONST_PERSISTENT);
696+
REGISTER_LONG_CONSTANT("MCAST_JOIN_SOURCE_GROUP", PHP_MCAST_JOIN_SOURCE_GROUP, CONST_CS | CONST_PERSISTENT);
697+
REGISTER_LONG_CONSTANT("MCAST_LEAVE_SOURCE_GROUP", PHP_MCAST_LEAVE_SOURCE_GROUP, CONST_CS | CONST_PERSISTENT);
709698
#endif
710699

711700
REGISTER_LONG_CONSTANT("IP_MULTICAST_IF", IP_MULTICAST_IF, CONST_CS | CONST_PERSISTENT);

0 commit comments

Comments
 (0)