Fix FreeBSD build.
[haiku.git] / headers / os / net / NetworkAddressResolver.h
blob9c42d38722fe2d51f1d727cf14ec9a6ccda168bf
1 /*
2 * Copyright 2010-2017, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _NETWORK_ADDRESS_RESOLVER_H
6 #define _NETWORK_ADDRESS_RESOLVER_H
9 #include <Locker.h>
10 #include <ObjectList.h>
11 #include <Referenceable.h>
12 #include <String.h>
13 #include <SupportDefs.h>
16 class BNetworkAddress;
17 struct addrinfo;
20 // flags for name resolution
21 enum {
22 B_NO_ADDRESS_RESOLUTION = 0x0001,
23 B_UNCONFIGURED_ADDRESS_FAMILIES = 0x0002,
27 class BNetworkAddressResolver: public BReferenceable {
28 public:
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,
36 uint32 flags = 0);
37 BNetworkAddressResolver(int family,
38 const char* address, const char* service,
39 uint32 flags = 0);
40 ~BNetworkAddressResolver();
42 status_t InitCheck() const;
44 void Unset();
46 status_t SetTo(const char* address, uint16 port = 0,
47 uint32 flags = 0);
48 status_t SetTo(const char* address, const char* service,
49 uint32 flags = 0);
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,
65 uint32 flags = 0);
66 static BReference<const BNetworkAddressResolver> Resolve(
67 const char* address, uint16 port = 0,
68 uint32 flags = 0);
69 static BReference<const BNetworkAddressResolver> Resolve(int family,
70 const char* address, const char* service,
71 uint32 flags = 0);
72 static BReference<const BNetworkAddressResolver> Resolve(int family,
73 const char* address, uint16 port = 0,
74 uint32 flags = 0);
76 private:
77 addrinfo* fInfo;
78 status_t fStatus;
81 struct CacheEntry {
82 CacheEntry(int family, const char* address, const char* service,
83 uint32 flags, BNetworkAddressResolver* resolver)
85 fFamily(family),
86 fAddress(address),
87 fService(service),
88 fFlags(flags),
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;
99 int fFamily;
100 BString fAddress;
101 BString fService;
102 uint32 fFlags;
104 BReference<const BNetworkAddressResolver> fResolver;
107 static BLocker sCacheLock;
108 static BObjectList<CacheEntry> sCacheMap;
112 #endif // _NETWORK_ADDRESS_RESOLVER_H