• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/03_stdlib/30_iptoarr

  1 The `iptoarr()` function parses the given IP address string into an array
  2 of byte values.
  3 
  4 Returns an array of byte values for the parsed IP address.
  5 
  6 Returns `null` if the given IP argument is not a string value or if the
  7 IP address could not be parsed.
  8 
  9 -- Testcase --
 10 {%
 11         print(join("\n", [
 12                 iptoarr("0.0.0.0"),
 13                 iptoarr("10.11.12.13"),
 14                 iptoarr("::"),
 15                 iptoarr("::ffff:192.168.1.1"),
 16                 iptoarr("2001:db8:1234:4567:789a:bcde:f012:3456"),
 17                 iptoarr("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
 18         ]), "\n");
 19 %}
 20 -- End --
 21 
 22 -- Expect stdout --
 23 [ 0, 0, 0, 0 ]
 24 [ 10, 11, 12, 13 ]
 25 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
 26 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 192, 168, 1, 1 ]
 27 [ 32, 1, 13, 184, 18, 52, 69, 103, 120, 154, 188, 222, 240, 18, 52, 86 ]
 28 [ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ]
 29 -- End --
 30 
 31 
 32 Supplying a non-string value or an unparsable address yields `null`.
 33 
 34 -- Testcase --
 35 {%
 36         print(join("\n", [
 37                 iptoarr(true),
 38                 iptoarr("invalid")
 39         ]), "\n");
 40 %}
 41 -- End --
 42 
 43 -- Expect stdout --
 44 null
 45 null
 46 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt