Skip to content

Commit

Permalink
Deprecate AllIPAddresses and IPAddress in favor of `networkInterf…
Browse files Browse the repository at this point in the history
…aces`.

Closes #1
  • Loading branch information
thecatalinstan committed Jun 18, 2021
1 parent 3d9127a commit 898069b
Show file tree
Hide file tree
Showing 17 changed files with 886 additions and 83 deletions.
2 changes: 1 addition & 1 deletion CSSystemInfoHelper.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.module_name = "CSSystemInfoHelper"

s.source_files = "CSSystemInfoHelper/Sources/*.{h,m}", "CSSystemInfoHelper/Headers/CSSystemInfoHelper/*.h"
s.public_header_files = "CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSSystemInfoHelper.h"
s.public_header_files = "CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSSystemInfoHelper.h", "CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSNetworkInterface.h"

s.ios.deployment_target = "9.0"
s.ios.frameworks = "Foundation"
Expand Down
45 changes: 45 additions & 0 deletions CSSystemInfoHelper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
objects = {

/* Begin PBXBuildFile section */
AD143BA1267C7D350094D246 /* CSSystemInfoProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = AD143B9F267C7D350094D246 /* CSSystemInfoProvider.h */; };
AD143BA2267C7D350094D246 /* CSSystemInfoProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = AD143BA0267C7D350094D246 /* CSSystemInfoProvider.m */; };
AD143BA4267C80760094D246 /* CSSystemInfoHelper+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = AD143BA3267C80760094D246 /* CSSystemInfoHelper+Internal.h */; };
AD143BA7267C87450094D246 /* CSSystemInfoProviderMock.m in Sources */ = {isa = PBXBuildFile; fileRef = AD143BA6267C87450094D246 /* CSSystemInfoProviderMock.m */; };
AD352510267CB84700A3A929 /* CSSystemInfoHelperDeprecatedTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AD35250F267CB84700A3A929 /* CSSystemInfoHelperDeprecatedTests.m */; };
AD3BFDF0267AA56600FF8076 /* CSSystemInfoHelper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD3BFDE6267AA56600FF8076 /* CSSystemInfoHelper.framework */; };
AD3BFDF5267AA56600FF8076 /* CSSystemInfoHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AD3BFDF4267AA56600FF8076 /* CSSystemInfoHelperTests.m */; };
AD3BFE07267AA5BD00FF8076 /* CSSystemInfoHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = AD3BFE03267AA5BD00FF8076 /* CSSystemInfoHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
AD3BFE08267AA5BD00FF8076 /* CSSystemInfoHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = AD3BFE05267AA5BD00FF8076 /* CSSystemInfoHelper.m */; };
ADB06B24267B5A2400D4F0E3 /* CSNetworkInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = ADB06B22267B5A2400D4F0E3 /* CSNetworkInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
ADB06B25267B5A2400D4F0E3 /* CSNetworkInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = ADB06B23267B5A2400D4F0E3 /* CSNetworkInterface.m */; };
ADB06B27267B5B6E00D4F0E3 /* CSNetworkInterface+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = ADB06B26267B5B6E00D4F0E3 /* CSNetworkInterface+Internal.h */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -24,13 +32,23 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
AD143B9F267C7D350094D246 /* CSSystemInfoProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSSystemInfoProvider.h; sourceTree = "<group>"; };
AD143BA0267C7D350094D246 /* CSSystemInfoProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CSSystemInfoProvider.m; sourceTree = "<group>"; };
AD143BA3267C80760094D246 /* CSSystemInfoHelper+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CSSystemInfoHelper+Internal.h"; sourceTree = "<group>"; };
AD143BA5267C87450094D246 /* CSSystemInfoProviderMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSystemInfoProviderMock.h; sourceTree = "<group>"; };
AD143BA6267C87450094D246 /* CSSystemInfoProviderMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSystemInfoProviderMock.m; sourceTree = "<group>"; };
AD35250F267CB84700A3A929 /* CSSystemInfoHelperDeprecatedTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CSSystemInfoHelperDeprecatedTests.m; sourceTree = "<group>"; };
AD3BFDE6267AA56600FF8076 /* CSSystemInfoHelper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CSSystemInfoHelper.framework; sourceTree = BUILT_PRODUCTS_DIR; };
AD3BFDEF267AA56600FF8076 /* CSSystemInfoHelperTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CSSystemInfoHelperTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
AD3BFDF4267AA56600FF8076 /* CSSystemInfoHelperTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CSSystemInfoHelperTests.m; sourceTree = "<group>"; };
AD3BFDF6267AA56600FF8076 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
AD3BFE03267AA5BD00FF8076 /* CSSystemInfoHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSystemInfoHelper.h; sourceTree = "<group>"; };
AD3BFE05267AA5BD00FF8076 /* CSSystemInfoHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSystemInfoHelper.m; sourceTree = "<group>"; };
AD3BFE06267AA5BD00FF8076 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
ADB06B22267B5A2400D4F0E3 /* CSNetworkInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSNetworkInterface.h; sourceTree = "<group>"; };
ADB06B23267B5A2400D4F0E3 /* CSNetworkInterface.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CSNetworkInterface.m; sourceTree = "<group>"; };
ADB06B26267B5B6E00D4F0E3 /* CSNetworkInterface+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CSNetworkInterface+Internal.h"; sourceTree = "<group>"; };
ADB06B28267B608800D4F0E3 /* Errors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Errors.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -52,12 +70,20 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
AD2D059D267ABDAC006B76EB /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
AD3BFDDC267AA56600FF8076 = {
isa = PBXGroup;
children = (
AD3BFE00267AA5BD00FF8076 /* CSSystemInfoHelper */,
AD3BFDF3267AA56600FF8076 /* CSSystemInfoHelperTests */,
AD3BFDE7267AA56600FF8076 /* Products */,
AD2D059D267ABDAC006B76EB /* Frameworks */,
);
sourceTree = "<group>";
};
Expand All @@ -73,7 +99,10 @@
AD3BFDF3267AA56600FF8076 /* CSSystemInfoHelperTests */ = {
isa = PBXGroup;
children = (
AD143BA5267C87450094D246 /* CSSystemInfoProviderMock.h */,
AD143BA6267C87450094D246 /* CSSystemInfoProviderMock.m */,
AD3BFDF4267AA56600FF8076 /* CSSystemInfoHelperTests.m */,
AD35250F267CB84700A3A929 /* CSSystemInfoHelperDeprecatedTests.m */,
AD3BFDF6267AA56600FF8076 /* Info.plist */,
);
path = CSSystemInfoHelperTests;
Expand Down Expand Up @@ -101,14 +130,21 @@
isa = PBXGroup;
children = (
AD3BFE03267AA5BD00FF8076 /* CSSystemInfoHelper.h */,
ADB06B22267B5A2400D4F0E3 /* CSNetworkInterface.h */,
);
path = CSSystemInfoHelper;
sourceTree = "<group>";
};
AD3BFE04267AA5BD00FF8076 /* Sources */ = {
isa = PBXGroup;
children = (
AD143BA3267C80760094D246 /* CSSystemInfoHelper+Internal.h */,
AD3BFE05267AA5BD00FF8076 /* CSSystemInfoHelper.m */,
ADB06B26267B5B6E00D4F0E3 /* CSNetworkInterface+Internal.h */,
ADB06B23267B5A2400D4F0E3 /* CSNetworkInterface.m */,
AD143B9F267C7D350094D246 /* CSSystemInfoProvider.h */,
AD143BA0267C7D350094D246 /* CSSystemInfoProvider.m */,
ADB06B28267B608800D4F0E3 /* Errors.h */,
);
path = Sources;
sourceTree = "<group>";
Expand All @@ -120,7 +156,11 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
ADB06B27267B5B6E00D4F0E3 /* CSNetworkInterface+Internal.h in Headers */,
AD143BA4267C80760094D246 /* CSSystemInfoHelper+Internal.h in Headers */,
AD3BFE07267AA5BD00FF8076 /* CSSystemInfoHelper.h in Headers */,
AD143BA1267C7D350094D246 /* CSSystemInfoProvider.h in Headers */,
ADB06B24267B5A2400D4F0E3 /* CSNetworkInterface.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -169,6 +209,7 @@
AD3BFDDD267AA56600FF8076 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1250;
LastUpgradeCheck = 1250;
TargetAttributes = {
AD3BFDE5267AA56600FF8076 = {
Expand Down Expand Up @@ -220,6 +261,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
ADB06B25267B5A2400D4F0E3 /* CSNetworkInterface.m in Sources */,
AD143BA2267C7D350094D246 /* CSSystemInfoProvider.m in Sources */,
AD3BFE08267AA5BD00FF8076 /* CSSystemInfoHelper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -228,7 +271,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
AD143BA7267C87450094D246 /* CSSystemInfoProviderMock.m in Sources */,
AD3BFDF5267AA56600FF8076 /* CSSystemInfoHelperTests.m in Sources */,
AD352510267CB84700A3A929 /* CSSystemInfoHelperDeprecatedTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AD3BFDE5267AA56600FF8076"
BuildableName = "CSSystemInfoHelper.framework"
BlueprintName = "CSSystemInfoHelper"
ReferencedContainer = "container:CSSystemInfoHelper.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AD3BFDEE267AA56600FF8076"
BuildableName = "CSSystemInfoHelperTests.xctest"
BlueprintName = "CSSystemInfoHelperTests"
ReferencedContainer = "container:CSSystemInfoHelper.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AD3BFDE5267AA56600FF8076"
BuildableName = "CSSystemInfoHelper.framework"
BlueprintName = "CSSystemInfoHelper"
ReferencedContainer = "container:CSSystemInfoHelper.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
26 changes: 26 additions & 0 deletions CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSNetworkInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// CSInterfaceAddress.h
// CSSystemInfoHelper
//
// Created by Cătălin Stan on 17/06/2021.
//

#import <Foundation/Foundation.h>
#import <sys/socket.h>

NS_ASSUME_NONNULL_BEGIN

@interface CSNetworkInterface : NSObject

@property (nonatomic, readonly, strong) NSString *name;
@property (nonatomic, readonly, strong) NSString *address;

@property (nonatomic, readonly) sa_family_t family;
@property (nonatomic, readonly, strong) NSString *familyName;

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
31 changes: 24 additions & 7 deletions CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSSystemInfoHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
FOUNDATION_EXPORT double CSSystemInfoHelperVersionNumber;
FOUNDATION_EXPORT const unsigned char CSSystemInfoHelperVersionString[];

#import <CSSystemInfoHelper/CSNetworkInterface.h>

NS_ASSUME_NONNULL_BEGIN

typedef NSString * CSSystemInfoKey NS_TYPED_EXTENSIBLE_ENUM;
Expand All @@ -26,6 +28,9 @@ FOUNDATION_EXPORT CSSystemInfoKey const CSSystemInfoKeyVersion;
/// Machine hardware platform.
FOUNDATION_EXPORT CSSystemInfoKey const CSSystemInfoKeyMachine;

/// Constant returned when no IP address could be deternimed
FOUNDATION_EXPORT NSString * const CSSystemInfoHelperIPAddressNone DEPRECATED_ATTRIBUTE;

/// The CSSystemInfoHelper class provides easy-access to some useful system
/// information that would otherwise require some more elaborate code.
@interface CSSystemInfoHelper : NSObject
Expand All @@ -37,14 +42,10 @@ FOUNDATION_EXPORT CSSystemInfoKey const CSSystemInfoKeyMachine;

/// @name Getting IP Addresses

/// A dictionary where the keys are interface names and the values are
/// the IP addresses associated with those interfaces.
/// An array of @c CSNetworkInterface objects representing all the IPv4 and IPv6
/// interfaces configured, in the order of discovery, as returned by @c getifaddrs(3)
/// @note Check the @c getifaddrs(3) manual page for more information.
@property (nonatomic, readonly, strong) NSDictionary<NSString *, NSString *> * AllIPAddresses;

/// The IP Address of "en0".
/// @note This is a convenience method for `AllIPAddresses[@"en0"]`.
@property (nonatomic, readonly, strong) NSString *IPAddress;
@property (nonatomic, readonly, strong, nullable) NSArray<CSNetworkInterface *> *networkInterfaces;

/// @name Getting @c uname System Information

Expand Down Expand Up @@ -75,6 +76,22 @@ FOUNDATION_EXPORT CSSystemInfoKey const CSSystemInfoKeyMachine;
/// Get the UUID of the current device
@property (nonatomic, readonly, strong) NSString * platformUUID API_UNAVAILABLE(ios, tvos, watchos);

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

#pragma mark - Deprecated

/// @name Deprecated

/// A dictionary where the keys are interface names and the values are
/// the IP addresses associated with those interfaces.
/// @note Check the @c getifaddrs(3) manual page for more information.
@property (nonatomic, readonly, strong) NSDictionary<NSString *, NSString *> * AllIPAddresses DEPRECATED_MSG_ATTRIBUTE("Use 'networkInterfaces' instead.");

/// The IP Address of "en0".
/// @note This is a convenience method for `AllIPAddresses[@"en0"]`.
@property (nonatomic, readonly, strong) NSString *IPAddress DEPRECATED_MSG_ATTRIBUTE("Use 'networkInterfaces' instead.");

@end

NS_ASSUME_NONNULL_END
23 changes: 23 additions & 0 deletions CSSystemInfoHelper/Sources/CSNetworkInterface+Internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// CSInterfaceAddress+Internal.h
// CSSystemInfoHelper
//
// Created by Cătălin Stan on 17/06/2021.
//

#import <CSSystemInfoHelper/CSNetworkInterface.h>

#import <sys/socket.h>

NS_ASSUME_NONNULL_BEGIN

@interface CSNetworkInterface ()

- (instancetype)initWithName:(NSString *)name
address:(NSString *)address
family:(sa_family_t)family
NS_DESIGNATED_INITIALIZER;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 898069b

Please sign in to comment.