updated network stack interface address check handling in ios/osx
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||
|
||||
@@ -183,12 +183,11 @@ class ViewController: UIViewController {
|
||||
while(true)
|
||||
{
|
||||
sleep(1)
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
//var str_buf = [Int8](count: 16, repeatedValue: 0)
|
||||
//print(self.zt.get_address(self.txtNWID.text!)) //, &str_buf);
|
||||
//self.lblAddress.text = String.fromCString(str_buf)
|
||||
// print("IPV4 = ", String.fromCString(str_buf))
|
||||
var str_buf = [Int8](count: 16, repeatedValue: 0)
|
||||
self.zt.get_ipv6_address(self.txtNWID.text!, &str_buf)
|
||||
self.lblAddress.text = String.fromCString(str_buf)
|
||||
print("addr = ", String.fromCString(str_buf))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -165,12 +165,14 @@ void zts_get_ipv4_address(const char *nwid, char *addrstr)
|
||||
uint64_t nwid_int = strtoull(nwid, NULL, 16);
|
||||
ZeroTier::NetconEthernetTap * tap = zt1Service->getTaps()[nwid_int];
|
||||
if(tap && tap->_ips.size()){
|
||||
for(int i=0; i<tap->_ips.size(); i++)
|
||||
{
|
||||
std::string addr = tap->_ips[0].toString();
|
||||
DEBUG_EXTRA("addr=%s, addrlen=%d", addr.c_str(), addr.length());
|
||||
for(int i=0; i<tap->_ips.size(); i++) {
|
||||
if(tap->_ips[i].isV4()) {
|
||||
std::string addr = tap->_ips[i].toString();
|
||||
// DEBUG_EXTRA("addr=%s, addrlen=%d", addr.c_str(), addr.length());
|
||||
memcpy(addrstr, addr.c_str(), addr.length()); // first address found that matches protocol version 4
|
||||
return;
|
||||
}
|
||||
}
|
||||
//memcpy(addrstr, addr.c_str(), addr.length());
|
||||
}
|
||||
else {
|
||||
memcpy(addrstr, "-1.-1.-1.-1/-1", 14);
|
||||
@@ -182,9 +184,14 @@ void zts_get_ipv6_address(const char *nwid, char *addrstr)
|
||||
uint64_t nwid_int = strtoull(nwid, NULL, 16);
|
||||
ZeroTier::NetconEthernetTap * tap = zt1Service->getTaps()[nwid_int];
|
||||
if(tap && tap->_ips.size()){
|
||||
std::string addr = tap->_ips[0].toString();
|
||||
DEBUG_EXTRA("addr=%s, addrlen=%d", addr.c_str(), addr.length());
|
||||
memcpy(addrstr, addr.c_str(), addr.length());
|
||||
for(int i=0; i<tap->_ips.size(); i++){
|
||||
if(tap->_ips[i].isV6()) {
|
||||
std::string addr = tap->_ips[i].toString();
|
||||
// DEBUG_EXTRA("addr=%s, addrlen=%d", addr.c_str(), addr.length());
|
||||
memcpy(addrstr, addr.c_str(), addr.length()); // first address found that matches protocol version 6
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
memcpy(addrstr, "-1.-1.-1.-1/-1", 14);
|
||||
|
||||
@@ -755,7 +755,6 @@ bool NetconEthernetTap::enabled() const
|
||||
void NetconEthernetTap::lwIP_init_interface(const InetAddress &ip)
|
||||
{
|
||||
#if defined(SDK_LWIP)
|
||||
DEBUG_INFO("local_addr=%s", ip.toString().c_str());
|
||||
Mutex::Lock _l(_ips_m);
|
||||
|
||||
if (std::find(_ips.begin(),_ips.end(),ip) == _ips.end()) {
|
||||
@@ -764,7 +763,7 @@ void NetconEthernetTap::lwIP_init_interface(const InetAddress &ip)
|
||||
|
||||
#if defined(SDK_IPV4)
|
||||
if (ip.isV4()) {
|
||||
DEBUG_INFO("IPV4");
|
||||
DEBUG_INFO("local_addr=%s", ip.toString().c_str());
|
||||
// convert address
|
||||
static ip_addr_t ipaddr, netmask, gw;
|
||||
IP4_ADDR((ip4_addr_t *)&gw,127,0,0,1);
|
||||
@@ -789,7 +788,7 @@ void NetconEthernetTap::lwIP_init_interface(const InetAddress &ip)
|
||||
|
||||
#if defined(SDK_IPV6)
|
||||
if(ip.isV6()) {
|
||||
DEBUG_INFO("IPV6");
|
||||
DEBUG_INFO("local_addr=%s", ip.toString().c_str());
|
||||
// convert address
|
||||
static ip6_addr_t addr6;
|
||||
struct sockaddr_in6 in6;
|
||||
@@ -862,7 +861,7 @@ std::vector<InetAddress> NetconEthernetTap::ips() const
|
||||
void NetconEthernetTap::lwIP_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||
{
|
||||
#if defined(SDK_LWIP)
|
||||
DEBUG_INFO();
|
||||
// DEBUG_EXTRA();
|
||||
struct pbuf *p,*q;
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
@@ -84,18 +84,13 @@ class ZTSDK : NSObject
|
||||
}
|
||||
|
||||
// Returns the IPV4 address of this device on a given ZeroTier network
|
||||
func get_ipv4_address(nwid: String) -> String? {
|
||||
var str_buf = [Int8](count: 16, repeatedValue: 0)
|
||||
zt_get_ipv4_address(nwid,&str_buf)
|
||||
return String.fromCString(str_buf)
|
||||
//return "IPV4"
|
||||
func get_ipv4_address(nwid: String, inout _ addrbuf: [Int8]) {
|
||||
zt_get_ipv4_address(nwid,&addrbuf)
|
||||
}
|
||||
|
||||
// Returns the IPV6 address of this device on a given ZeroTier network
|
||||
func get_ipv6_address(nwid: String) -> String? {
|
||||
var str_buf = [Int8](count: 16, repeatedValue: 0)
|
||||
zt_get_ipv6_address(nwid,&str_buf)
|
||||
return String.fromCString(str_buf)
|
||||
func get_ipv6_address(nwid: String, inout _ addrbuf: [Int8]) {
|
||||
zt_get_ipv6_address(nwid,&addrbuf)
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +122,9 @@ class ZTSDK : NSObject
|
||||
|
||||
*/
|
||||
|
||||
// TODO: Verify this hasn't been broken. Should check for interface addresses based on
|
||||
// protocol version. (important)
|
||||
|
||||
// SOCKET API
|
||||
func socket(socket_family: Int32, _ socket_type: Int32, _ socket_protocol: Int32) -> Int32 {
|
||||
return zt_socket(socket_family, socket_type, socket_protocol);
|
||||
@@ -137,7 +135,10 @@ class ZTSDK : NSObject
|
||||
return zt_connect(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
||||
}
|
||||
while(true) { // politely wait until an address is provided. simulates a blocking call
|
||||
if(self.get_ipv4_address(nwid!) != nil) {
|
||||
var addrbuf = [Int8](count: 16, repeatedValue: 0)
|
||||
self.get_ipv4_address(nwid!, &addrbuf)
|
||||
var addr_str:String = String.fromCString(addrbuf)!
|
||||
if(addr_str != "-1.-1.-1.-1/-1") {
|
||||
return zt_connect(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
||||
}
|
||||
}
|
||||
@@ -147,7 +148,10 @@ class ZTSDK : NSObject
|
||||
return zt_bind(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
||||
}
|
||||
while(true) { // politely wait until an address is provided. simulates a blocking call
|
||||
if(self.get_ipv4_address(nwid!) != nil) {
|
||||
var addrbuf = [Int8](count: 16, repeatedValue: 0)
|
||||
self.get_ipv4_address(nwid!, &addrbuf)
|
||||
var addr_str:String = String.fromCString(addrbuf)!
|
||||
if(addr_str != "-1.-1.-1.-1/-1") {
|
||||
return zt_bind(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user