2 * Copyright 2010-2017, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _NETWORK_ADDRESS_RESOLVER_H
6 #define _NETWORK_ADDRESS_RESOLVER_H
10 #include <ObjectList.h>
11 #include <Referenceable.h>
13 #include <SupportDefs.h>
16 class BNetworkAddress
;
20 // flags for name resolution
22 B_NO_ADDRESS_RESOLUTION
= 0x0001,
23 B_UNCONFIGURED_ADDRESS_FAMILIES
= 0x0002,
27 class BNetworkAddressResolver
: public BReferenceable
{
29 BNetworkAddressResolver();
30 BNetworkAddressResolver(const char* address
,
31 uint16 port
= 0, uint32 flags
= 0);
32 BNetworkAddressResolver(const char* address
,
33 const char* service
, uint32 flags
= 0);
34 BNetworkAddressResolver(int family
,
35 const char* address
, uint16 port
= 0,
37 BNetworkAddressResolver(int family
,
38 const char* address
, const char* service
,
40 ~BNetworkAddressResolver();
42 status_t
InitCheck() const;
46 status_t
SetTo(const char* address
, uint16 port
= 0,
48 status_t
SetTo(const char* address
, const char* service
,
50 status_t
SetTo(int family
, const char* address
,
51 uint16 port
= 0, uint32 flags
= 0);
52 status_t
SetTo(int family
, const char* address
,
53 const char* service
, uint32 flags
= 0);
55 status_t
GetNextAddress(uint32
* cookie
,
56 BNetworkAddress
& address
) const;
57 status_t
GetNextAddress(int family
, uint32
* cookie
,
58 BNetworkAddress
& address
) const;
60 // TODO all the ::Resolve variants are needed. Maybe the SetTo and
61 // constructors could be removed as ::Resolve is the right way to get a
62 // resolver (using the cache).
63 static BReference
<const BNetworkAddressResolver
> Resolve(
64 const char* address
, const char* service
,
66 static BReference
<const BNetworkAddressResolver
> Resolve(
67 const char* address
, uint16 port
= 0,
69 static BReference
<const BNetworkAddressResolver
> Resolve(int family
,
70 const char* address
, const char* service
,
72 static BReference
<const BNetworkAddressResolver
> Resolve(int family
,
73 const char* address
, uint16 port
= 0,
82 CacheEntry(int family
, const char* address
, const char* service
,
83 uint32 flags
, BNetworkAddressResolver
* resolver
)
89 fResolver(resolver
, false)
93 bool Matches(int family
, BString address
, BString service
, uint32 flags
)
95 return family
== fFamily
&& flags
== fFlags
&& address
== fAddress
96 && service
== fService
;
104 BReference
<const BNetworkAddressResolver
> fResolver
;
107 static BLocker sCacheLock
;
108 static BObjectList
<CacheEntry
> sCacheMap
;
112 #endif // _NETWORK_ADDRESS_RESOLVER_H