refactor: discovery code cleanups (#6856)

* Use foreach $key => value

* use get_port_by_ifIndex
get rid of the rest of the array_keys()

* improve hex_to_ip() function, add tests, use in more places

* Simplify can_skip_discovery logic
This commit is contained in:
Tony Murray
2017-06-22 15:08:20 -05:00
committed by Neil Lathwood
parent 03a273f722
commit 90aa485149
4 changed files with 82 additions and 108 deletions

View File

@@ -50,4 +50,22 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase
$this->assertFalse(isHexString('a5 fj 53'));
$this->assertFalse(isHexString('a5fe53'));
}
public function testHexToIp()
{
$this->assertSame("192.168.1.254", hex_to_ip("c0 a8 01 fe"));
$this->assertSame("192.168.1.254", hex_to_ip("c0a801fe"));
$this->assertSame("192.168.1.254", hex_to_ip("c0 a8 01 fe "));
$this->assertNotSame("192.168.1.1.254", hex_to_ip("c0 a8 01 01 fe"));
$this->assertSame("192.168.1.254", hex_to_ip("\"c0 a8 01 fe\""));
$this->assertSame("192.168.1.254", hex_to_ip("192.168.1.254"));
$this->assertSame('2001:db8:0:0:0:0:2:1', hex_to_ip('2001:db8:0:0:0:0:2:1'));
$this->assertSame('2001:db8:0:0:0:0:2:1', hex_to_ip('20 01 0d b8 00 00 00 00 00 00 00 00 00 02 00 01'));
$this->assertSame('2001:db8:0:0:0:0:2:1', hex_to_ip('20010db8000000000000000000020001'));
$this->assertNotSame(
'2001:db8:0:0:0:0:2:0:1',
hex_to_ip('20 01 0d b8 00 00 00 00 00 00 00 00 00 02 00 00 00 01')
);
}
}