tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

getai.c (914B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "nspr.h"
      7 
      8 #include <stdio.h>
      9 #include <stdlib.h>
     10 
     11 int main(int argc, char** argv) {
     12  PRAddrInfo* ai;
     13  void* iter;
     14  PRNetAddr addr;
     15 
     16  ai = PR_GetAddrInfoByName(argv[1], PR_AF_UNSPEC, PR_AI_ADDRCONFIG);
     17  if (ai == NULL) {
     18    fprintf(stderr, "PR_GetAddrInfoByName failed: (%d, %d)\n", PR_GetError(),
     19            PR_GetOSError());
     20    exit(1);
     21  }
     22  printf("%s\n", PR_GetCanonNameFromAddrInfo(ai));
     23  iter = NULL;
     24  while ((iter = PR_EnumerateAddrInfo(iter, ai, 0, &addr)) != NULL) {
     25    char buf[128];
     26    PR_NetAddrToString(&addr, buf, sizeof buf);
     27    printf("%s\n", buf);
     28  }
     29  PR_FreeAddrInfo(ai);
     30  return 0;
     31 }