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