示例#1
0
        public void SendToRaw(IPAddress rawAddress, byte id, byte[] buf, int offset, int size)
        {
            var headerList = new ArrayList();


            var icmpHeader = new IcmpHeader();

            icmpHeader.Id       = 123;
            icmpHeader.Sequence = 24;
            icmpHeader.Type     = IcmpHeader.EchoReplyType;
            icmpHeader.Code     = IcmpHeader.EchoReplyCode;

            headerList.Add(icmpHeader);


            var myheader = new MyProtocol();

            myheader.Id = (byte)(byte.MaxValue - id);
            headerList.Add(myheader);

            byte[] sub = new byte[size];
            Array.Copy(buf, offset, sub, 0, size);

            var rawpacket = ProtocolHeader.BuildPacket(headerList, sub);

            RawSocket.BeginSendTo(rawpacket, 0, rawpacket.Length, SocketFlags.None,
                                  new IPEndPoint(rawAddress, 0),
                                  new AsyncCallback(TransportLayer.Instance().OnRawWriteComplete), rawpacket.Length);
        }
示例#2
0
 public TunnelServer(byte clientId, IPEndPoint targetEndPoint)
 {
     if (clientId > 127)
     {
         throw new ArgumentOutOfRangeException("clientId", "should less than 128");
     }
     _id          = (byte)(byte.MaxValue - clientId);
     Log.Name     = "Server";
     _targetPoint = targetEndPoint;
     TransportLayer.Instance().Listeners.Add(this);
 }
示例#3
0
        public TunnelClient(byte id, IPAddress remoteAddress, IPEndPoint listenEndPoint)
        {
            Log.Name             = "Client";
            _id                  = id;
            _connection          = new Connection(remoteAddress, Utils.DetectHost(), null, listenEndPoint);
            _connection.Id       = _id;
            _listenEndPoint      = listenEndPoint;
            _connection.Log.Name = "ClientListen";
            _connection.Start();

            TransportLayer.Instance().Listeners.Add(this);
        }
示例#4
0
        private void OnUdpReadComplete(IAsyncResult ar)
        {
            var state    = (object[])ar.AsyncState;
            var buf      = (byte[])(state[0]);
            var endPoint = (EndPoint)(state[1]);
            int readed   = UdpSocket.EndReceiveFrom(ar, ref endPoint);

            _clients.TryAdd(endPoint as IPEndPoint, 1);

            Log.T("received form udp {0} bytes", readed);

            TransportLayer.Instance().SendToRaw(_rawAddress, Id, buf, 0, readed);
        }