Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 1 | From c1f3e19d3cb0aa948248616eb1684a1e80aa39b4 Mon Sep 17 00:00:00 2001 |
| 2 | From: Nate Karstens <nate.karstens@garmin.com> |
| 3 | Date: Wed, 28 Jun 2017 17:30:00 -0500 |
| 4 | Subject: [PATCH 1/8] Create subroutine for cleaning recent interfaces |
| 5 | |
| 6 | Moves functionality for cleaning the list of recent |
| 7 | interfaces into its own subroutine. |
| 8 | |
| 9 | Upstream-Status: Submitted [dts@apple.com] |
| 10 | |
| 11 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> |
| 12 | Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com> |
| 13 | --- |
| 14 | mDNSPosix/mDNSPosix.c | 24 ++++++++++++++---------- |
| 15 | 1 file changed, 14 insertions(+), 10 deletions(-) |
| 16 | |
| 17 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c |
| 18 | index 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 | -- |
| 60 | 2.35.1 |
| 61 | |