Skip to content

Commit 4e5e9f7

Browse files
authored
Fix IP parsing php error (librenms#18418)
Exception: TypeError Unsupported operand types: string - int @ /opt/librenms/LibreNMS/Util/IPv6.php:153
1 parent 9aa2291 commit 4e5e9f7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

LibreNMS/Util/IP.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,15 @@ public function __toString()
270270
* Extract an address from a cidr, assume a host is given if it does not contain /
271271
*
272272
* @param string $ip
273-
* @return array [$ip, $cidr]
273+
* @return array{0: string, 1: int} [$ip, $cidr]
274274
*/
275-
protected function extractCidr($ip)
275+
protected function extractCidr($ip): array
276276
{
277-
return array_pad(explode('/', $ip, 2), 2, $this->host_bits);
277+
$parts = explode('/', $ip, 2);
278+
$addr = $parts[0];
279+
$cidr = $parts[1] ?? $this->host_bits;
280+
281+
return [$addr, (int) $cidr];
278282
}
279283

280284
/**

0 commit comments

Comments
 (0)