Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/network_info_plus/network_info_plus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

- Add IP v6 to MacOS

## 2.0.0

- Remove deprecated method `registerWith` (of Android v1 embedding)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/network_info_plus/network_info_plus/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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/

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

- Add IP v6 support

## 1.0.1

- Improve documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,3 @@
#include <arpa/inet.h>
#include <ifaddrs.h>

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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import CoreWLAN
import FlutterMacOS
import SystemConfiguration.CaptiveNetwork


public class NetworkInfoPlusPlugin: NSObject, FlutterPlugin {
var cwinterface: CWInterface?

Expand All @@ -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<ifaddrs>?
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
}

Original file line number Diff line number Diff line change
@@ -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/

Expand Down