Bug 1866777 - Disable test_race_cache_with_network.js on windows opt for frequent...
[gecko.git] / netwerk / dns / PlatformDNSUnix.cpp
blob753d78697793889fd4e8c8447bc01a62fe159750
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=4 sw=2 sts=2 et cin: */
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 #include "GetAddrInfo.h"
8 #include "mozilla/net/DNSPacket.h"
9 #include "nsIDNSService.h"
10 #include "mozilla/Maybe.h"
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <netinet/in.h>
16 #include <resolv.h>
18 namespace mozilla::net {
20 #define LOG(msg, ...) \
21 MOZ_LOG(gGetAddrInfoLog, LogLevel::Debug, ("[DNS]: " msg, ##__VA_ARGS__))
23 nsresult ResolveHTTPSRecordImpl(const nsACString& aHost, uint16_t aFlags,
24 TypeRecordResultType& aResult, uint32_t& aTTL) {
25 DNSPacket packet;
26 nsAutoCString host(aHost);
27 nsAutoCString cname;
28 nsresult rv;
30 LOG("resolving %s\n", host.get());
31 // Perform the query
32 rv = packet.FillBuffer(
33 [&](unsigned char response[DNSPacket::MAX_SIZE]) -> int {
34 int len = 0;
35 #if defined(XP_LINUX)
36 len = res_nquery(&_res, host.get(), ns_c_in,
37 nsIDNSService::RESOLVE_TYPE_HTTPSSVC, response,
38 DNSPacket::MAX_SIZE);
39 #elif defined(XP_MACOSX)
40 len =
41 res_query(host.get(), ns_c_in, nsIDNSService::RESOLVE_TYPE_HTTPSSVC,
42 response, DNSPacket::MAX_SIZE);
43 #endif
45 if (len < 0) {
46 LOG("DNS query failed");
48 return len;
49 });
50 if (NS_FAILED(rv)) {
51 return rv;
54 return ParseHTTPSRecord(host, packet, aResult, aTTL);
57 } // namespace mozilla::net