File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,43 @@ @implementation RNNetworkInfo
6161 callback (@[BSSID]);
6262}
6363
64+ RCT_EXPORT_METHOD (getBroadcast:(RCTResponseSenderBlock)callback)
65+ {
66+ NSString *address = @" error" ;
67+ NSString *netmask = @" error" ;
68+
69+ struct ifaddrs *interfaces = NULL ;
70+ struct ifaddrs *temp_addr = NULL ;
71+ int success = 0 ;
72+
73+ success = getifaddrs (&interfaces);
74+
75+ if (success == 0 ) {
76+ temp_addr = interfaces;
77+ while (temp_addr != NULL ) {
78+ if (temp_addr->ifa_addr ->sa_family == AF_INET) {
79+ if ([[NSString stringWithUTF8String: temp_addr->ifa_name] isEqualToString: @" en0" ]) {
80+ address = [NSString stringWithUTF8String: inet_ntoa (((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
81+ netmask = [NSString stringWithUTF8String: inet_ntoa (((struct sockaddr_in *)temp_addr->ifa_netmask)->sin_addr)];
82+
83+ struct in_addr local_addr;
84+ struct in_addr netmask_addr;
85+ inet_aton ([address UTF8String ], &local_addr);
86+ inet_aton ([netmask UTF8String ], &netmask_addr);
87+
88+ local_addr.s_addr |= ~(netmask_addr.s_addr );
89+
90+ address = [NSString stringWithUTF8String: inet_ntoa (local_addr)];
91+ }
92+ }
93+ temp_addr = temp_addr->ifa_next ;
94+ }
95+ }
96+
97+ freeifaddrs (interfaces);
98+ callback (@[address]);
99+ }
100+
64101RCT_EXPORT_METHOD (getIPAddress:(RCTResponseSenderBlock)callback)
65102{
66103 NSString *address = @" error" ;
You can’t perform that action at this time.
0 commit comments