Beispiel #1
0
        public IntPtr ConnectTo(String host, ushort port, TNET_Socket.tnet_socket_type_t type)
        {
            if (!mStarted)
            {
                TSK_Debug.Error("Transport not started");
                return(IntPtr.Zero);
            }

            if (this.Type != type)
            {
                TSK_Debug.Error("Master/destination types mismatch [{0}/{1}]", this.Type, type);
                return(IntPtr.Zero);
            }

            EndPoint endpoint = TNET_Socket.CreateEndPoint(host, port);

            if (endpoint != null)
            {
                //var args = new SocketAsyncEventArgs();
                //args.RemoteEndPoint = endpoint;
                //args.Completed += this.SocketAsyncEventArgs_Callback;
                // args.SetBuffer(buffer, 0, buffer.Length);

                return(IntPtr.Zero);
            }

            return(IntPtr.Zero);
        }
Beispiel #2
0
        protected TSIP_Transport(TSIP_Stack stack, String host, ushort port, TNET_Socket.tnet_socket_type_t type, String description)
            : base(host, port, type, description)
        {
            mStack  = stack;
            mScheme = TNET_Socket.IsTLSType(type) ? "sips" : "sip";
            if (TNET_Socket.IsStreamType(type))
            {
                mProtocol = "tcp";

                if (TNET_Socket.IsTLSType(type))
                {
                    mViaProtocol = "TLS";
                    mService     = "SIPS+D2T";
                }
                else
                {
                    mViaProtocol = "TCP";
                    mService     = "SIP+D2T";
                }
            }
            else
            {
                mProtocol    = "udp";
                mViaProtocol = "UDP";
                mService     = "SIP+D2U";
            }
        }
        public TSIP_Stack(TSIP_Uri domainName, String privateIdentity, TSIP_Uri publicIdentity, String proxyHost, ushort proxyPort)
        {
            mSipSessions = new Dictionary <Int64, TSip_Session>();
            mHeaders     = new List <TSK_Param>();

            if (domainName == null || String.IsNullOrEmpty(privateIdentity) || publicIdentity == null)
            {
                TSK_Debug.Error("Invalid parameter");
                goto bail;
            }

            mRealm             = domainName;
            mPrivateIdentity   = privateIdentity;
            mPublicIdentity    = publicIdentity;
            mPreferredIdentity = mPublicIdentity;
            mProxyHost         = String.IsNullOrEmpty(proxyHost) ? domainName.Host : proxyHost;
            mProxyPort         = proxyPort == 0 ? (ushort)5060 : proxyPort;

            /* === Default values === */
            mLocalIP   = TNET_Socket.TNET_SOCKET_HOST_ANY;
            mLocalPort = TNET_Socket.TNET_SOCKET_PORT_ANY;
            mProxyType = TNET_Socket.tnet_socket_type_t.tnet_socket_type_udp_ipv4;

            mLayerDialog    = new TSIP_DialogLayer(this);
            mLayerTransac   = new TSIP_TransacLayer(this);
            mLayerTransport = new TSIP_TransportLayer(this);


            mValid = true;



            bail :;
        }
        internal Boolean AddTransport(String localHost, ushort localPort, TNET_Socket.tnet_socket_type_t type, String description)
        {
            TSIP_Transport transport = TNET_Socket.IsStreamType(type) ? (TSIP_Transport) new TSIP_TransportTCP(mStack, localHost, localPort, TNET_Socket.IsIPv6Type(type), description)
                : (TSIP_Transport) new TSIP_TransportUDP(mStack, localHost, localPort, TNET_Socket.IsIPv6Type(type), description);

            if (transport != null)
            {
                // FIXME:DO not forget to call "transport.NetworkEvent -= this.TSIP_Transport_NetworkEvent;" before removing the transport
                transport.NetworkEvent += this.TSIP_Transport_NetworkEvent;
                mTransports.Add(transport);
            }

            return(transport != null);
        }
Beispiel #5
0
        public TNET_Transport(String host, ushort port, TNET_Socket.tnet_socket_type_t type, String description)
        {
            mHost        = host;
            mPort        = port;
            mType        = type;
            mDescription = description;

            mSockets = new Dictionary <Int64, TNET_Socket>();

            mMasterSocket = new TNET_Socket(host, port, type);
            if (mMasterSocket != null)
            {
                mMasterSocket.RecvSocketCompleted += this.SocketAsyncEventArgs_Callback;
                mSockets.Add(mMasterSocket.Id, mMasterSocket);
            }
        }
        public TNET_Transport(String host, ushort port, TNET_Socket.tnet_socket_type_t type, String description)
        {
            mHost = host;
            mPort = port;
            mType = type;
            mDescription = description;

            mSockets = new Dictionary<Int64, TNET_Socket>();

            mMasterSocket = new TNET_Socket(host, port, type);
            if (mMasterSocket != null)
            {
                mMasterSocket.RecvSocketCompleted += this.SocketAsyncEventArgs_Callback;
                mSockets.Add(mMasterSocket.Id, mMasterSocket);
            }
        }
        public static IPAddress GetBestLocalIPAddress(String host, TNET_Socket.tnet_socket_type_t type)
        {
            try
            {
#if WINDOWS_PHONE
                String      localHostNameOrAddress = (host == TNET_Socket.TNET_SOCKET_HOST_ANY) ? "localhost" : host;                      // Not use yet
                IPAddress[] ipAddresses            = new IPAddress[] { TNET_Socket.IsIPv6Type(type) ? IPAddress.IPv6Any : IPAddress.Any }; // FIXME: didn't found how to get local IP on WP7
#else
                String      localHostNameOrAddress = (host == TNET_Socket.TNET_SOCKET_HOST_ANY) ? Dns.GetHostName() : host;
                IPAddress[] ipAddresses            = Dns.GetHostAddresses(localHostNameOrAddress);
#endif
                IPAddress ipAddress = null;
                Boolean   useIPv6   = TNET_Socket.IsIPv6Type(type);
                if (ipAddresses != null && ipAddresses.Length > 0)
                {
                    ipAddress = ipAddresses[0];
                    foreach (IPAddress ia in ipAddresses)
                    {
                        if ((ia.AddressFamily == AddressFamily.InterNetwork && (IPAddress.Loopback.ToString().Equals(ia.ToString()))) ||
                            (ia.AddressFamily == AddressFamily.InterNetworkV6 && (IPAddress.IPv6Loopback.ToString().Equals(ia.ToString()))))
                        {
                            continue;
                        }
                        if ((ia.AddressFamily == AddressFamily.InterNetwork && !useIPv6) || (ia.AddressFamily == AddressFamily.InterNetworkV6 && !ia.IsIPv6LinkLocal && useIPv6))
                        {
                            ipAddress = ia;
                            break;
                        }
                    }
                }

                if (ipAddress == null)
                {
                    TSK_Debug.Error("{0} is an invalid hostname or address", localHostNameOrAddress);
                    ipAddress = TNET_Socket.IsIPv6Type(type) ? IPAddress.IPv6Any : IPAddress.Any;
                }

                return(ipAddress);
            }
            catch (Exception e)
            {
                TSK_Debug.Error("GetBestLocalIPAddress(host={0}) failed: ", host, e);
            }
            return(TNET_Socket.IsIPv6Type(type) ? IPAddress.IPv6Any : IPAddress.Any);
        }
Beispiel #8
0
 protected TSIP_Transport(TSIP_Stack stack, TNET_Socket.tnet_socket_type_t type, String description)
     : this(stack, TNET_Socket.TNET_SOCKET_HOST_ANY, TNET_Socket.TNET_SOCKET_PORT_ANY, type, description)
 {
 }
        public TSIP_Stack(TSIP_Uri domainName, String privateIdentity, TSIP_Uri publicIdentity, String proxyHost, ushort proxyPort)
        {
            mSipSessions = new Dictionary<Int64, TSip_Session>();
            mHeaders = new List<TSK_Param>();

            if (domainName == null || String.IsNullOrEmpty(privateIdentity) || publicIdentity == null)
            {
                TSK_Debug.Error("Invalid parameter");
                goto bail;
            }

            mRealm = domainName;
            mPrivateIdentity = privateIdentity;
            mPublicIdentity = publicIdentity;
            mPreferredIdentity = mPublicIdentity;
            mProxyHost = String.IsNullOrEmpty(proxyHost) ? domainName.Host : proxyHost;
            mProxyPort = proxyPort == 0 ? (ushort)5060 : proxyPort;

            /* === Default values === */
            mLocalIP = TNET_Socket.TNET_SOCKET_HOST_ANY;
            mLocalPort = TNET_Socket.TNET_SOCKET_PORT_ANY;
            mProxyType = TNET_Socket.tnet_socket_type_t.tnet_socket_type_udp_ipv4;

            mLayerDialog = new TSIP_DialogLayer(this);
            mLayerTransac = new TSIP_TransacLayer(this);
            mLayerTransport = new TSIP_TransportLayer(this);

            mValid = true;

            bail: ;
        }