blob: 91198dea733cadc4c9e77dafad5009d1529144f0 [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001From c1f3e19d3cb0aa948248616eb1684a1e80aa39b4 Mon Sep 17 00:00:00 2001
2From: Nate Karstens <nate.karstens@garmin.com>
3Date: Wed, 28 Jun 2017 17:30:00 -0500
4Subject: [PATCH 1/8] Create subroutine for cleaning recent interfaces
5
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>
12Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
13---
14 mDNSPosix/mDNSPosix.c | 24 ++++++++++++++----------
15 1 file changed, 14 insertions(+), 10 deletions(-)
16
17diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
18index 0a7c3dfa2475..fe7242d83599 100644
19--- a/mDNSPosix/mDNSPosix.c
20+++ b/mDNSPosix/mDNSPosix.c
21@@ -1322,6 +1322,19 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf
22 return err;
23 }
24
25+// Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
26+mDNSlocal void CleanRecentInterfaces(void)
27+{
28+ PosixNetworkInterface **ri = &gRecentInterfaces;
29+ const mDNSs32 utc = mDNSPlatformUTC();
30+ while (*ri)
31+ {
32+ PosixNetworkInterface *pi = *ri;
33+ if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next;
34+ else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; mdns_free(pi); }
35+ }
36+}
37+
38 // Creates a PosixNetworkInterface for the interface whose IP address is
39 // intfAddr and whose name is intfName and registers it with mDNS core.
40 mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask,
41@@ -1559,16 +1572,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m)
42
43 // Clean up.
44 if (intfList != NULL) freeifaddrs(intfList);
45-
46- // Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
47- PosixNetworkInterface **ri = &gRecentInterfaces;
48- const mDNSs32 utc = mDNSPlatformUTC();
49- while (*ri)
50- {
51- PosixNetworkInterface *pi = *ri;
52- if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next;
53- else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; mdns_free(pi); }
54- }
55+ CleanRecentInterfaces();
56
57 return err;
58 }
59--
602.35.1
61