@@ -59,7 +59,7 @@ static const char *_php_source_op_to_string(enum source_op sop);
59
59
static int _php_source_op_to_ipv4_op (enum source_op sop );
60
60
#endif
61
61
62
- zend_result php_string_to_if_index (const char * val , unsigned * out )
62
+ bool php_string_to_if_index (const char * val , unsigned * out )
63
63
{
64
64
#ifdef HAVE_IF_NAMETOINDEX
65
65
unsigned int ind ;
@@ -68,30 +68,30 @@ zend_result php_string_to_if_index(const char *val, unsigned *out)
68
68
if (ind == 0 ) {
69
69
php_error_docref (NULL , E_WARNING ,
70
70
"No interface with name \"%s\" could be found" , val );
71
- return FAILURE ;
71
+ return false ;
72
72
} else {
73
73
* out = ind ;
74
- return SUCCESS ;
74
+ return true ;
75
75
}
76
76
#else
77
77
php_error_docref (NULL , E_WARNING ,
78
78
"This platform does not support looking up an interface by "
79
79
"name, an integer interface index must be supplied instead" );
80
- return FAILURE ;
80
+ return false ;
81
81
#endif
82
82
}
83
83
84
- static zend_result php_get_if_index_from_zval (zval * val , unsigned * out )
84
+ static bool php_get_if_index_from_zval (zval * val , unsigned * out )
85
85
{
86
- int ret ;
86
+ bool ret = false ;
87
87
88
88
if (Z_TYPE_P (val ) == IS_LONG ) {
89
89
if (Z_LVAL_P (val ) < 0 || (zend_ulong )Z_LVAL_P (val ) > UINT_MAX ) {
90
90
zend_value_error ("Index must be between 0 and %u" , UINT_MAX );
91
- return FAILURE ;
91
+ return ret ;
92
92
}
93
93
* out = Z_LVAL_P (val );
94
- ret = SUCCESS ;
94
+ ret = true ;
95
95
} else {
96
96
zend_string * tmp_str ;
97
97
zend_string * str = zval_get_tmp_string (val , & tmp_str );
@@ -104,39 +104,39 @@ static zend_result php_get_if_index_from_zval(zval *val, unsigned *out)
104
104
105
105
106
106
107
- static zend_result php_get_if_index_from_array (const HashTable * ht , const char * key ,
107
+ static bool php_get_if_index_from_array (const HashTable * ht , const char * key ,
108
108
php_socket * sock , unsigned int * if_index )
109
109
{
110
110
zval * val ;
111
111
112
112
if ((val = zend_hash_str_find (ht , key , strlen (key ))) == NULL ) {
113
113
* if_index = 0 ; /* default: 0 */
114
- return SUCCESS ;
114
+ return true ;
115
115
}
116
116
117
117
return php_get_if_index_from_zval (val , if_index );
118
118
}
119
119
120
- static zend_result php_get_address_from_array (const HashTable * ht , const char * key ,
120
+ static bool php_get_address_from_array (const HashTable * ht , const char * key ,
121
121
php_socket * sock , php_sockaddr_storage * ss , socklen_t * ss_len )
122
122
{
123
123
zval * val ;
124
124
zend_string * str , * tmp_str ;
125
125
126
126
if ((val = zend_hash_str_find (ht , key , strlen (key ))) == NULL ) {
127
127
zend_value_error ("No key \"%s\" passed in optval" , key );
128
- return FAILURE ;
128
+ return false ;
129
129
}
130
130
str = zval_get_tmp_string (val , & tmp_str );
131
- if (php_set_inet46_addr (ss , ss_len , ZSTR_VAL (str ), sock ) == FAILURE ) {
131
+ if (! php_set_inet46_addr (ss , ss_len , ZSTR_VAL (str ), sock )) {
132
132
zend_tmp_string_release (tmp_str );
133
- return FAILURE ;
133
+ return false ;
134
134
}
135
135
zend_tmp_string_release (tmp_str );
136
- return SUCCESS ;
136
+ return true ;
137
137
}
138
138
139
- static zend_result php_do_mcast_opt (php_socket * php_sock , int level , int optname , zval * arg4 )
139
+ static bool php_do_mcast_opt (php_socket * php_sock , int level , int optname , zval * arg4 )
140
140
{
141
141
HashTable * opt_ht ;
142
142
unsigned int if_index ;
@@ -162,13 +162,13 @@ mcast_req_fun: ;
162
162
convert_to_array (arg4 );
163
163
opt_ht = Z_ARRVAL_P (arg4 );
164
164
165
- if (php_get_address_from_array (opt_ht , "group" , php_sock , & group ,
166
- & glen ) == FAILURE ) {
167
- return FAILURE ;
165
+ if (! php_get_address_from_array (opt_ht , "group" , php_sock , & group ,
166
+ & glen )) {
167
+ return false ;
168
168
}
169
- if (php_get_if_index_from_array (opt_ht , "interface" , php_sock ,
170
- & if_index ) == FAILURE ) {
171
- return FAILURE ;
169
+ if (! php_get_if_index_from_array (opt_ht , "interface" , php_sock ,
170
+ & if_index )) {
171
+ return false ;
172
172
}
173
173
174
174
retval = mcast_req_fun (php_sock , level , (struct sockaddr * )& group ,
@@ -198,17 +198,17 @@ mcast_req_fun: ;
198
198
convert_to_array (arg4 );
199
199
opt_ht = Z_ARRVAL_P (arg4 );
200
200
201
- if (php_get_address_from_array (opt_ht , "group" , php_sock , & group ,
202
- & glen ) == FAILURE ) {
203
- return FAILURE ;
201
+ if (! php_get_address_from_array (opt_ht , "group" , php_sock , & group ,
202
+ & glen )) {
203
+ return false ;
204
204
}
205
- if (php_get_address_from_array (opt_ht , "source" , php_sock , & source ,
206
- & slen ) == FAILURE ) {
207
- return FAILURE ;
205
+ if (! php_get_address_from_array (opt_ht , "source" , php_sock , & source ,
206
+ & slen )) {
207
+ return false ;
208
208
}
209
- if (php_get_if_index_from_array (opt_ht , "interface" , php_sock ,
210
- & if_index ) == FAILURE ) {
211
- return FAILURE ;
209
+ if (! php_get_if_index_from_array (opt_ht , "interface" , php_sock ,
210
+ & if_index )) {
211
+ return false ;
212
212
}
213
213
214
214
retval = mcast_sreq_fun (php_sock , level , (struct sockaddr * )& group ,
@@ -220,16 +220,16 @@ mcast_req_fun: ;
220
220
php_error_docref (NULL , E_WARNING ,
221
221
"Unexpected option in php_do_mcast_opt (level %d, option %d). "
222
222
"This is a bug." , level , optname );
223
- return FAILURE ;
223
+ return false ;
224
224
}
225
225
226
226
if (retval != 0 ) {
227
227
if (retval != -2 ) { /* error, but message already emitted */
228
228
PHP_SOCKET_ERROR (php_sock , "Unable to set socket option" , errno );
229
229
}
230
- return FAILURE ;
230
+ return false ;
231
231
}
232
- return SUCCESS ;
232
+ return true ;
233
233
}
234
234
235
235
int php_do_setsockopt_ip_mcast (php_socket * php_sock ,
@@ -253,18 +253,18 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock,
253
253
case PHP_MCAST_JOIN_SOURCE_GROUP :
254
254
case PHP_MCAST_LEAVE_SOURCE_GROUP :
255
255
#endif
256
- if (php_do_mcast_opt (php_sock , level , optname , arg4 ) == FAILURE ) {
256
+ if (! php_do_mcast_opt (php_sock , level , optname , arg4 )) {
257
257
return FAILURE ;
258
258
} else {
259
259
return SUCCESS ;
260
260
}
261
261
262
262
case IP_MULTICAST_IF :
263
- if (php_get_if_index_from_zval (arg4 , & if_index ) == FAILURE ) {
263
+ if (! php_get_if_index_from_zval (arg4 , & if_index )) {
264
264
return FAILURE ;
265
265
}
266
266
267
- if (php_if_index_to_addr4 (if_index , php_sock , & if_addr ) == FAILURE ) {
267
+ if (! php_if_index_to_addr4 (if_index , php_sock , & if_addr )) {
268
268
return FAILURE ;
269
269
}
270
270
opt_ptr = & if_addr ;
@@ -321,14 +321,14 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock,
321
321
case PHP_MCAST_JOIN_SOURCE_GROUP :
322
322
case PHP_MCAST_LEAVE_SOURCE_GROUP :
323
323
#endif
324
- if (php_do_mcast_opt (php_sock , level , optname , arg4 ) == FAILURE ) {
324
+ if (! php_do_mcast_opt (php_sock , level , optname , arg4 )) {
325
325
return FAILURE ;
326
326
} else {
327
327
return SUCCESS ;
328
328
}
329
329
330
330
case IPV6_MULTICAST_IF :
331
- if (php_get_if_index_from_zval (arg4 , & if_index ) == FAILURE ) {
331
+ if (! php_get_if_index_from_zval (arg4 , & if_index )) {
332
332
return FAILURE ;
333
333
}
334
334
@@ -463,8 +463,7 @@ static int _php_mcast_join_leave(
463
463
assert (group_len == sizeof (struct sockaddr_in ));
464
464
465
465
if (if_index != 0 ) {
466
- if (php_if_index_to_addr4 (if_index , sock , & addr ) ==
467
- FAILURE )
466
+ if (!php_if_index_to_addr4 (if_index , sock , & addr ))
468
467
return -2 ; /* failure, but notice already emitted */
469
468
mreq .imr_interface = addr ;
470
469
} else {
@@ -532,8 +531,7 @@ static int _php_mcast_source_op(
532
531
assert (source_len == sizeof (struct sockaddr_in ));
533
532
534
533
if (if_index != 0 ) {
535
- if (php_if_index_to_addr4 (if_index , sock , & addr ) ==
536
- FAILURE )
534
+ if (!php_if_index_to_addr4 (if_index , sock , & addr ))
537
535
return -2 ; /* failure, but notice already emitted */
538
536
mreqs .imr_interface = addr ;
539
537
} else {
@@ -616,7 +614,7 @@ static int _php_source_op_to_ipv4_op(enum source_op sop)
616
614
#endif /* HAS_MCAST_EXT */
617
615
618
616
#ifdef PHP_WIN32
619
- zend_result php_if_index_to_addr4 (unsigned if_index , php_socket * php_sock , struct in_addr * out_addr )
617
+ bool php_if_index_to_addr4 (unsigned if_index , php_socket * php_sock , struct in_addr * out_addr )
620
618
{
621
619
MIB_IPADDRTABLE * addr_table ;
622
620
ULONG size ;
@@ -627,7 +625,7 @@ zend_result php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struc
627
625
628
626
if (if_index == 0 ) {
629
627
out_addr -> s_addr = INADDR_ANY ;
630
- return SUCCESS ;
628
+ return true ;
631
629
}
632
630
633
631
size = 4 * (sizeof * addr_table );
@@ -642,23 +640,23 @@ zend_result php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struc
642
640
efree (addr_table );
643
641
php_error_docref (NULL , E_WARNING ,
644
642
"GetIpAddrTable failed with error %lu" , retval );
645
- return FAILURE ;
643
+ return false ;
646
644
}
647
645
for (i = 0 ; i < addr_table -> dwNumEntries ; i ++ ) {
648
646
MIB_IPADDRROW r = addr_table -> table [i ];
649
647
if (r .dwIndex == if_index ) {
650
648
out_addr -> s_addr = r .dwAddr ;
651
649
efree (addr_table );
652
- return SUCCESS ;
650
+ return true ;
653
651
}
654
652
}
655
653
efree (addr_table );
656
654
php_error_docref (NULL , E_WARNING ,
657
655
"No interface with index %u was found" , if_index );
658
- return FAILURE ;
656
+ return false ;
659
657
}
660
658
661
- zend_result php_add4_to_if_index (struct in_addr * addr , php_socket * php_sock , unsigned * if_index )
659
+ bool php_add4_to_if_index (struct in_addr * addr , php_socket * php_sock , unsigned * if_index )
662
660
{
663
661
MIB_IPADDRTABLE * addr_table ;
664
662
ULONG size ;
@@ -669,7 +667,7 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
669
667
670
668
if (addr -> s_addr == INADDR_ANY ) {
671
669
* if_index = 0 ;
672
- return SUCCESS ;
670
+ return true ;
673
671
}
674
672
675
673
size = 4 * (sizeof * addr_table );
@@ -684,14 +682,14 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
684
682
efree (addr_table );
685
683
php_error_docref (NULL , E_WARNING ,
686
684
"GetIpAddrTable failed with error %lu" , retval );
687
- return FAILURE ;
685
+ return false ;
688
686
}
689
687
for (i = 0 ; i < addr_table -> dwNumEntries ; i ++ ) {
690
688
MIB_IPADDRROW r = addr_table -> table [i ];
691
689
if (r .dwAddr == addr -> s_addr ) {
692
690
* if_index = r .dwIndex ;
693
691
efree (addr_table );
694
- return SUCCESS ;
692
+ return true ;
695
693
}
696
694
}
697
695
efree (addr_table );
@@ -702,18 +700,18 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
702
700
php_error_docref (NULL , E_WARNING ,
703
701
"The interface with IP address %s was not found" , addr_str );
704
702
}
705
- return FAILURE ;
703
+ return false ;
706
704
}
707
705
708
706
#else
709
707
710
- zend_result php_if_index_to_addr4 (unsigned if_index , php_socket * php_sock , struct in_addr * out_addr )
708
+ bool php_if_index_to_addr4 (unsigned if_index , php_socket * php_sock , struct in_addr * out_addr )
711
709
{
712
710
struct ifreq if_req ;
713
711
714
712
if (if_index == 0 ) {
715
713
out_addr -> s_addr = INADDR_ANY ;
716
- return SUCCESS ;
714
+ return true ;
717
715
}
718
716
719
717
#if !defined(ifr_ifindex ) && (defined(ifr_index ) || defined(__HAIKU__ ))
@@ -730,21 +728,21 @@ zend_result php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struc
730
728
#endif
731
729
php_error_docref (NULL , E_WARNING ,
732
730
"Failed obtaining address for interface %u: error %d" , if_index , errno );
733
- return FAILURE ;
731
+ return false ;
734
732
}
735
733
736
734
if (ioctl (php_sock -> bsd_socket , SIOCGIFADDR , & if_req ) == -1 ) {
737
735
php_error_docref (NULL , E_WARNING ,
738
736
"Failed obtaining address for interface %u: error %d" , if_index , errno );
739
- return FAILURE ;
737
+ return false ;
740
738
}
741
739
742
740
memcpy (out_addr , & ((struct sockaddr_in * ) & if_req .ifr_addr )-> sin_addr ,
743
741
sizeof * out_addr );
744
- return SUCCESS ;
742
+ return true ;
745
743
}
746
744
747
- zend_result php_add4_to_if_index (struct in_addr * addr , php_socket * php_sock , unsigned * if_index )
745
+ bool php_add4_to_if_index (struct in_addr * addr , php_socket * php_sock , unsigned * if_index )
748
746
{
749
747
struct ifconf if_conf = {0 };
750
748
char * buf = NULL ,
@@ -755,7 +753,7 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
755
753
756
754
if (addr -> s_addr == INADDR_ANY ) {
757
755
* if_index = 0 ;
758
- return SUCCESS ;
756
+ return true ;
759
757
}
760
758
761
759
for (;;) {
@@ -819,7 +817,7 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
819
817
* if_index = index_tmp ;
820
818
#endif
821
819
efree (buf );
822
- return SUCCESS ;
820
+ return true ;
823
821
}
824
822
}
825
823
}
@@ -834,6 +832,6 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
834
832
err :
835
833
if (buf != NULL )
836
834
efree (buf );
837
- return FAILURE ;
835
+ return false ;
838
836
}
839
837
#endif
0 commit comments