summaryrefslogtreecommitdiffstats
path: root/mDNSResponder/unittests/uds_daemon_ut.c
blob: 971a14194f0a6ccec07c94707e9bd0e5d49bf8e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "DNSCommon.h"                  // Defines general DNS utility routines

mDNSexport mStatus handle_client_request_ut(void *req)
{
	return handle_client_request((request_state*)req);
}

mDNSexport void LogCacheRecords_ut(mDNSs32 now, mDNSu32* retCacheUsed, mDNSu32* retCacheActive)
{
	mDNSu32 CacheUsed =0, CacheActive =0, slot;
	const CacheGroup *cg;
	const CacheRecord *cr;

	LogMsgNoIdent("------------ Cache -------------");
	LogMsgNoIdent("Slt Q     TTL if     U Type rdlen");
	for (slot = 0; slot < CACHE_HASH_SLOTS; slot++)
	{
		for (cg = mDNSStorage.rrcache_hash[slot]; cg; cg=cg->next)
		{
			CacheUsed++;    // Count one cache entity for the CacheGroup object
			for (cr = cg->members; cr; cr=cr->next)
			{
				const mDNSs32 remain = cr->resrec.rroriginalttl - (now - cr->TimeRcvd) / mDNSPlatformOneSecond;
				const char *ifname;
				mDNSInterfaceID InterfaceID = cr->resrec.InterfaceID;
				if (!InterfaceID && cr->resrec.rDNSServer && (cr->resrec.rDNSServer->scopeType != kScopeNone))
					InterfaceID = cr->resrec.rDNSServer->interface;
				ifname = InterfaceNameForID(&mDNSStorage, InterfaceID);
				if (cr->CRActiveQuestion) CacheActive++;
				PrintOneCacheRecord(cr, slot, remain, ifname, &CacheUsed);
				PrintCachedRecords(cr, slot, remain, ifname, &CacheUsed);
			}
		}
	}

	*retCacheUsed = CacheUsed;
	*retCacheActive = CacheActive;
}

mDNSexport int LogEtcHosts_ut(mDNS *const m)
{
	return LogEtcHosts(m);
}