| 1 | import socket |
| 2 | import sys |
| 3 | |
| 4 | # Keep track of the test case number so that any error message is more useful. |
| 5 | testnum = 0 |
| 6 | |
| 7 | |
| 8 | def testcase(success, errmsg): |
| 9 | global testnum |
| 10 | testnum += 1 |
| 11 | |
| 12 | if not success: |
| 13 | sys.stderr.write(f"Test #{testnum}: {errmsg}\n") |
| 14 | sys.exit(1) |
| 15 | |
| 16 | |
| 17 | def ipv4binary(ipstr): |
| 18 | return socket.inet_pton(socket.AF_INET, ipstr) |
| 19 | |
| 20 | |
| 21 | def ipv6binary(ipstr): |
| 22 | return socket.inet_pton(socket.AF_INET6, ipstr) |