Пример #1
0
        /// <summary>
        /// Convert Java InetAddress to .Net IPAddress.
        /// </summary>
        /// <param name="inetAddress">The InetAddress object.</param>
        /// <returns>The equivalent .Net IPAddress object.</returns>
        /// <exception cref="System.ArgumentException">Failed to parse InetAddress: ...</exception>
        public static System.Net.IPAddress ToIPAddress(this Java.Net.InetAddress inetAddress)
        {
            if (inetAddress == null)
            {
                return(null);
            }

            // Use get the bytes and create an IP address from that
            if (inetAddress.GetAddress() != null && inetAddress.GetAddress().Length > 0)
            {
                return(new System.Net.IPAddress(inetAddress.GetAddress()));
            }

            // Use the host name string which should be in the standard "1.2.3.4" format
            System.Net.IPAddress ipAddress;
            if (System.Net.IPAddress.TryParse(inetAddress.HostAddress, out ipAddress))
            {
                return(ipAddress);
            }

            // In Android 7 (Nougat) both of the above return null for IPv4 addresses however ToString still appears to work

            // The IP address should be the bit following the slash
            string str = inetAddress.ToString().Split('/').LastOrDefault();

            if (System.Net.IPAddress.TryParse(str, out ipAddress))
            {
                return(ipAddress);
            }

            // Don't know what else to try
            throw new ArgumentException(string.Format("Failed to parse InetAddress: {0}", inetAddress.ToString()));
        }
Пример #2
0
        public static string ConvertIpAddress(Java.Net.InetAddress inetAddress)
        {
            if (inetAddress == null)
            {
                return(null);
            }

            try
            {
                string address = inetAddress.HostAddress;
                if (address == null)
                {
                    string text = inetAddress.ToString();
                    System.Text.RegularExpressions.Match match =
                        System.Text.RegularExpressions.Regex.Match(text, @"\d+\.\d+\.\d+\.\d+$", System.Text.RegularExpressions.RegexOptions.Singleline);
                    if (match.Success)
                    {
                        address = match.Value;
                    }
                }
                return(address);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #3
0
 public static string ConvertIpAddress(int ipAddress)
 {
     if (Java.Nio.ByteOrder.NativeOrder().Equals(Java.Nio.ByteOrder.LittleEndian))
     {
         ipAddress = Java.Lang.Integer.ReverseBytes(ipAddress);
     }
     byte[] ipByteArray = Java.Math.BigInteger.ValueOf(ipAddress).ToByteArray();
     try
     {
         Java.Net.InetAddress inetAddress = Java.Net.InetAddress.GetByAddress(ipByteArray);
         string address = inetAddress.HostAddress;
         if (address == null)
         {
             string text = inetAddress.ToString();
             System.Text.RegularExpressions.Match match =
                 System.Text.RegularExpressions.Regex.Match(text, @"\d+\.\d+\.\d+\.\d+$", System.Text.RegularExpressions.RegexOptions.Singleline);
             if (match.Success)
             {
                 address = match.Value;
             }
         }
         return(address);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Пример #4
0
        public bool CBCMGWiFiConnected()
        {
            bool   wc     = false;
            bool   gc     = false;
            String WiFiIP = null;

            if (WiFiStatus() == NetworkState.ConnectedWifi)
            {
                wc = true;
                PlayWiFiConnected();
                Java.Util.IEnumeration networkInterfaces = Java.Net.NetworkInterface.NetworkInterfaces;
                while (networkInterfaces.HasMoreElements)
                {
                    Java.Net.NetworkInterface netInterface = (Java.Net.NetworkInterface)networkInterfaces.NextElement();
                    Java.Util.IEnumeration    a            = netInterface.InetAddresses;
                    while (a.HasMoreElements)
                    {
                        Java.Net.InetAddress b = (Java.Net.InetAddress)a.NextElement();
                        String IP = b.GetAddress()[0] + "." + b.GetAddress()[1] + "." + b.GetAddress()[2] + "." + b.GetAddress()[3];
                        if (IP.StartsWith(IPRange, StringComparison.Ordinal))
                        {
                            WiFiIP = IP;
                            gc     = true;
                            PlayCBCMGWiFiConnected();
                        }
                    }
                }
            }
            LOGMSG("IP " + WiFiIP + " WiFi connected: " + wc + " CBCMG connected: " + gc + " " + sd.GetEnabled() + ":" + WiFiConnectDateTime + " " + WiFiDisconnectWarning + ":" + WiFiDisconnectDateTime + " " + sd.GetMovingDateTime());
            return(gc);
        }
        public override Java.Net.Socket CreateSocket(Java.Net.InetAddress address, int port, Java.Net.InetAddress localAddress, int localPort)
        {
            SSLSocket socket = (SSLSocket)_factory.CreateSocket(address, port, localAddress, localPort);

            socket.SetEnabledProtocols(socket.GetSupportedProtocols());

            return(socket);
        }
        public override Java.Net.Socket CreateSocket(Java.Net.InetAddress host, int port)
        {
            SSLSocket socket = (SSLSocket)_factory.CreateSocket(host, port);

            socket.SetEnabledProtocols(socket.GetSupportedProtocols());

            return(socket);
        }
Пример #7
0
        public override Java.Net.Socket CreateSocket(string host, int port, Java.Net.InetAddress localHost, int localPort)
        {
            SSLSocket socket = (SSLSocket)factory.CreateSocket(host, port, localHost, localPort);

            socket.SetEnabledProtocols(socket.GetSupportedProtocols());

            return(socket);
        }
        public void Destination(Java.Net.InetAddress address, int port)
        {
            this.port     = port;
            upack.Port    = port;
            upack.Address = address;

            /*ipEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.35"), port);
             * connection = new UdpClient();
             * connection.Connect(ipEndPoint);*/
        }
Пример #9
0
 public static string ConvertIpAddress(int ipAddress)
 {
     if (Java.Nio.ByteOrder.NativeOrder().Equals(Java.Nio.ByteOrder.LittleEndian))
     {
         ipAddress = Java.Lang.Integer.ReverseBytes(ipAddress);
     }
     byte[] ipByteArray = Java.Math.BigInteger.ValueOf(ipAddress).ToByteArray();
     try
     {
         Java.Net.InetAddress inetAddress = Java.Net.InetAddress.GetByAddress(ipByteArray);
         return(ConvertIpAddress(inetAddress));
     }
     catch (Exception)
     {
         return(null);
     }
 }
		public Session(Java.Net.InetAddress destination, int videoPort) {
			this.destination = destination;
			this.videoPort = videoPort;
		}
 public RtpSocket(byte[] buffer, Java.Net.InetAddress dest, int dport)
 {
     upack.Port    = dport;
     upack.Address = dest;
 }
Пример #12
0
 public void SetDestination(Java.Net.InetAddress address, int port)
 {
     packetizer.SetDestination(address, port);
 }
 /** The destination address for all the streams of the session
  * @param destination The destination address
  */
 public void SetDestination(Java.Net.InetAddress destination)
 {
     this.destination = destination;
 }
Пример #14
0
        public static void ExecuteNetworkCommand(ExecuteNetworkDelegate command, IPAddress ipAddr, object networkDataObject)
        {
#if Android
            if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.Lollipop)
            {
                command();
                return;
            }
            Android.Net.Network             bindNetwork         = null;
            NetworkData                     networkData         = networkDataObject as NetworkData;
            Android.Net.ConnectivityManager connectivityManager = networkData?.ConnectivityManager;
            Java.Net.InetAddress            inetAddr            = Java.Net.InetAddress.GetByName(ipAddr.ToString());
            // ReSharper disable once UseNullPropagation
            if (connectivityManager != null && inetAddr is Java.Net.Inet4Address inet4Addr)
            {
                System.Collections.Generic.List <Android.Net.Network> networkList = new System.Collections.Generic.List <Android.Net.Network>();
                lock (networkData.LockObject)
                {
                    networkList.AddRange(networkData.ActiveWifiNetworks);
                    networkList.AddRange(networkData.ActiveEthernetNetworks);
                }

                foreach (Android.Net.Network network in networkList)
                {
                    Android.Net.NetworkCapabilities networkCapabilities = connectivityManager.GetNetworkCapabilities(network);
                    // HasTransport support started also with Lollipop
                    if (networkCapabilities != null)
                    {
                        bool linkValid = false;
                        Android.Net.LinkProperties linkProperties = connectivityManager.GetLinkProperties(network);
                        if (linkProperties != null)
                        {
                            foreach (Android.Net.LinkAddress linkAddress in linkProperties.LinkAddresses)
                            {
                                if (linkAddress.Address is Java.Net.Inet4Address linkInet4Address)
                                {
                                    Java.Net.NetworkInterface networkInterface = Java.Net.NetworkInterface.GetByInetAddress(linkInet4Address);
                                    if (networkInterface != null && networkInterface.IsUp &&
                                        (linkInet4Address.IsSiteLocalAddress || linkInet4Address.IsLinkLocalAddress))
                                    {
                                        foreach (Java.Net.InterfaceAddress interfaceAddress in networkInterface.InterfaceAddresses)
                                        {
                                            if (interfaceAddress.Address is Java.Net.Inet4Address)
                                            {
                                                byte[] linkAddrBytes  = interfaceAddress.Address.GetAddress();
                                                byte[] inet4AddrBytes = inet4Addr.GetAddress();
                                                if (linkAddrBytes.Length == inet4AddrBytes.Length)
                                                {
                                                    for (int bit = interfaceAddress.NetworkPrefixLength; bit < linkAddrBytes.Length * 8; bit++)
                                                    {
                                                        int  index = bit >> 3;
                                                        byte mask  = (byte)(0x80 >> (bit & 0x07));
                                                        linkAddrBytes[index]  |= mask;
                                                        inet4AddrBytes[index] |= mask;
                                                    }
                                                }

                                                if (linkAddrBytes.SequenceEqual(inet4AddrBytes))
                                                {
                                                    linkValid = true;
                                                    break;
                                                }
                                            }
                                        }

                                        if (linkValid)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (linkValid)
                        {
                            bindNetwork = network;
                            break;
                        }
                    }
                }
            }

            if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.M)
            {
#pragma warning disable 618
                Android.Net.Network defaultNetwork = Android.Net.ConnectivityManager.ProcessDefaultNetwork;
                try
                {
                    Android.Net.ConnectivityManager.SetProcessDefaultNetwork(bindNetwork);
                    command();
                }
                finally
                {
                    Android.Net.ConnectivityManager.SetProcessDefaultNetwork(defaultNetwork);
                }
#pragma warning restore 618
                return;
            }
            Android.Net.Network boundNetwork = connectivityManager?.BoundNetworkForProcess;
            try
            {
                connectivityManager?.BindProcessToNetwork(bindNetwork);
                command();
            }
            finally
            {
                connectivityManager?.BindProcessToNetwork(boundNetwork);
            }
#else
            command();
#endif
        }
Пример #15
0
 public void SetDestination(Java.Net.InetAddress address, int port)
 {
     socket.Destination(address, port);
 }
 public Session(Java.Net.InetAddress destination, int videoPort)
 {
     this.destination = destination;
     this.videoPort   = videoPort;
 }
		/** The destination address for all the streams of the session
		 * @param destination The destination address
		 */
		public void SetDestination(Java.Net.InetAddress destination) {
			this.destination =  destination;
		}