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: /* michael@0: * File: str2addr.c michael@0: * Description: a test for PR_StringToNetAddr michael@0: */ michael@0: michael@0: #include "nspr.h" michael@0: michael@0: #include michael@0: #include michael@0: michael@0: /* Address string to convert */ michael@0: #define DEFAULT_IPV4_ADDR_STR "207.200.73.41" michael@0: michael@0: /* Expected conversion result, in network byte order */ michael@0: static unsigned char default_ipv4_addr[] = {207, 200, 73, 41}; michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRNetAddr addr; michael@0: const char *addrStr; michael@0: unsigned char *bytes; michael@0: int idx; michael@0: michael@0: addrStr = DEFAULT_IPV4_ADDR_STR; michael@0: if (PR_StringToNetAddr(addrStr, &addr) == PR_FAILURE) { michael@0: fprintf(stderr, "PR_StringToNetAddr failed\n"); michael@0: exit(1); michael@0: } michael@0: if (addr.inet.family != PR_AF_INET) { michael@0: fprintf(stderr, "addr.inet.family should be %d but is %d\n", michael@0: PR_AF_INET, addr.inet.family); michael@0: exit(1); michael@0: } michael@0: bytes = (unsigned char *) &addr.inet.ip; michael@0: for (idx = 0; idx < 4; idx++) { michael@0: if (bytes[idx] != default_ipv4_addr[idx]) { michael@0: fprintf(stderr, "byte %d of IPv4 addr should be %d but is %d\n", michael@0: idx, default_ipv4_addr[idx], bytes[idx]); michael@0: exit(1); michael@0: } michael@0: } michael@0: michael@0: printf("PASS\n"); michael@0: return 0; michael@0: }