1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
49 #include "obsolete/probslet.h"
53 #define DNS_BUFFER 100
54 #define ADDR_BUFFER 100
55 #define HOST_BUFFER 1024
56 #define PROTO_BUFFER 1500
58 #define NETADDR_SIZE(addr) \
59 (PR_AF_INET == (addr)->raw.family ? \
60 sizeof((addr)->inet) : sizeof((addr)->ipv6))
62 static PRFileDesc
*err
= NULL
;
64 static void Help(void)
66 PR_fprintf(err
, "Usage: [-V] [-h]\n");
67 PR_fprintf(err
, "\t<nul> Name of host to lookup (default: self)\n");
68 PR_fprintf(err
, "\t-V Display runtime version info (default: FALSE)\n");
69 PR_fprintf(err
, "\t-h This message and nothing else\n");
72 static void DumpAddr(const PRNetAddr
* address
, const char *msg
)
74 PRUint32
*word
= (PRUint32
*)address
;
75 PRUint32 addr_len
= sizeof(PRNetAddr
);
76 PR_fprintf(err
, "%s[%d]\t", msg
, NETADDR_SIZE(address
));
79 PR_fprintf(err
, " %08x", *word
++);
80 addr_len
-= sizeof(PRUint32
);
82 PR_fprintf(err
, "\n");
85 static PRStatus
PrintAddress(const PRNetAddr
* address
)
87 PRNetAddr translation
;
88 char buffer
[ADDR_BUFFER
];
89 PRStatus rv
= PR_NetAddrToString(address
, buffer
, sizeof(buffer
));
90 if (PR_FAILURE
== rv
) PL_FPrintError(err
, "PR_NetAddrToString");
93 PR_fprintf(err
, "\t%s\n", buffer
);
94 memset(&translation
, 0, sizeof(translation
));
95 rv
= PR_StringToNetAddr(buffer
, &translation
);
96 if (PR_FAILURE
== rv
) PL_FPrintError(err
, "PR_StringToNetAddr");
99 PRSize addr_len
= NETADDR_SIZE(address
);
100 if (0 != memcmp(address
, &translation
, addr_len
))
102 PR_fprintf(err
, "Address translations do not match\n");
103 DumpAddr(address
, "original");
104 DumpAddr(&translation
, "translate");
112 PRIntn
main(PRIntn argc
, char **argv
)
118 const char *name
= NULL
;
119 PRBool failed
= PR_FALSE
, version
= PR_FALSE
;
120 PLOptState
*opt
= PL_CreateOptState(argc
, argv
, "Vh");
122 err
= PR_GetSpecialFD(PR_StandardError
);
124 while (PL_OPT_EOL
!= (os
= PL_GetNextOpt(opt
)))
126 if (PL_OPT_BAD
== os
) continue;
129 case 0: /* Name of host to lookup */
132 case 'V': /* Do version discovery */
135 case 'h': /* user wants some guidance */
137 Help(); /* so give him an earful */
138 return 2; /* but not a lot else */
141 PL_DestroyOptState(opt
);
146 #define NSPR_LIB "libnspr4"
148 #define NSPR_LIB "nspr4"
150 const PRVersionDescription
*version_info
;
151 char *nspr_path
= PR_GetEnv("LD_LIBRARY_PATH");
152 char *nspr_name
= PR_GetLibraryName(nspr_path
, NSPR_LIB
);
153 PRLibrary
*runtime
= PR_LoadLibrary(nspr_name
);
155 PL_FPrintError(err
, "PR_LoadLibrary");
158 versionEntryPointType versionPoint
= (versionEntryPointType
)
159 PR_FindSymbol(runtime
, "libVersionPoint");
160 if (NULL
== versionPoint
)
161 PL_FPrintError(err
, "PR_FindSymbol");
165 PRExplodedTime exploded
;
166 version_info
= versionPoint();
167 (void)PR_fprintf(err
, "Runtime library version information\n");
169 version_info
->buildTime
, PR_GMTParameters
, &exploded
);
171 buffer
, sizeof(buffer
), "%d %b %Y %H:%M:%S", &exploded
);
172 (void)PR_fprintf(err
, " Build time: %s GMT\n", buffer
);
174 err
, " Build time: %s\n", version_info
->buildTimeString
);
176 err
, " %s V%u.%u.%u (%s%s%s)\n",
177 version_info
->description
,
178 version_info
->vMajor
,
179 version_info
->vMinor
,
180 version_info
->vPatch
,
181 (version_info
->beta
? " beta " : ""),
182 (version_info
->debug
? " debug " : ""),
183 (version_info
->special
? " special" : ""));
184 (void)PR_fprintf(err
, " filename: %s\n", version_info
->filename
);
185 (void)PR_fprintf(err
, " security: %s\n", version_info
->security
);
186 (void)PR_fprintf(err
, " copyright: %s\n", version_info
->copyright
);
187 (void)PR_fprintf(err
, " comment: %s\n", version_info
->comment
);
190 if (NULL
!= nspr_name
) PR_FreeLibraryName(nspr_name
);
196 char *me
= (char*)PR_MALLOC(DNS_BUFFER
);
197 rv
= PR_GetSystemInfo(PR_SI_HOSTNAME
, me
, DNS_BUFFER
);
198 if (PR_FAILURE
== rv
)
201 PL_FPrintError(err
, "PR_GetSystemInfo");
204 name
= me
; /* just leak the storage */
209 char buffer
[HOST_BUFFER
];
210 PR_fprintf(err
, "Translating the name %s ...", name
);
212 rv
= PR_GetHostByName(name
, buffer
, sizeof(buffer
), &host
);
213 if (PR_FAILURE
== rv
)
216 PL_FPrintError(err
, "PR_GetHostByName");
222 memset(&address
, 0, sizeof(PRNetAddr
));
223 PR_fprintf(err
, "success .. enumerating results\n");
226 index
= PR_EnumerateHostEnt(index
, &host
, 0, &address
);
227 if (index
> 0) PrintAddress(&address
);
228 else if (-1 == index
)
231 PL_FPrintError(err
, "PR_EnumerateHostEnt");
239 char buffer
[PROTO_BUFFER
];
241 ** Get Proto by name/number
243 rv
= PR_GetProtoByName("tcp", &buffer
[1], sizeof(buffer
) - 1, &proto
);
244 rv
= PR_GetProtoByNumber(6, &buffer
[3], sizeof(buffer
) - 3, &proto
);
247 return (failed
) ? 1 : 0;