diff --git a/packages/network_info_plus/network_info_plus/CHANGELOG.md b/packages/network_info_plus/network_info_plus/CHANGELOG.md index 924e66498e..0437e84c08 100644 --- a/packages/network_info_plus/network_info_plus/CHANGELOG.md +++ b/packages/network_info_plus/network_info_plus/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.1 + +- Add IP v6 to MacOS + ## 2.0.0 - Remove deprecated method `registerWith` (of Android v1 embedding) diff --git a/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/project.pbxproj b/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/project.pbxproj index e5933e98cf..7b217f4432 100644 --- a/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/project.pbxproj +++ b/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/project.pbxproj @@ -296,12 +296,15 @@ buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework", + "${BUILT_PRODUCTS_DIR}/network_info_plus_macos/network_info_plus_macos.framework", ); name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/network_info_plus_macos.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/packages/network_info_plus/network_info_plus/pubspec.yaml b/packages/network_info_plus/network_info_plus/pubspec.yaml index 4bbdb1445e..21ea70d9bf 100644 --- a/packages/network_info_plus/network_info_plus/pubspec.yaml +++ b/packages/network_info_plus/network_info_plus/pubspec.yaml @@ -1,6 +1,6 @@ name: network_info_plus description: Flutter plugin for discovering information (e.g. WiFi details) of the network. -version: 2.0.0 +version: 2.0.1 homepage: https://plus.fluttercommunity.dev/ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ @@ -27,7 +27,7 @@ dependencies: meta: ^1.3.0 network_info_plus_platform_interface: ^1.0.0 network_info_plus_linux: ^1.0.0 - network_info_plus_macos: ^1.0.0 + network_info_plus_macos: ^1.1.0 network_info_plus_windows: ^1.0.0 network_info_plus_web: ^1.0.0 diff --git a/packages/network_info_plus/network_info_plus_macos/CHANGELOG.md b/packages/network_info_plus/network_info_plus_macos/CHANGELOG.md index 8e694adabb..e1f27a75c0 100644 --- a/packages/network_info_plus/network_info_plus_macos/CHANGELOG.md +++ b/packages/network_info_plus/network_info_plus_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + +- Add IP v6 support + ## 1.0.1 - Improve documentation diff --git a/packages/network_info_plus/network_info_plus_macos/macos/Classes/IPHelper.h b/packages/network_info_plus/network_info_plus_macos/macos/Classes/IPHelper.h index 5fef2b9721..9ec17c7a33 100644 --- a/packages/network_info_plus/network_info_plus_macos/macos/Classes/IPHelper.h +++ b/packages/network_info_plus/network_info_plus_macos/macos/Classes/IPHelper.h @@ -19,33 +19,3 @@ #include #include -NSString* getWifiIP() { - NSString* address = @"error"; - struct ifaddrs* interfaces = NULL; - struct ifaddrs* temp_addr = NULL; - int success = 0; - - // Retrieve the current interfaces - returns 0 on success. - success = getifaddrs(&interfaces); - if (success == 0) { - // Loop through linked list of interfaces. - temp_addr = interfaces; - while (temp_addr != NULL) { - if (temp_addr->ifa_addr->sa_family == AF_INET) { - // Check if interface is en0 which is the wifi connection on the iPhone. - if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) { - // Get NSString from C String - address = [NSString - stringWithUTF8String:inet_ntoa(((struct sockaddr_in*)temp_addr->ifa_addr)->sin_addr)]; - } - } - - temp_addr = temp_addr->ifa_next; - } - } - - // Free memory - freeifaddrs(interfaces); - - return address; -} diff --git a/packages/network_info_plus/network_info_plus_macos/macos/Classes/NetworkInfoPlusPlugin.swift b/packages/network_info_plus/network_info_plus_macos/macos/Classes/NetworkInfoPlusPlugin.swift index 45226789c2..dd92d24416 100644 --- a/packages/network_info_plus/network_info_plus_macos/macos/Classes/NetworkInfoPlusPlugin.swift +++ b/packages/network_info_plus/network_info_plus_macos/macos/Classes/NetworkInfoPlusPlugin.swift @@ -17,6 +17,7 @@ import CoreWLAN import FlutterMacOS import SystemConfiguration.CaptiveNetwork + public class NetworkInfoPlusPlugin: NSObject, FlutterPlugin { var cwinterface: CWInterface? @@ -40,9 +41,53 @@ public class NetworkInfoPlusPlugin: NSObject, FlutterPlugin { case "wifiBSSID": result(cwinterface?.bssid()) case "wifiIPAddress": - result(getWifiIP()) + result(getWiFiAddress(family: AF_INET)) + case "wifiIPv6Address": + result(getWiFiAddress(family: AF_INET6)) + case "wifiSubmask": + result("") + case "wifiBroadcast": + result("") + case "wifiGatewayAddress": + result("") default: result(FlutterMethodNotImplemented) } } } + +// Return IP address of WiFi interface (en0) as a String, or `nil` +func getWiFiAddress(family: Int32) -> String? { + var address : String? + + // Get list of all interfaces on the local machine: + var ifaddr : UnsafeMutablePointer? + guard getifaddrs(&ifaddr) == 0 else { return nil } + guard let firstAddr = ifaddr else { return nil } + + // For each interface ... + for ifptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) { + let interface = ifptr.pointee + + // Check for IPv4 or IPv6 interface: + let addrFamily = interface.ifa_addr.pointee.sa_family + if addrFamily == UInt8(family) { + + // Check interface name: + let name = String(cString: interface.ifa_name) + if name == "en0" { + + // Convert interface address to a human readable string: + var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST)) + getnameinfo(interface.ifa_addr, socklen_t(interface.ifa_addr.pointee.sa_len), + &hostname, socklen_t(hostname.count), + nil, socklen_t(0), NI_NUMERICHOST) + address = String(cString: hostname) + } + } + } + freeifaddrs(ifaddr) + + return address +} + diff --git a/packages/network_info_plus/network_info_plus_macos/pubspec.yaml b/packages/network_info_plus/network_info_plus_macos/pubspec.yaml index 149cce1b21..bebc83eb1d 100644 --- a/packages/network_info_plus/network_info_plus_macos/pubspec.yaml +++ b/packages/network_info_plus/network_info_plus_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: network_info_plus_macos description: macOS implementation of the network_info_plus plugin. -version: 1.0.1 +version: 1.1.0 homepage: https://plus.fluttercommunity.dev/ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/