1 The `arrtoip()` function converts the given byte array into an IP address 2 string. Array of length 4 are converted to IPv4 addresses, arrays of 3 length 16 to IPv6 addresses. 4 5 Returns the resulting IPv4 or IPv6 address string. 6 7 Returns `null` if the given value is not an array, if the array has an 8 unsuitable length or if any item within the array is not an integer within 9 the range 0-255. 10 11 -- Testcase -- 12 {% 13 print(join("\n", [ 14 arrtoip([ 0, 0, 0, 0 ]), 15 arrtoip([ 192, 168, 1, 1 ]), 16 arrtoip([ 255, 255, 255, 255 ]), 17 arrtoip([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]), 18 arrtoip([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 192, 168, 1, 1 ]), 19 arrtoip([ 32, 1, 13, 184, 18, 52, 69, 103, 120, 154, 188, 222, 240, 18, 52, 86 ]), 20 arrtoip([ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ]) 21 ]), "\n"); 22 %} 23 -- End -- 24 25 -- Expect stdout -- 26 0.0.0.0 27 192.168.1.1 28 255.255.255.255 29 :: 30 ::ffff:192.168.1.1 31 2001:db8:1234:4567:789a:bcde:f012:3456 32 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 33 -- End -- 34 35 36 Supplying a non-array value, an array of unsuitable length or an array 37 containing invalid byte values yields `null`. 38 39 -- Testcase -- 40 {% 41 print(join("\n", [ 42 arrtoip(true), 43 arrtoip([ ]), 44 arrtoip([ 1, 2, 3 ]), 45 arrtoip([ 192, 168, 1, -1 ]), 46 arrtoip([ true, false, -5, 500 ]) 47 ]), "\n"); 48 %} 49 -- End -- 50 51 -- Expect stdout -- 52 null 53 null 54 null 55 null 56 null 57 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt