Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame^] | 1 | From 89ea6ac4a8840e8c2be0140a9805c6522c6c5280 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 01/11] 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 | --- |
| 13 | mDNSPosix/mDNSPosix.c | 24 ++++++++++++++---------- |
| 14 | 1 file changed, 14 insertions(+), 10 deletions(-) |
| 15 | |
| 16 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c |
| 17 | index 0e10bd5..ffc9696 100644 |
| 18 | --- a/mDNSPosix/mDNSPosix.c |
| 19 | +++ b/mDNSPosix/mDNSPosix.c |
| 20 | @@ -856,6 +856,19 @@ mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interf |
| 21 | 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) |
| 40 | @@ -1010,16 +1023,7 @@ mDNSlocal int SetupInterfaceList(mDNS *const m) |
| 41 | |
| 42 | // Clean up. |
| 43 | if (intfList != NULL) free_ifi_info(intfList); |
| 44 | - |
| 45 | - // Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute |
| 46 | - PosixNetworkInterface **ri = &gRecentInterfaces; |
| 47 | - const mDNSs32 utc = mDNSPlatformUTC(); |
| 48 | - while (*ri) |
| 49 | - { |
| 50 | - PosixNetworkInterface *pi = *ri; |
| 51 | - if (utc - pi->LastSeen < 60) ri = (PosixNetworkInterface **)&pi->coreIntf.next; |
| 52 | - else { *ri = (PosixNetworkInterface *)pi->coreIntf.next; free(pi); } |
| 53 | - } |
| 54 | + CleanRecentInterfaces(); |
| 55 | |
| 56 | return err; |
| 57 | } |
| 58 | -- |
| 59 | 2.17.1 |
| 60 | |