コード例 #1
0
        public static bool IsPossibleBroadcastAddress(NetAddress addr)
        {
            int sequentialOnes = 0;

            foreach (var oct in addr.Address.GetAddressBytes().Reverse())
            {
                for (int bit = 0; bit < 8; bit++)
                {
                    if (((oct >> bit) & 0x01) == 0x01)
                    {
                        sequentialOnes++;
                    }
                    else
                    {
                        return(sequentialOnes > 1);
                    }
                }
            }
            return(true);
        }
コード例 #2
0
        public Task <bool> Connect(NetAddress remote, Func <ISocketAsyncEventArgs, bool> receiveCallback)
        {
            PLog.LogTrace($"Connecting to {remote}");
            TaskCompletionSource <bool> src = new TaskCompletionSource <bool>();

            if (
                (m_isConnected) ||
                (m_isConnecting)
                )
            {
                src.SetResult(false);
                return(src.Task);
            }
            m_isConnecting = true;
            m_remote       = remote;
            try
            {
                m_receiveCallback = receiveCallback;
                ISocketAsyncEventArgs args = m_factory.GetEmptyArgs();
                args.UserToken      = src;
                args.RemoteEndPoint = m_remote;
                args.Completed     += OnConnectCompleted;
                if (!m_socket.ConnectAsync(args))
                {
                    OnConnectCompleted(this, args as SocketAsyncEventArgs);
                }
            }
            catch (Exception ex)
            {
                PLog.LogError($"Failed to connect to {m_remote}");
                m_isConnecting    = false;
                m_receiveCallback = null;
                src.SetException(ex);
            }

            return(src.Task);
        }
コード例 #3
0
        public static bool IsMulticastAddress(NetAddress addr)
        {
            var top = addr.Address.GetAddressBytes().First();

            return(top >= 224 && top <= 239);
        }