michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "prnetdb.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: const char *testaddrs[] = { michael@0: "::", "::", michael@0: "::1", "::1", michael@0: "::ffff", "::ffff", michael@0: "::1:0", "::0.1.0.0", michael@0: "::127.0.0.1", "::127.0.0.1", michael@0: "::FFFF:127.0.0.1", "::ffff:127.0.0.1", michael@0: "::FFFE:9504:3501", "::fffe:9504:3501", michael@0: "0:0:1:0:35c:0:0:0", "0:0:1:0:35c::", michael@0: "0:0:3f4c:0:0:4552:0:0", "::3f4c:0:0:4552:0:0", michael@0: "0:0:1245:0:0:0:0567:0", "0:0:1245::567:0", michael@0: "0:1:2:3:4:5:6:7", "0:1:2:3:4:5:6:7", michael@0: "1:2:3:0:4:5:6:7", "1:2:3:0:4:5:6:7", michael@0: "1:2:3:4:5:6:7:0", "1:2:3:4:5:6:7:0", michael@0: "1:2:3:4:5:6:7:8", "1:2:3:4:5:6:7:8", michael@0: "1:2:3:4:5:6::7", "1:2:3:4:5:6:0:7", michael@0: 0 michael@0: }; michael@0: michael@0: const char *badaddrs[] = { michael@0: "::.1.2.3", michael@0: "ffff::.1.2.3", michael@0: "1:2:3:4:5:6:7::8", michael@0: "1:2:3:4:5:6::7:8", michael@0: "::ff99.2.3.4", michael@0: 0 michael@0: }; michael@0: michael@0: int failed_already = 0; michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: const char **nexttestaddr = testaddrs; michael@0: const char **nextbadaddr = badaddrs; michael@0: const char *in, *expected_out; michael@0: PRNetAddr addr; michael@0: char buf[256]; michael@0: PRStatus rv; michael@0: michael@0: while ((in = *nexttestaddr++) != 0) { michael@0: expected_out = *nexttestaddr++; michael@0: rv = PR_StringToNetAddr(in, &addr); michael@0: if (rv) { michael@0: printf("cannot convert %s to addr: %d\n", in, rv); michael@0: failed_already = 1; michael@0: continue; michael@0: } michael@0: rv = PR_NetAddrToString(&addr, buf, sizeof(buf)); michael@0: if (rv) { michael@0: printf("cannot convert %s back to string: %d\n", in, rv); michael@0: failed_already = 1; michael@0: continue; michael@0: } michael@0: if (strcmp(buf, expected_out)) { michael@0: /* This is not necessarily an error */ michael@0: printf("%s expected %s got %s\n", in, expected_out, buf); michael@0: } michael@0: } michael@0: while ((in = *nextbadaddr++) != 0) { michael@0: if (PR_StringToNetAddr(in, &addr) == PR_SUCCESS) { michael@0: printf("converted bad addr %s\n", in); michael@0: failed_already = 1; michael@0: } michael@0: } michael@0: if (failed_already) { michael@0: printf("FAIL\n"); michael@0: return 1; michael@0: } michael@0: printf("PASS\n"); michael@0: return 0; michael@0: }