summaryrefslogtreecommitdiffstats
path: root/netwerk/dns/PlatformDNSUnix.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /netwerk/dns/PlatformDNSUnix.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/dns/PlatformDNSUnix.cpp')
-rw-r--r--netwerk/dns/PlatformDNSUnix.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/netwerk/dns/PlatformDNSUnix.cpp b/netwerk/dns/PlatformDNSUnix.cpp
new file mode 100644
index 0000000000..dedbe337df
--- /dev/null
+++ b/netwerk/dns/PlatformDNSUnix.cpp
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=4 sw=2 sts=2 et cin: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "GetAddrInfo.h"
+#include "mozilla/net/DNSPacket.h"
+#include "nsIDNSService.h"
+#include "mozilla/Maybe.h"
+#include "mozilla/StaticPrefs_network.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <resolv.h>
+
+namespace mozilla::net {
+
+#define LOG(msg, ...) \
+ MOZ_LOG(gGetAddrInfoLog, LogLevel::Debug, ("[DNS]: " msg, ##__VA_ARGS__))
+
+nsresult ResolveHTTPSRecordImpl(const nsACString& aHost, uint16_t aFlags,
+ TypeRecordResultType& aResult, uint32_t& aTTL) {
+ DNSPacket packet;
+ nsAutoCString host(aHost);
+ nsAutoCString cname;
+ nsresult rv;
+
+ if (xpc::IsInAutomation() &&
+ !StaticPrefs::network_dns_native_https_query_in_automation()) {
+ return NS_ERROR_UNKNOWN_HOST;
+ }
+
+ LOG("resolving %s\n", host.get());
+ // Perform the query
+ rv = packet.FillBuffer(
+ [&](unsigned char response[DNSPacket::MAX_SIZE]) -> int {
+ int len = 0;
+#if defined(XP_LINUX)
+ len = res_nquery(&_res, host.get(), ns_c_in,
+ nsIDNSService::RESOLVE_TYPE_HTTPSSVC, response,
+ DNSPacket::MAX_SIZE);
+#elif defined(XP_MACOSX)
+ len =
+ res_query(host.get(), ns_c_in, nsIDNSService::RESOLVE_TYPE_HTTPSSVC,
+ response, DNSPacket::MAX_SIZE);
+#endif
+
+ if (len < 0) {
+ LOG("DNS query failed");
+ }
+ return len;
+ });
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
+
+ return ParseHTTPSRecord(host, packet, aResult, aTTL);
+}
+
+} // namespace mozilla::net