File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -16,21 +16,21 @@ class Util
1616 */
1717 public static function cidr ($ ipAddress , $ prefixLen )
1818 {
19- $ ipBytes = array_merge ( unpack ( ' C* ' , inet_pton ($ ipAddress)) );
20- $ networkBytes = array_fill ( 0 , \count ($ ipBytes ), 0 );
19+ $ ipBytes = inet_pton ($ ipAddress );
20+ $ networkBytes = str_repeat ( "\0" , \strlen ($ ipBytes ));
2121
2222 $ curPrefix = $ prefixLen ;
23- for ($ i = 0 ; $ i < \count ($ ipBytes ) && $ curPrefix > 0 ; $ i ++) {
23+ for ($ i = 0 ; $ i < \strlen ($ ipBytes ) && $ curPrefix > 0 ; $ i ++) {
2424 $ b = $ ipBytes [$ i ];
2525 if ($ curPrefix < 8 ) {
2626 $ shiftN = 8 - $ curPrefix ;
27- $ b = (0xFF & ($ b >> $ shiftN ) << $ shiftN );
27+ $ b = \chr (0xFF & (\ord ( $ b ) >> $ shiftN ) << $ shiftN );
2828 }
2929 $ networkBytes [$ i ] = $ b ;
3030 $ curPrefix -= 8 ;
3131 }
3232
33- $ network = inet_ntop (pack ( ' C* ' , ... $ networkBytes) );
33+ $ network = inet_ntop ($ networkBytes );
3434
3535 return "$ network/ $ prefixLen " ;
3636 }
You can’t perform that action at this time.
0 commit comments