예제 #1
0
        public void Bind(IPv6Address ipAddress, ushort ipPort)
        {
            if (_sourceIpAddressAndPortAssigned)
            {
                throw new SocketsException("Socket is connected.");
            }

            _sourceIpAddressAndPortAssigned = true;

            // if ipAddress is IP_ADDRESS_ANY, then change it to to our actual ipAddress.
            if (ipAddress.Equals(IPv6Any))
            {
                sourceIpAddress = NetworkingInterface.IPAddress;
            }
            else
            {
                sourceIpAddress = ipAddress;
            }

            if (ipPort == IPPortAny)
            {
                sourcePort = NetworkingInterface.GetEphemeralPort();
            }
            else
            {
                sourcePort = ipPort;
            }


            // verify that this source IP address is correct
            if (sourceIpAddress != NetworkingInterface.IPAddress)
            {
                throw new SocketsException("Source address is not correct.");
            }

            NetworkingInterface.CreateSocket(this);
            ReceiveTimeout = 5000;
        }
예제 #2
0
        public void PacketHandler(IPv6Packet ipv6Packet)
        {
            UdpDatagram udpDatagram = (UdpDatagram)ipv6Packet.Payload;

            destinationIpAddress = ipv6Packet.SourceAddress;
            destinationPort      = udpDatagram.SourcePort;

            /* if we do not have enough room for the incoming frame, discard it */
            if (receivedPacketBuffer.IsEmpty == false)
            {
                return;
            }

            lock (receivedPacketBuffer.LockObject)
            {
                int bytesReceived = udpDatagram.Payload.Length;

                Array.Copy(udpDatagram.Payload, receivedPacketBuffer.Buffer, bytesReceived);
                receivedPacketBuffer.IsEmpty       = false;
                receivedPacketBuffer.BytesReceived = bytesReceived;

                receivedPacketBufferFilledEvent.Set();
            }
        }
예제 #3
0
        //public IPEndPoint(long address, int port)
        //{
        //    m_Port = port;
        //    m_Address = new IPv6Address(address);
        //}

        public IPv6EndPoint(IPv6Address address, int port)
        {
            m_Port    = port;
            m_Address = address;
        }