1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/getai.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,32 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nspr.h" 1.10 + 1.11 +#include <stdio.h> 1.12 +#include <stdlib.h> 1.13 + 1.14 +int main(int argc, char **argv) 1.15 +{ 1.16 + PRAddrInfo *ai; 1.17 + void *iter; 1.18 + PRNetAddr addr; 1.19 + 1.20 + ai = PR_GetAddrInfoByName(argv[1], PR_AF_UNSPEC, PR_AI_ADDRCONFIG); 1.21 + if (ai == NULL) { 1.22 + fprintf(stderr, "PR_GetAddrInfoByName failed: (%d, %d)\n", 1.23 + PR_GetError(), PR_GetOSError()); 1.24 + exit(1); 1.25 + } 1.26 + printf("%s\n", PR_GetCanonNameFromAddrInfo(ai)); 1.27 + iter = NULL; 1.28 + while ((iter = PR_EnumerateAddrInfo(iter, ai, 0, &addr)) != NULL) { 1.29 + char buf[128]; 1.30 + PR_NetAddrToString(&addr, buf, sizeof buf); 1.31 + printf("%s\n", buf); 1.32 + } 1.33 + PR_FreeAddrInfo(ai); 1.34 + return 0; 1.35 +}