1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef netwerk_dns_GetAddrInfo_h
8 #define netwerk_dns_GetAddrInfo_h
12 #include "nsINativeDNSResolverOverride.h"
13 #include "nsHashKeys.h"
14 #include "nsTHashMap.h"
15 #include "mozilla/RWLock.h"
18 #include "mozilla/net/DNS.h"
21 # define DNSQUERY_AVAILABLE 1
23 # undef DNSQUERY_AVAILABLE
32 * Look up a host by name. Mostly equivalent to getaddrinfo(host, NULL, ...) of
35 * @param aHost[in] Character string defining the host name of interest
36 * @param aAddressFamily[in] May be AF_INET, AF_INET6, or AF_UNSPEC.
37 * @param aFlags[in] May be either PR_AI_ADDRCONFIG or
38 * PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME. Include PR_AI_NOCANONNAME to
39 * suppress the determination of the canonical name corresponding to
40 * hostname (PR_AI_NOCANONNAME will be ignored if the TTL is retrieved).
41 * @param aAddrInfo[out] Will point to the results of the host lookup, or be
42 * null if the lookup failed.
43 * @param aGetTtl[in] If true, the TTL will be retrieved if DNS provides the
46 nsresult
GetAddrInfo(const nsACString
& aHost
, uint16_t aAddressFamily
,
47 uint16_t aFlags
, AddrInfo
** aAddrInfo
, bool aGetTtl
);
50 * Initialize the GetAddrInfo module.
52 * GetAddrInfoShutdown() should be called for every time this function is
55 nsresult
GetAddrInfoInit();
58 * Shutdown the GetAddrInfo module.
60 * This function should be called for every time GetAddrInfoInit() is called.
61 * An assertion may throw (but is not guarenteed) if this function is called
64 nsresult
GetAddrInfoShutdown();
66 class NativeDNSResolverOverride
: public nsINativeDNSResolverOverride
{
67 NS_DECL_THREADSAFE_ISUPPORTS
68 NS_DECL_NSINATIVEDNSRESOLVEROVERRIDE
70 NativeDNSResolverOverride() = default;
72 static already_AddRefed
<nsINativeDNSResolverOverride
> GetSingleton();
75 virtual ~NativeDNSResolverOverride() = default;
76 mozilla::RWLock mLock MOZ_UNANNOTATED
{"NativeDNSResolverOverride"};
78 nsTHashMap
<nsCStringHashKey
, nsTArray
<NetAddr
>> mOverrides
;
79 nsTHashMap
<nsCStringHashKey
, nsCString
> mCnames
;
81 friend bool FindAddrOverride(const nsACString
& aHost
, uint16_t aAddressFamily
,
82 uint16_t aFlags
, AddrInfo
** aAddrInfo
);
86 } // namespace mozilla
88 #endif // netwerk_dns_GetAddrInfo_h