1*4a64e381SAndroid Build Coastguard WorkerFrom 4f7970ac1615aba7a39ae94c1ca14135265574e9 Mon Sep 17 00:00:00 2001
2*4a64e381SAndroid Build Coastguard WorkerMessage-ID: <4f7970ac1615aba7a39ae94c1ca14135265574e9.1687508149.git.stefan@agner.ch>
3*4a64e381SAndroid Build Coastguard WorkerIn-Reply-To: <e136dcdcdd93ef32ada981e89c195905eb809eea.1687508149.git.stefan@agner.ch>
4*4a64e381SAndroid Build Coastguard WorkerReferences: <e136dcdcdd93ef32ada981e89c195905eb809eea.1687508149.git.stefan@agner.ch>
5*4a64e381SAndroid Build Coastguard WorkerFrom: Nate Karstens <[email protected]>
6*4a64e381SAndroid Build Coastguard WorkerDate: Wed, 28 Jun 2017 17:30:00 -0500
7*4a64e381SAndroid Build Coastguard WorkerSubject: [PATCH] Create subroutine for cleaning recent interfaces
8*4a64e381SAndroid Build Coastguard Worker
9*4a64e381SAndroid Build Coastguard WorkerMoves functionality for cleaning the list of recent
10*4a64e381SAndroid Build Coastguard Workerinterfaces into its own subroutine.
11*4a64e381SAndroid Build Coastguard Worker
12*4a64e381SAndroid Build Coastguard WorkerUpstream-Status: Submitted [[email protected]]
13*4a64e381SAndroid Build Coastguard Worker
14*4a64e381SAndroid Build Coastguard WorkerSigned-off-by: Nate Karstens <[email protected]>
15*4a64e381SAndroid Build Coastguard WorkerSigned-off-by: Alex Kiernan <[email protected]>
16*4a64e381SAndroid Build Coastguard Worker---
17*4a64e381SAndroid Build Coastguard Worker mDNSPosix/mDNSPosix.c | 24 ++++++++++++++----------
18*4a64e381SAndroid Build Coastguard Worker 1 file changed, 14 insertions(+), 10 deletions(-)
19*4a64e381SAndroid Build Coastguard Worker
20*4a64e381SAndroid Build Coastguard Workerdiff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
21*4a64e381SAndroid Build Coastguard Workerindex 0a7c3df..fe7242d 100644
22*4a64e381SAndroid Build Coastguard Worker--- a/mDNSPosix/mDNSPosix.c
23*4a64e381SAndroid Build Coastguard Worker+++ b/mDNSPosix/mDNSPosix.c
24*4a64e381SAndroid Build Coastguard Worker@@ -1322,6 +1322,19 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf
25*4a64e381SAndroid Build Coastguard Worker     return err;
26*4a64e381SAndroid Build Coastguard Worker }
27*4a64e381SAndroid Build Coastguard Worker
28*4a64e381SAndroid Build Coastguard Worker+// Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
29*4a64e381SAndroid Build Coastguard Worker+mDNSlocal void CleanRecentInterfaces(void)
30*4a64e381SAndroid Build Coastguard Worker+{
31*4a64e381SAndroid Build Coastguard Worker+    PosixNetworkInterface **ri = &gRecentInterfaces;
32*4a64e381SAndroid Build Coastguard Worker+    const mDNSs32 utc = mDNSPlatformUTC();
33*4a64e381SAndroid Build Coastguard Worker+    while (*ri)
34*4a64e381SAndroid Build Coastguard Worker+    {
35*4a64e381SAndroid Build Coastguard Worker+        PosixNetworkInterface *pi = *ri;
36*4a64e381SAndroid Build Coastguard Worker+        if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next;
37*4a64e381SAndroid Build Coastguard Worker+        else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; mdns_free(pi); }
38*4a64e381SAndroid Build Coastguard Worker+    }
39*4a64e381SAndroid Build Coastguard Worker+}
40*4a64e381SAndroid Build Coastguard Worker+
41*4a64e381SAndroid Build Coastguard Worker // Creates a PosixNetworkInterface for the interface whose IP address is
42*4a64e381SAndroid Build Coastguard Worker // intfAddr and whose name is intfName and registers it with mDNS core.
43*4a64e381SAndroid Build Coastguard Worker mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask,
44*4a64e381SAndroid Build Coastguard Worker@@ -1559,16 +1572,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m)
45*4a64e381SAndroid Build Coastguard Worker
46*4a64e381SAndroid Build Coastguard Worker     // Clean up.
47*4a64e381SAndroid Build Coastguard Worker     if (intfList != NULL) freeifaddrs(intfList);
48*4a64e381SAndroid Build Coastguard Worker-
49*4a64e381SAndroid Build Coastguard Worker-    // Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
50*4a64e381SAndroid Build Coastguard Worker-    PosixNetworkInterface **ri = &gRecentInterfaces;
51*4a64e381SAndroid Build Coastguard Worker-    const mDNSs32 utc = mDNSPlatformUTC();
52*4a64e381SAndroid Build Coastguard Worker-    while (*ri)
53*4a64e381SAndroid Build Coastguard Worker-    {
54*4a64e381SAndroid Build Coastguard Worker-        PosixNetworkInterface *pi = *ri;
55*4a64e381SAndroid Build Coastguard Worker-        if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next;
56*4a64e381SAndroid Build Coastguard Worker-        else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; mdns_free(pi); }
57*4a64e381SAndroid Build Coastguard Worker-    }
58*4a64e381SAndroid Build Coastguard Worker+    CleanRecentInterfaces();
59*4a64e381SAndroid Build Coastguard Worker
60*4a64e381SAndroid Build Coastguard Worker     return err;
61*4a64e381SAndroid Build Coastguard Worker }
62*4a64e381SAndroid Build Coastguard Worker--
63*4a64e381SAndroid Build Coastguard Worker2.41.0
64*4a64e381SAndroid Build Coastguard Worker
65