]> git.saurik.com Git - apple/mdnsresponder.git/blob - unittests/mdns_macosx_ut.c
mDNSResponder-878.1.1.tar.gz
[apple/mdnsresponder.git] / unittests / mdns_macosx_ut.c
1 #include "DNSCommon.h" // Defines general DNS utility routines
2
3 // To match *either* a v4 or v6 instance of this interface
4 mDNSlocal mDNSInterfaceID SearchForInterfaceByAddr(mDNSAddr* addr)
5 {
6 NetworkInterfaceInfoOSX *i;
7 for (i = mDNSStorage.p->InterfaceList; i; i = i->next)
8 if (i->Exists)
9 {
10 if ((i->ifinfo.ip.type == mDNSAddrType_IPv4) &&
11 i->ifinfo.ip.ip.v4.NotAnInteger == addr->ip.v4.NotAnInteger)
12 return i->ifinfo.InterfaceID;
13 else if ((i->ifinfo.ip.type == mDNSAddrType_IPv6) &&
14 (i->ifinfo.ip.ip.v6.l[0] == addr->ip.v6.l[0] &&
15 i->ifinfo.ip.ip.v6.l[1] == addr->ip.v6.l[1] &&
16 i->ifinfo.ip.ip.v6.l[2] == addr->ip.v6.l[2] &&
17 i->ifinfo.ip.ip.v6.l[3] == addr->ip.v6.l[3])
18 )
19 return i->ifinfo.InterfaceID;
20 }
21 return(NULL);
22 }
23
24 mDNSexport void SetInterfaces_ut(mDNSInterfaceID* pri_id, mDNSAddr *pri_v4, mDNSAddr* pri_v6, mDNSAddr* pri_router)
25 {
26 mDNSs32 utc = mDNSPlatformUTC();
27
28 MarkAllInterfacesInactive(utc);
29 UpdateInterfaceList(utc);
30 ClearInactiveInterfaces(utc);
31 SetupActiveInterfaces(utc);
32
33 // set primary interface info
34 {
35 mDNSAddr* addr;
36 NetworkChangedKey_IPv4 = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
37 NetworkChangedKey_IPv6 = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, kSCDynamicStoreDomainState, kSCEntNetIPv6);
38 NetworkChangedKey_Hostnames = SCDynamicStoreKeyCreateHostNames(NULL);
39 NetworkChangedKey_Computername = SCDynamicStoreKeyCreateComputerName(NULL);
40 NetworkChangedKey_DNS = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, kSCDynamicStoreDomainState, kSCEntNetDNS);
41 NetworkChangedKey_StateInterfacePrefix = SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL, kSCDynamicStoreDomainState, CFSTR(""), NULL);
42
43 mDNSPlatformGetPrimaryInterface(pri_v4, pri_v6, pri_router);
44 addr = (pri_v4->type == mDNSAddrType_IPv4) ? pri_v4 : pri_v6;
45 *pri_id = SearchForInterfaceByAddr(addr);
46
47 CFRelease(NetworkChangedKey_IPv4);
48 CFRelease(NetworkChangedKey_IPv6);
49 CFRelease(NetworkChangedKey_Hostnames);
50 CFRelease(NetworkChangedKey_Computername);
51 CFRelease(NetworkChangedKey_DNS);
52 CFRelease(NetworkChangedKey_StateInterfacePrefix);
53 }
54 }
55
56 mDNSexport mDNSBool mDNSMacOSXCreateEtcHostsEntry_ut(const domainname *domain, const struct sockaddr *sa, const domainname *cname, char *ifname, AuthHash *auth)
57 {
58 return mDNSMacOSXCreateEtcHostsEntry(domain, sa, cname, ifname, auth);
59 }
60
61 mDNSexport void UpdateEtcHosts_ut(void *context)
62 {
63 mDNS_Lock(&mDNSStorage);
64 UpdateEtcHosts(&mDNSStorage, context);
65 mDNS_Unlock(&mDNSStorage);
66 }