コード例 #1
0
        /// <summary>
        ///		Send a SYN request to the next port to check it's state.
        /// </summary>
        private void SendRequest()
        {
            m_remoteEndPoint.Port = m_ports [m_portIndex];

            // increment the local port.
            if (m_incPorts)
            {
                if (m_localEndPoint.Port == ushort.MaxValue)
                {
                    m_localEndPoint.Port = 1024;
                }

                m_localEndPoint.Port++;
            }

            IpV4Packet ipHeader = new IpV4Packet();

            // fill in the minimal IP fields
            ipHeader.DestinationAddress = m_remoteEndPoint.Address;
            ipHeader.SourceAddress      = m_localEndPoint.Address;

            TcpPacket tcpHeader = new TcpPacket();

            // fill in the minimal tcp fields
            tcpHeader.DestinationPort = (ushort)m_remoteEndPoint.Port;
            tcpHeader.SourcePort      = (ushort)m_localEndPoint.Port;
            tcpHeader.SetFlag(TcpFlags.Synchronize, true);

            // send the request
            ipHeader.Data = tcpHeader.Serialize(m_localEndPoint.Address, m_remoteEndPoint.Address);

            // send each fragment
            if (m_fragment)
            {
                IpV4Packet[] fragments = ipHeader.Fragment(8);

                for (int i = 0; i < fragments.Length; i++)
                {
                    byte[] packet = fragments[i].Serialize();
                    m_socket.SendTo(packet, 0, packet.Length, SocketFlags.None, new IPEndPoint(fragments[i].DestinationAddress, 0));
                }
            }

            // send the packet
            else
            {
                byte[] packet = ipHeader.Serialize();
                m_socket.SendTo(packet, 0, packet.Length, SocketFlags.None, new IPEndPoint(ipHeader.DestinationAddress, 0));
            }

            // start the time out timer
            m_timeoutTimer.Enabled = true;
        }