Compare commits

...

2 Commits

Author SHA1 Message Date
Bananymous f467a9a309 resolver: Resolve hostname to loopback address
We don't currently support loopback adapters, but some ports were trying
to resolve it.
2025-04-22 00:48:26 +03:00
Bananymous 5c9710c78b LibC: Implement `strcoll_l` 2025-04-22 00:48:26 +03:00
2 changed files with 19 additions and 3 deletions

View File

@ -156,7 +156,12 @@ char* strncat(char* __restrict__ dest, const char* __restrict__ src, size_t n)
int strcoll(const char* s1, const char* s2)
{
switch (__getlocale(LC_COLLATE))
return strcoll_l(s1, s2, __getlocale(LC_COLLATE));
}
int strcoll_l(const char *s1, const char *s2, locale_t locale)
{
switch (locale)
{
case LOCALE_INVALID:
ASSERT_NOT_REACHED();

View File

@ -127,7 +127,7 @@ BAN::Optional<DNSResponse> read_dns_response(int socket)
DNSAnswer& answer = *reinterpret_cast<DNSAnswer*>(&reply.data[idx]);
if (answer.type() != QTYPE::A)
{
dprintln("Not A record");
dprintln("Not A record, but {}", static_cast<uint16_t>(answer.type()));
return {};
}
if (answer.data_len() != 4)
@ -197,6 +197,10 @@ int main(int, char**)
{
srand(time(nullptr));
char hostname[HOST_NAME_MAX];
if (gethostname(hostname, sizeof(hostname)) == -1)
hostname[0] = '\0';
int service_socket = create_service_socket();
if (service_socket == -1)
return 1;
@ -306,7 +310,14 @@ int main(int, char**)
BAN::Optional<DNSEntry> result;
if (dns_cache.contains(*query))
if (*hostname && strcmp(query->data(), hostname) == 0)
{
result = DNSEntry {
.valid_until = time(nullptr),
.address = ntohl(INADDR_LOOPBACK),
};
}
else if (dns_cache.contains(*query))
{
auto& cached = dns_cache[*query];
if (time(nullptr) <= cached.valid_until)