blob: f8efc10448aced225d622ac8cfa18ed7e85db05d [file] [log] [blame]
Andrew Geisslerd688a012020-09-18 13:36:00 -05001From 6d90f9fdaf008f5c3b8fd8d91594fa1461437888 Mon Sep 17 00:00:00 2001
Andrew Geissler82c905d2020-04-13 13:39:40 -05002From: Nate Karstens <nate.karstens@garmin.com>
3Date: Wed, 28 Jun 2017 17:30:00 -0500
Andrew Geisslerd688a012020-09-18 13:36:00 -05004Subject: [PATCH] Create subroutine for cleaning recent interfaces
Andrew Geissler82c905d2020-04-13 13:39:40 -05005
6Moves functionality for cleaning the list of recent
7interfaces into its own subroutine.
8
9Upstream-Status: Submitted [dts@apple.com]
10
11Signed-off-by: Nate Karstens <nate.karstens@garmin.com>
12---
Andrew Geisslerd688a012020-09-18 13:36:00 -050013 mDNSPosix/mDNSPosix.c | 23 ++++++++++++++---------
14 1 file changed, 14 insertions(+), 9 deletions(-)
Andrew Geissler82c905d2020-04-13 13:39:40 -050015
16diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
Andrew Geisslerd688a012020-09-18 13:36:00 -050017index a63cd19..7aeee7b 100755
Andrew Geissler82c905d2020-04-13 13:39:40 -050018--- a/mDNSPosix/mDNSPosix.c
19+++ b/mDNSPosix/mDNSPosix.c
Andrew Geisslerd688a012020-09-18 13:36:00 -050020@@ -1199,6 +1199,19 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf
Andrew Geissler82c905d2020-04-13 13:39:40 -050021 return err;
22 }
23
24+// Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
25+mDNSlocal void CleanRecentInterfaces(void)
26+{
27+ PosixNetworkInterface **ri = &gRecentInterfaces;
28+ const mDNSs32 utc = mDNSPlatformUTC();
29+ while (*ri)
30+ {
31+ PosixNetworkInterface *pi = *ri;
32+ if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next;
33+ else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; free(pi); }
34+ }
35+}
36+
37 // Creates a PosixNetworkInterface for the interface whose IP address is
38 // intfAddr and whose name is intfName and registers it with mDNS core.
39 mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask, const char *intfName, int intfIndex)
Andrew Geisslerd688a012020-09-18 13:36:00 -050040@@ -1388,15 +1401,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m)
Andrew Geissler82c905d2020-04-13 13:39:40 -050041 // Clean up.
Andrew Geisslerd688a012020-09-18 13:36:00 -050042 if (intfList != NULL) freeifaddrs(intfList);
43
Andrew Geissler82c905d2020-04-13 13:39:40 -050044- // Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
45- PosixNetworkInterface **ri = &gRecentInterfaces;
46- const mDNSs32 utc = mDNSPlatformUTC();
47- while (*ri)
48- {
49- PosixNetworkInterface *pi = *ri;
50- if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next;
51- else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; free(pi); }
52- }
53+ CleanRecentInterfaces();
54
55 return err;
56 }
57--
Andrew Geisslerd688a012020-09-18 13:36:00 -0500582.20.1
Andrew Geissler82c905d2020-04-13 13:39:40 -050059