VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prnetdb.h@ 26515

Last change on this file since 26515 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.6 KB
Line 
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
4 *
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/
9 *
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
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
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.
21 *
22 * Contributor(s):
23 *
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.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef prnetdb_h___
39#define prnetdb_h___
40
41#include "prtypes.h"
42#include "prio.h"
43
44#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
45#define PR_StringToNetAddr VBoxNsprPR_StringToNetAddr
46#define PR_NetAddrToString VBoxNsprPR_NetAddrToString
47#define PR_GetHostByName VBoxNsprPR_GetHostByName
48#define PR_GetIPNodeByName VBoxNsprPR_GetIPNodeByName
49#define PR_GetHostByAddr VBoxNsprPR_GetHostByAddr
50#define PR_EnumerateHostEnt VBoxNsprPR_EnumerateHostEnt
51#define PR_InitializeNetAddr VBoxNsprPR_InitializeNetAddr
52#define PR_SetNetAddr VBoxNsprPR_SetNetAddr
53#define PR_IsNetAddrType VBoxNsprPR_IsNetAddrType
54#define PR_ConvertIPv4AddrToIPv6 VBoxNsprPR_ConvertIPv4AddrToIPv6
55#define PR_GetProtoByName VBoxNsprPR_GetProtoByName
56#define PR_GetProtoByNumber VBoxNsprPR_GetProtoByNumber
57#define PR_GetAddrInfoByName VBoxNsprPR_GetAddrInfoByName
58#define PR_FreeAddrInfo VBoxNsprPR_FreeAddrInfo
59#define PR_EnumerateAddrInfo VBoxNsprPR_EnumerateAddrInfo
60#define PR_GetCanonNameFromAddrInfo VBoxNsprPR_GetCanonNameFromAddrInfo
61#define PR_htonl VBoxNsprPR_htonl
62#define PR_htonll VBoxNsprPR_htonll
63#define PR_htons VBoxNsprPR_htons
64#define PR_ntohl VBoxNsprPR_ntohl
65#define PR_ntohll VBoxNsprPR_ntohll
66#define PR_ntohs VBoxNsprPR_ntohs
67#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
68
69PR_BEGIN_EXTERN_C
70
71
72/*
73 *********************************************************************
74 * Translate an Internet address to/from a character string
75 *********************************************************************
76 */
77NSPR_API(PRStatus) PR_StringToNetAddr(
78 const char *string, PRNetAddr *addr);
79
80NSPR_API(PRStatus) PR_NetAddrToString(
81 const PRNetAddr *addr, char *string, PRUint32 size);
82
83/*
84** Structures returned by network data base library. All addresses are
85** supplied in host order, and returned in network order (suitable for
86** use in system calls).
87*/
88/*
89** Beware that WINSOCK.H defines h_addrtype and h_length as short.
90** Client code does direct struct copies of hostent to PRHostEnt and
91** hence the ifdef.
92*/
93typedef struct PRHostEnt {
94 char *h_name; /* official name of host */
95 char **h_aliases; /* alias list */
96#if defined(WIN32) || defined(WIN16)
97 PRInt16 h_addrtype; /* host address type */
98 PRInt16 h_length; /* length of address */
99#else
100 PRInt32 h_addrtype; /* host address type */
101 PRInt32 h_length; /* length of address */
102#endif
103 char **h_addr_list; /* list of addresses from name server */
104} PRHostEnt;
105
106/* A safe size to use that will mostly work... */
107#if (defined(AIX) && defined(_THREAD_SAFE)) || defined(OSF1)
108#define PR_NETDB_BUF_SIZE sizeof(struct protoent_data)
109#else
110#define PR_NETDB_BUF_SIZE 1024
111#endif
112
113/***********************************************************************
114** FUNCTION:
115** DESCRIPTION: PR_GetHostByName()
116** Lookup a host by name.
117**
118** INPUTS:
119** char *hostname Character string defining the host name of interest
120** char *buf A scratch buffer for the runtime to return result.
121** This buffer is allocated by the caller.
122** PRIntn bufsize Number of bytes in 'buf'. A recommnded value to
123** use is PR_NETDB_BUF_SIZE.
124** OUTPUTS:
125** PRHostEnt *hostentry
126** This structure is filled in by the runtime if
127** the function returns PR_SUCCESS. This structure
128** is allocated by the caller.
129** RETURN:
130** PRStatus PR_SUCCESS if the lookup succeeds. If it fails
131** the result will be PR_FAILURE and the reason
132** for the failure can be retrieved by PR_GetError().
133***********************************************************************/
134NSPR_API(PRStatus) PR_GetHostByName(
135 const char *hostname, char *buf, PRIntn bufsize, PRHostEnt *hostentry);
136
137/***********************************************************************
138** FUNCTION:
139** DESCRIPTION: PR_GetIPNodeByName()
140** Lookup a host by name. Equivalent to getipnodebyname(AI_DEFAULT)
141** of RFC 2553.
142**
143** INPUTS:
144** char *hostname Character string defining the host name of interest
145** PRUint16 af Address family (either PR_AF_INET or PR_AF_INET6)
146** PRIntn flags Specifies the types of addresses that are searched
147** for and the types of addresses that are returned.
148** The only supported flag is PR_AI_DEFAULT.
149** char *buf A scratch buffer for the runtime to return result.
150** This buffer is allocated by the caller.
151** PRIntn bufsize Number of bytes in 'buf'. A recommnded value to
152** use is PR_NETDB_BUF_SIZE.
153** OUTPUTS:
154** PRHostEnt *hostentry
155** This structure is filled in by the runtime if
156** the function returns PR_SUCCESS. This structure
157** is allocated by the caller.
158** RETURN:
159** PRStatus PR_SUCCESS if the lookup succeeds. If it fails
160** the result will be PR_FAILURE and the reason
161** for the failure can be retrieved by PR_GetError().
162***********************************************************************/
163
164
165#define PR_AI_ALL 0x08
166#define PR_AI_V4MAPPED 0x10
167#define PR_AI_ADDRCONFIG 0x20
168#define PR_AI_NOCANONNAME 0x8000
169#define PR_AI_DEFAULT (PR_AI_V4MAPPED | PR_AI_ADDRCONFIG)
170
171NSPR_API(PRStatus) PR_GetIPNodeByName(
172 const char *hostname,
173 PRUint16 af,
174 PRIntn flags,
175 char *buf,
176 PRIntn bufsize,
177 PRHostEnt *hostentry);
178
179/***********************************************************************
180** FUNCTION:
181** DESCRIPTION: PR_GetHostByAddr()
182** Lookup a host entry by its network address.
183**
184** INPUTS:
185** char *hostaddr IP address of host in question
186** char *buf A scratch buffer for the runtime to return result.
187** This buffer is allocated by the caller.
188** PRIntn bufsize Number of bytes in 'buf'. A recommnded value to
189** use is PR_NETDB_BUF_SIZE.
190** OUTPUTS:
191** PRHostEnt *hostentry
192** This structure is filled in by the runtime if
193** the function returns PR_SUCCESS. This structure
194** is allocated by the caller.
195** RETURN:
196** PRStatus PR_SUCCESS if the lookup succeeds. If it fails
197** the result will be PR_FAILURE and the reason
198** for the failure can be retrieved by PR_GetError().
199***********************************************************************/
200NSPR_API(PRStatus) PR_GetHostByAddr(
201 const PRNetAddr *hostaddr, char *buf, PRIntn bufsize, PRHostEnt *hostentry);
202
203/***********************************************************************
204** FUNCTION: PR_EnumerateHostEnt()
205** DESCRIPTION:
206** A stateless enumerator over a PRHostEnt structure acquired from
207** PR_GetHostByName() PR_GetHostByAddr() to evaluate the possible
208** network addresses.
209**
210** INPUTS:
211** PRIntn enumIndex Index of the enumeration. The enumeration starts
212** and ends with a value of zero.
213**
214** PRHostEnt *hostEnt A pointer to a host entry struct that was
215** previously returned by PR_GetHostByName() or
216** PR_GetHostByAddr().
217**
218** PRUint16 port The port number to be assigned as part of the
219** PRNetAddr.
220**
221** OUTPUTS:
222** PRNetAddr *address A pointer to an address structure that will be
223** filled in by the call to the enumeration if the
224** result of the call is greater than zero.
225**
226** RETURN:
227** PRIntn The value that should be used for the next call
228** of the enumerator ('enumIndex'). The enumeration
229** is ended if this value is returned zero.
230** If a value of -1 is returned, the enumeration
231** has failed. The reason for the failure can be
232** retrieved by calling PR_GetError().
233***********************************************************************/
234NSPR_API(PRIntn) PR_EnumerateHostEnt(
235 PRIntn enumIndex, const PRHostEnt *hostEnt, PRUint16 port, PRNetAddr *address);
236
237/***********************************************************************
238** FUNCTION: PR_InitializeNetAddr(),
239** DESCRIPTION:
240** Initialize the fields of a PRNetAddr, assigning well known values as
241** appropriate.
242**
243** INPUTS
244** PRNetAddrValue val The value to be assigned to the IP Address portion
245** of the network address. This can only specify the
246** special well known values that are equivalent to
247** INADDR_ANY and INADDR_LOOPBACK.
248**
249** PRUint16 port The port number to be assigned in the structure.
250**
251** OUTPUTS:
252** PRNetAddr *addr The address to be manipulated.
253**
254** RETURN:
255** PRStatus To indicate success or failure. If the latter, the
256** reason for the failure can be retrieved by calling
257** PR_GetError();
258***********************************************************************/
259typedef enum PRNetAddrValue
260{
261 PR_IpAddrNull, /* do NOT overwrite the IP address */
262 PR_IpAddrAny, /* assign logical INADDR_ANY to IP address */
263 PR_IpAddrLoopback, /* assign logical INADDR_LOOPBACK */
264 PR_IpAddrV4Mapped /* IPv4 mapped address */
265} PRNetAddrValue;
266
267NSPR_API(PRStatus) PR_InitializeNetAddr(
268 PRNetAddrValue val, PRUint16 port, PRNetAddr *addr);
269
270/***********************************************************************
271** FUNCTION: PR_SetNetAddr(),
272** DESCRIPTION:
273** Set the fields of a PRNetAddr, assigning well known values as
274** appropriate. This function is similar to PR_InitializeNetAddr
275** but differs in that the address family is specified.
276**
277** INPUTS
278** PRNetAddrValue val The value to be assigned to the IP Address portion
279** of the network address. This can only specify the
280** special well known values that are equivalent to
281** INADDR_ANY and INADDR_LOOPBACK.
282**
283** PRUint16 af The address family (either PR_AF_INET or PR_AF_INET6)
284**
285** PRUint16 port The port number to be assigned in the structure.
286**
287** OUTPUTS:
288** PRNetAddr *addr The address to be manipulated.
289**
290** RETURN:
291** PRStatus To indicate success or failure. If the latter, the
292** reason for the failure can be retrieved by calling
293** PR_GetError();
294***********************************************************************/
295NSPR_API(PRStatus) PR_SetNetAddr(
296 PRNetAddrValue val, PRUint16 af, PRUint16 port, PRNetAddr *addr);
297
298/***********************************************************************
299** FUNCTION:
300** DESCRIPTION: PR_IsNetAddrType()
301** Determine if the network address is of the specified type.
302**
303** INPUTS:
304** const PRNetAddr *addr A network address.
305** PRNetAddrValue The type of network address
306**
307** RETURN:
308** PRBool PR_TRUE if the network address is of the
309** specified type, else PR_FALSE.
310***********************************************************************/
311NSPR_API(PRBool) PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val);
312
313/***********************************************************************
314** FUNCTION:
315** DESCRIPTION: PR_ConvertIPv4AddrToIPv6()
316** Convert an IPv4 addr to an (IPv4-mapped) IPv6 addr
317**
318** INPUTS:
319** PRUint32 v4addr IPv4 address
320**
321** OUTPUTS:
322** PRIPv6Addr *v6addr The converted IPv6 address
323**
324** RETURN:
325** void
326**
327***********************************************************************/
328NSPR_API(void) PR_ConvertIPv4AddrToIPv6(PRUint32 v4addr, PRIPv6Addr *v6addr);
329
330/***********************************************************************
331** MACRO:
332** DESCRIPTION: PR_NetAddrFamily()
333** Get the 'family' field of a PRNetAddr union.
334**
335** INPUTS:
336** const PRNetAddr *addr A network address.
337**
338** RETURN:
339** PRUint16 The 'family' field of 'addr'.
340***********************************************************************/
341#define PR_NetAddrFamily(addr) ((addr)->raw.family)
342
343/***********************************************************************
344** MACRO:
345** DESCRIPTION: PR_NetAddrInetPort()
346** Get the 'port' field of a PRNetAddr union.
347**
348** INPUTS:
349** const PRNetAddr *addr A network address.
350**
351** RETURN:
352** PRUint16 The 'port' field of 'addr'.
353***********************************************************************/
354#define PR_NetAddrInetPort(addr) \
355 ((addr)->raw.family == PR_AF_INET6 ? (addr)->ipv6.port : (addr)->inet.port)
356
357/***********************************************************************
358** FUNCTION:
359** DESCRIPTION: PR_GetProtoByName()
360** Lookup a protocol entry based on protocol's name
361**
362** INPUTS:
363** char *protocolname Character string of the protocol's name.
364** char *buf A scratch buffer for the runtime to return result.
365** This buffer is allocated by the caller.
366** PRIntn bufsize Number of bytes in 'buf'. A recommnded value to
367** use is PR_NETDB_BUF_SIZE.
368** OUTPUTS:
369** PRHostEnt *PRProtoEnt
370** This structure is filled in by the runtime if
371** the function returns PR_SUCCESS. This structure
372** is allocated by the caller.
373** RETURN:
374** PRStatus PR_SUCCESS if the lookup succeeds. If it fails
375** the result will be PR_FAILURE and the reason
376** for the failure can be retrieved by PR_GetError().
377***********************************************************************/
378
379typedef struct PRProtoEnt {
380 char *p_name; /* official protocol name */
381 char **p_aliases; /* alias list */
382#if defined(WIN32) || defined(WIN16)
383 PRInt16 p_num; /* protocol # */
384#else
385 PRInt32 p_num; /* protocol # */
386#endif
387} PRProtoEnt;
388
389NSPR_API(PRStatus) PR_GetProtoByName(
390 const char* protocolname, char* buffer, PRInt32 bufsize, PRProtoEnt* result);
391
392/***********************************************************************
393** FUNCTION:
394** DESCRIPTION: PR_GetProtoByNumber()
395** Lookup a protocol entry based on protocol's number
396**
397** INPUTS:
398** PRInt32 protocolnumber
399** Number assigned to the protocol.
400** char *buf A scratch buffer for the runtime to return result.
401** This buffer is allocated by the caller.
402** PRIntn bufsize Number of bytes in 'buf'. A recommnded value to
403** use is PR_NETDB_BUF_SIZE.
404** OUTPUTS:
405** PRHostEnt *PRProtoEnt
406** This structure is filled in by the runtime if
407** the function returns PR_SUCCESS. This structure
408** is allocated by the caller.
409** RETURN:
410** PRStatus PR_SUCCESS if the lookup succeeds. If it fails
411** the result will be PR_FAILURE and the reason
412** for the failure can be retrieved by PR_GetError().
413***********************************************************************/
414NSPR_API(PRStatus) PR_GetProtoByNumber(
415 PRInt32 protocolnumber, char* buffer, PRInt32 bufsize, PRProtoEnt* result);
416
417/***********************************************************************
418** FUNCTION:
419** DESCRIPTION: PR_GetAddrInfoByName()
420** Lookup a host by name. Equivalent to getaddrinfo(host, NULL, ...) of
421** RFC 3493.
422**
423** INPUTS:
424** char *hostname Character string defining the host name of interest
425** PRUint16 af May be PR_AF_UNSPEC or PR_AF_INET.
426** PRIntn flags May be either PR_AI_ADDRCONFIG or
427** PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME. Include
428** PR_AI_NOCANONNAME to suppress the determination of
429** the canonical name corresponding to hostname.
430** RETURN:
431** PRAddrInfo* Handle to a data structure containing the results
432** of the host lookup. Use PR_EnumerateAddrInfo to
433** inspect the PRNetAddr values stored in this object.
434** When no longer needed, this handle must be destroyed
435** with a call to PR_FreeAddrInfo. If a lookup error
436** occurs, then NULL will be returned.
437***********************************************************************/
438typedef struct PRAddrInfo PRAddrInfo;
439
440NSPR_API(PRAddrInfo*) PR_GetAddrInfoByName(
441 const char *hostname, PRUint16 af, PRIntn flags);
442
443/***********************************************************************
444** FUNCTION:
445** DESCRIPTION: PR_FreeAddrInfo()
446** Destroy the PRAddrInfo handle allocated by PR_GetAddrInfoByName().
447**
448** INPUTS:
449** PRAddrInfo *addrInfo
450** The handle resulting from a successful call to
451** PR_GetAddrInfoByName().
452** RETURN:
453** void
454***********************************************************************/
455NSPR_API(void) PR_FreeAddrInfo(PRAddrInfo *addrInfo);
456
457/***********************************************************************
458** FUNCTION:
459** DESCRIPTION: PR_EnumerateAddrInfo()
460** A stateless enumerator over a PRAddrInfo handle acquired from
461** PR_GetAddrInfoByName() to inspect the possible network addresses.
462**
463** INPUTS:
464** void *enumPtr Index pointer of the enumeration. The enumeration
465** starts and ends with a value of NULL.
466** PRAddrInfo *addrInfo
467** The PRAddrInfo handle returned by a successful
468** call to PR_GetAddrInfoByName().
469** PRUint16 port The port number to be assigned as part of the
470** PRNetAddr.
471** OUTPUTS:
472** PRNetAddr *result A pointer to an address structure that will be
473** filled in by the call to the enumeration if the
474** result of the call is greater than zero.
475** RETURN:
476** void* The value that should be used for the next call
477** of the enumerator ('enumPtr'). The enumeration
478** is ended if this value is returned NULL.
479***********************************************************************/
480NSPR_API(void *) PR_EnumerateAddrInfo(
481 void *enumPtr, const PRAddrInfo *addrInfo, PRUint16 port, PRNetAddr *result);
482
483/***********************************************************************
484** FUNCTION:
485** DESCRIPTION: PR_GetCanonNameFromAddrInfo()
486** Extracts the canonical name of the hostname passed to
487** PR_GetAddrInfoByName().
488**
489** INPUTS:
490** PRAddrInfo *addrInfo
491** The PRAddrInfo handle returned by a successful
492** call to PR_GetAddrInfoByName().
493** RETURN:
494** const char * A const pointer to the canonical hostname stored
495** in the given PRAddrInfo handle. This pointer is
496** invalidated once the PRAddrInfo handle is destroyed
497** by a call to PR_FreeAddrInfo().
498***********************************************************************/
499NSPR_API(const char *) PR_GetCanonNameFromAddrInfo(
500 const PRAddrInfo *addrInfo);
501
502/***********************************************************************
503** FUNCTIONS: PR_ntohs, PR_ntohl, PR_ntohll, PR_htons, PR_htonl, PR_htonll
504**
505** DESCRIPTION: API entries for the common byte ordering routines.
506**
507** PR_ntohs 16 bit conversion from network to host
508** PR_ntohl 32 bit conversion from network to host
509** PR_ntohll 64 bit conversion from network to host
510** PR_htons 16 bit conversion from host to network
511** PR_htonl 32 bit conversion from host to network
512** PR_ntonll 64 bit conversion from host to network
513**
514***********************************************************************/
515NSPR_API(PRUint16) PR_ntohs(PRUint16);
516NSPR_API(PRUint32) PR_ntohl(PRUint32);
517NSPR_API(PRUint64) PR_ntohll(PRUint64);
518NSPR_API(PRUint16) PR_htons(PRUint16);
519NSPR_API(PRUint32) PR_htonl(PRUint32);
520NSPR_API(PRUint64) PR_htonll(PRUint64);
521
522PR_END_EXTERN_C
523
524#endif /* prnetdb_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette