public void CollectStatWhenGiven2ip2icmp1tcp5udpPacketsThenCountOfPacketsIsRight() {
     NetworkPacket[] packets = new NetworkPacket[10];
     packets[0] = new IPPacket();
     packets[1] = new IPPacket();
     packets[2] = new ICMPPacket();
     packets[3] = new ICMPPacket();
     packets[4] = new TCPPacket();
     packets[5] = new UDPPacket();
     packets[6] = new UDPPacket();
     packets[7] = new UDPPacket();
     packets[8] = new UDPPacket();
     packets[9] = new UDPPacket();
     Firewall fw = new Firewall(new FilterMock(),
         new DistributorMock());
     CollectStatCommand clltStat = new CollectStatCommand();
     Assert.AreEqual(fw.Statistics["ip"], 0);
     Assert.AreEqual(fw.Statistics["icmp"], 0);
     Assert.AreEqual(fw.Statistics["tcp"], 0);
     Assert.AreEqual(fw.Statistics["udp"], 0);
     Assert.AreEqual(fw.Statistics["total"], 0);
     foreach (var packet in packets) {
         clltStat.DoWithPacket(fw, packet);
     }
     Assert.AreEqual(fw.Statistics["ip"], 2);
     Assert.AreEqual(fw.Statistics["icmp"], 2);
     Assert.AreEqual(fw.Statistics["tcp"], 1);
     Assert.AreEqual(fw.Statistics["udp"], 5);
     Assert.AreEqual(fw.Statistics["total"], 10);
 }
Esempio n. 2
0
        public IPPacket(ref byte[] Packet)
            : base()
        {
            try {
                Version = (byte)(Packet[0] >> 4);
                HeaderLength = (byte)((Packet[0] & 0x0F) * 4);
                TypeOfService = Packet[1];
                TotalLength = (ushort)System.Net.IPAddress.NetworkToHostOrder(System.BitConverter.ToInt16(Packet, 2));
                Identification = (ushort)System.Net.IPAddress.NetworkToHostOrder(System.BitConverter.ToInt16(Packet, 4));
                Flags = (byte)((Packet[6] & 0xE0) >> 5);
                FragmentOffset = (ushort)(System.Net.IPAddress.NetworkToHostOrder(System.BitConverter.ToInt16(Packet, 6)) & 0x1FFF);
                TimeToLive = Packet[8];
                Protocol = Packet[9];
                HeaderChecksum = (ushort)(System.Net.IPAddress.NetworkToHostOrder(System.BitConverter.ToInt16(Packet, 10)));
                SourceAddress = new System.Net.IPAddress(System.BitConverter.ToInt32(Packet, 12) & 0x00000000FFFFFFFF);
                DestinationAddress = new System.Net.IPAddress(System.BitConverter.ToInt32(Packet, 16) & 0x00000000FFFFFFFF);
                PacketData = new byte[TotalLength - HeaderLength];
                System.Buffer.BlockCopy(Packet, HeaderLength, PacketData, 0, PacketData.Length);
            } catch { }

            switch (Protocol) {
                case 1: ICMP = new ICMPPacket(ref PacketData); break;
                case 6: TCP = new TCPPacket(ref PacketData); break;
                case 17: UDP = new UDPPacket(ref PacketData); break;
            }
        }
        public void TestUDPConverterFromBytesToObject() {
            byte[] binPacket = new byte[TCPPacket.Size];
            //Source MAC
            binPacket[0] = 0x11;
            binPacket[1] = 0x22;
            binPacket[2] = 0x33;
            binPacket[3] = 0x44;
            binPacket[4] = 0x55;
            binPacket[5] = 0x66;
            //Destination MAC
            binPacket[6] = 0x66;
            binPacket[7] = 0x55;
            binPacket[8] = 0x44;
            binPacket[9] = 0x33;
            binPacket[10] = 0x22;
            binPacket[11] = 0x11;
            //Source IP
            binPacket[12] = 127;
            binPacket[13] = 0;
            binPacket[14] = 0;
            binPacket[15] = 1;
            //Destination IP
            binPacket[16] = 1;
            binPacket[17] = 1;
            binPacket[18] = 1;
            binPacket[19] = 1;
            //Source port
            binPacket[20] = 0x11;
            binPacket[21] = 0x11;
            //Destination port
            binPacket[22] = 0x22;
            binPacket[23] = 0x22;
            //Data
            binPacket[24] = 1;
            binPacket[25] = 2;

            UDPPacket packet = new UDPPacket();
            packet.SrcMAC =
               new PhysicalAddress(new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 });
            packet.DstMAC =
                new PhysicalAddress(new byte[] { 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 });
            packet.SrcIP = new NetworkAddress("127.0.0.1");
            packet.DstIP = new NetworkAddress("1.1.1.1");
            packet.SrcPort = 0x1111;
            packet.DstPort = 0x2222;
            packet.Data[0] = 1;
            packet.Data[1] = 2;

            UDPPacketConverter converter = new UDPPacketConverter();
            UDPPacket convertedPacket = (UDPPacket) converter.ConvertPacket(binPacket);
            Assert.AreEqual(packet, convertedPacket);
        }
 public void TestCopyUDPPackets() {
     UDPPacket packetSrc = new UDPPacket();
     UDPPacket packetDst = new UDPPacket();
     packetSrc.SrcMAC =
         new PhysicalAddress(new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 });
     packetSrc.DstMAC =
         new PhysicalAddress(new byte[] { 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 });
     packetSrc.SrcIP = new NetworkAddress("127.0.0.1");
     packetSrc.DstIP = new NetworkAddress("1.1.1.1");
     packetSrc.DstPort = 1234;
     packetSrc.SrcPort = 123;
     packetSrc.Data[0] = 1;
     packetSrc.Data[1] = 2;
     packetSrc.Copy(packetDst);
     Assert.AreEqual(packetSrc, packetDst);
     Assert.AreNotSame(packetSrc, packetDst);
 }
 void Given5UdpPacketsAnd2IcmpPackets() {
     udpPackets = new UDPPacket[5];
     UDPPacket udpPacket = new UDPPacket();
     udpPacket.SrcIP = new NetworkAddress("1.2.3.4");
     udpPacket.DstIP = new NetworkAddress("4.3.2.1");
     udpPackets[0] = udpPacket;
     udpPackets[1] = udpPacket;
     udpPackets[2] = udpPacket;
     udpPackets[3] = udpPacket;
     udpPackets[4] = udpPacket;
     icmpPackets = new ICMPPacket[2];
     icmpPackets[0] = new ICMPPacket();
     icmpPackets[1] = new ICMPPacket();
     icmpPackets[0].SrcIP = new NetworkAddress("1.2.3.4");
     icmpPackets[0].DstIP = new NetworkAddress("4.3.2.1");
     icmpPackets[1].SrcIP = new NetworkAddress("1.2.3.4");
     icmpPackets[1].DstIP = new NetworkAddress("4.3.2.1");
 }
Esempio n. 6
0
        /// <summary>Look up a hostname given a DNS request in the form of IPPacket
        /// </summary>
        /// <param name="req_ipp">An IPPacket containing the DNS request</param>
        /// <returns>An IPPacket containing the results</returns>
        public virtual IPPacket LookUp(IPPacket req_ipp)
        {
            UDPPacket req_udpp = new UDPPacket(req_ipp.Payload);
              DNSPacket dnspacket = new DNSPacket(req_udpp.Payload);
              ICopyable rdnspacket = null;
              try {
            string qname_response = String.Empty;
            string qname = dnspacket.Questions[0].QNAME;
            if(dnspacket.Questions[0].QTYPE == DNSPacket.TYPES.A) {
              qname_response = AddressLookUp(qname);
            }
            else if(dnspacket.Questions[0].QTYPE == DNSPacket.TYPES.PTR) {
              if(!InRange(qname)) {
            throw new Exception("Address out of range.");
              }
              qname_response = NameLookUp(qname);
            }
            if(qname_response == null) {
              throw new Exception("Unable to resolve name: " + qname);
            }
            Response response = new Response(qname, dnspacket.Questions[0].QTYPE,
              dnspacket.Questions[0].QCLASS, 1800, qname_response);

            // For some reason, if RD is set and we don't have RA it Linux `host`
            // doesn't work!
            DNSPacket res_packet = new DNSPacket(dnspacket.ID, false,
              dnspacket.OPCODE, true, dnspacket.RD, dnspacket.RD,
              dnspacket.Questions, new Response[] {response}, null, null);

            rdnspacket = res_packet.ICPacket;
              }
              catch(Exception e) {
            ProtocolLog.WriteIf(IpopLog.DNS, e.Message);
            rdnspacket = DNSPacket.BuildFailedReplyPacket(dnspacket);
              }
              UDPPacket res_udpp = new UDPPacket(req_udpp.DestinationPort,
                                         req_udpp.SourcePort, rdnspacket);
              IPPacket res_ipp = new IPPacket(IPPacket.Protocols.UDP,
                                       req_ipp.DestinationIP,
                                       req_ipp.SourceIP,
                                       res_udpp.ICPacket);
              return res_ipp;
        }
Esempio n. 7
0
        public static Message Decode(UDPPacket p)
        {
            var m = new DirPeopleReply
            {
                AgentID = p.ReadUUID(),
                QueryID = p.ReadUUID()
            };
            uint n = p.ReadUInt8();

            while (n-- != 0)
            {
                m.QueryReplies.Add(new QueryReplyData
                {
                    AgentID    = p.ReadUUID(),
                    FirstName  = p.ReadStringLen8(),
                    LastName   = p.ReadStringLen8(),
                    Group      = p.ReadStringLen8(),
                    Online     = p.ReadBoolean(),
                    Reputation = p.ReadInt32()
                });
            }
            return(m);
        }
Esempio n. 8
0
        public static Message Decode(UDPPacket p)
        {
            var m = new CopyInventoryItem
            {
                AgentID   = p.ReadUUID(),
                SessionID = p.ReadUUID()
            };
            uint c = p.ReadUInt8();

            for (uint i = 0; i < c; ++i)
            {
                m.InventoryData.Add(new InventoryDataEntry
                {
                    CallbackID  = p.ReadUInt32(),
                    OldAgentID  = p.ReadUUID(),
                    OldItemID   = p.ReadUUID(),
                    NewFolderID = p.ReadUUID(),
                    NewName     = p.ReadStringLen8()
                });
            }

            return(m);
        }
Esempio n. 9
0
        public static RequestImage Decode(UDPPacket p)
        {
            var m = new RequestImage
            {
                AgentID   = p.ReadUUID(),
                SessionID = p.ReadUUID()
            };
            uint count = p.ReadUInt8();

            for (uint idx = 0; idx < count; ++idx)
            {
                m.RequestImageList.Add(new RequestImageEntry
                {
                    ImageID          = p.ReadUUID(),
                    DiscardLevel     = p.ReadInt8(),
                    DownloadPriority = p.ReadFloat(),
                    Packet           = p.ReadUInt32(),
                    Type             = (ImageType)p.ReadUInt8()
                });
            }

            return(m);
        }
Esempio n. 10
0
        public static Message Decode(UDPPacket p)
        {
            var m = new ParcelReturnObjects
            {
                AgentID    = p.ReadUUID(),
                SessionID  = p.ReadUUID(),
                LocalID    = p.ReadInt32(),
                ReturnType = (ObjectReturnType)p.ReadUInt32()
            };
            uint cnt = p.ReadUInt8();

            for (uint i = 0; i < cnt; ++i)
            {
                m.TaskIDs.Add(p.ReadUUID());
            }

            cnt = p.ReadUInt8();
            for (uint i = 0; i < cnt; ++i)
            {
                m.OwnerIDs.Add(p.ReadUUID());
            }
            return(m);
        }
Esempio n. 11
0
        public static Message Decode(UDPPacket p)
        {
            var m = new GroupNoticesListReply
            {
                AgentID = p.ReadUUID(),
                GroupID = p.ReadUUID()
            };
            uint n = p.ReadUInt8();

            for (uint i = 0; i < n; ++i)
            {
                m.Data.Add(new GroupNoticeData
                {
                    NoticeID      = p.ReadUUID(),
                    Timestamp     = Date.UnixTimeToDateTime(p.ReadUInt32()),
                    FromName      = p.ReadStringLen16(),
                    Subject       = p.ReadStringLen16(),
                    HasAttachment = p.ReadBoolean(),
                    AssetType     = (AssetType)p.ReadUInt32()
                });
            }
            return(m);
        }
Esempio n. 12
0
        /* Runs when triggered by an F117Reader object */
        private void OnPacketReceived(object sender, F117ReceivedEventArgs args)
        {
            UDPPacket packet = args.packet;

            dataMtx.WaitOne();
            maxRpm = (int)packet.m_max_rpm;
            dataMtx.ReleaseMutex();

            PositionEventArgs newPos = new PositionEventArgs();

            newPos.x = packet.m_x;
            newPos.y = packet.m_y;
            newPos.z = packet.m_z;

            GForceEventArgs newGs = new GForceEventArgs();

            newGs.lat = packet.m_gforce_lat;
            newGs.lon = packet.m_gforce_lon;

            PowertrainEventArgs newPow = new PowertrainEventArgs();

            newPow.rpm = (int)packet.m_engineRate;
            newPow.kmh = packet.m_speed * 3.6f;
            newPow.mph = packet.m_speed * 2.23694f;

            AxesEventArgs newAxes = new AxesEventArgs();

            newAxes.throttle = packet.m_throttle;
            newAxes.brake    = packet.m_brake;
            newAxes.clutch   = packet.m_clutch;
            newAxes.steering = packet.m_steer * -1.0f;

            RaisePositionReceived(newPos);
            RaiseGForceReceived(newGs);
            RaisePowertrainReceived(newPow);
            RaiseAxesReceived(newAxes);
        }
Esempio n. 13
0
        public static Message Decode(UDPPacket p)
        {
            var m = new AvatarAnimation
            {
                Sender = p.ReadUUID()
            };
            uint n = p.ReadUInt8();

            for (uint i = 0; i < n; ++i)
            {
                m.AnimationList.Add(new AnimationData
                {
                    AnimID         = p.ReadUUID(),
                    AnimSequenceID = p.ReadUInt32()
                });
            }
            n = p.ReadUInt8();
            for (uint i = 0; i < n; ++i)
            {
                UUID objectID = p.ReadUUID();
                if (m.AnimationList.Count > i)
                {
                    var d = m.AnimationList[(int)i];
                    d.ObjectID = objectID;
                    m.AnimationList[(int)i] = d;
                }
            }
            n = p.ReadUInt8();
            for (uint i = 0; i < n; ++i)
            {
                m.PhysicalAvatarEventList.Add(new PhysicalAvatarEventData
                {
                    TypeData = p.ReadBytes(p.ReadUInt8())
                });
            }
            return(m);
        }
Esempio n. 14
0
        public static Message Decode(UDPPacket p)
        {
            var m = new ObjectDuplicateOnRay
            {
                AgentID              = p.ReadUUID(),
                SessionID            = p.ReadUUID(),
                GroupID              = p.ReadUUID(),
                RayStart             = p.ReadVector3f(),
                RayEnd               = p.ReadVector3f(),
                BypassRayCast        = p.ReadBoolean(),
                RayEndIsIntersection = p.ReadBoolean(),
                CopyCenters          = p.ReadBoolean(),
                CopyRotates          = p.ReadBoolean(),
                RayTargetID          = p.ReadUUID(),
                DuplicateFlags       = (PrimitiveFlags)p.ReadUInt32()
            };
            uint c = p.ReadUInt8();

            for (uint i = 0; i < c; ++i)
            {
                m.ObjectLocalIDs.Add(p.ReadUInt32());
            }
            return(m);
        }
Esempio n. 15
0
        void udpFileServer_DataArrival(object sender, SockEventArgs e)
        {
            if (e.Data.Length < 21)
            {
                return;                    //如果收到非法数据包则退出
            }
            UDPPacket fileMsg = new UDPPacket(e.Data);

            if (fileMsg.type == (byte)TransmitType.getFilePackage || fileMsg.type == (byte)TransmitType.over || fileMsg.type == (byte)TransmitType.Penetrate)
            {
                //客户端请求与另一客户端打洞或请求转发文件数据包到另一客户端
                IPEndPoint RemoteEP = new IPEndPoint(fileMsg.RemoteIP, fileMsg.Port); //获得消息接收者远程主机信息
                udpFileServer.Send(RemoteEP, fileMsg.BaseData);                       //将远程主机信息发送给客户端
            }
            else if (fileMsg.type == (byte)TransmitType.getRemoteEP)                  //客户端请求获取自己的远程主机信息
            {
                fileMsg.RemoteIP = e.RemoteIPEndPoint.Address;                        //设置客户端的远程IP
                fileMsg.Port     = e.RemoteIPEndPoint.Port;                           //设置客户端的远程UDP 端口
                udpFileServer.Send(e.RemoteIPEndPoint, fileMsg.BaseData);             //将远程主机信息发送给客户端
            }

            //if (DataArrival != null)
            //    DataArrival(this, new SockEventArgs(e.Data, e.RemoteIPEndPoint));
        }
Esempio n. 16
0
        public static Message Decode(UDPPacket p)
        {
            var m = new GroupRoleUpdate
            {
                AgentID   = p.ReadUUID(),
                SessionID = p.ReadUUID(),
                GroupID   = p.ReadUUID()
            };
            uint cnt = p.ReadUInt8();

            for (uint i = 0; i < cnt; ++i)
            {
                m.RoleData.Add(new RoleDataEntry
                {
                    RoleID      = p.ReadUUID(),
                    Name        = p.ReadStringLen8(),
                    Description = p.ReadStringLen8(),
                    Title       = p.ReadStringLen8(),
                    Powers      = (GroupPowers)p.ReadUInt64(),
                    UpdateType  = (RoleUpdateType)p.ReadUInt8()
                });
            }
            return(m);
        }
Esempio n. 17
0
        // dns
        public void VerifyPacket3(Packet p)
        {
            Console.WriteLine(p.ToString());
            EthernetPacket e = (EthernetPacket)p;

            Assert.AreEqual("00:16:cf:c9:1e:29", e.SourceHwAddress);
            Assert.AreEqual("00:14:bf:f2:ef:0a", e.DestinationHwAddress);

            IPPacket ip = (IPPacket)p;

            Assert.AreEqual(System.Net.IPAddress.Parse("192.168.1.172"), ip.SourceAddress);
            Assert.AreEqual(System.Net.IPAddress.Parse("66.189.0.29"), ip.DestinationAddress);
            Assert.AreEqual(IPProtocol.IPProtocolType.UDP, ip.IPProtocol);
            Assert.AreEqual(0x7988, ip.ComputeIPChecksum());

            UDPPacket udp = (UDPPacket)(p);

            Assert.AreEqual(3619, udp.SourcePort);
            Assert.AreEqual(53, udp.DestinationPort);
            Assert.AreEqual(47, udp.UDPLength);
            Assert.AreEqual(0x7988, udp.ComputeIPChecksum());
            Assert.AreEqual(0xbe2d, udp.UDPChecksum);
            Assert.AreEqual(0xbe2d, udp.Checksum);
        }
Esempio n. 18
0
        public static Message Decode(UDPPacket p)
        {
            var msg = new ObjectProperties();
            int n   = p.ReadUInt8();

            while (n-- != 0)
            {
                using (var ms = new MemoryStream())
                {
                    byte[] b = p.ReadBytes(174);
                    ms.Write(b, 0, b.Length);
                    int k = 4;
                    while (k-- != 0)
                    {
                        byte c = p.ReadUInt8();
                        ms.WriteByte(c);
                        b = p.ReadBytes(c);
                        ms.Write(b, 0, b.Length);
                    }
                    msg.ObjectData.Add(ms.ToArray());
                }
            }
            return(msg);
        }
Esempio n. 19
0
 public PacketStatus GetStatus(Packet pkt)
 {
     if (pkt.ContainsLayer(Protocol.UDP))
     {
         UDPPacket udppkt = (UDPPacket)pkt;
         if (pkt.Outbound && (direction & Direction.OUT) == Direction.OUT)
         {
             if (port.Contains(udppkt.DestPort) ||
                 inPortRange(udppkt.DestPort))
             {
                 if (log)
                 {
                     message = " UDP packet from " + udppkt.SourceIP.ToString() +
                               ":" + udppkt.SourcePort.ToString() + " to " + udppkt.DestIP.ToString() +
                               ":" + udppkt.DestPort.ToString();
                 }
                 return(ps);
             }
         }
         else if (!pkt.Outbound && (direction & Direction.IN) == Direction.IN)
         {
             if (port.Contains(udppkt.DestPort) ||
                 inPortRange(udppkt.DestPort))
             {
                 if (log)
                 {
                     message = " UDP packet from " + udppkt.SourceIP.ToString() +
                               ":" + udppkt.SourcePort.ToString() + " to " + udppkt.DestIP.ToString() +
                               ":" + udppkt.DestPort.ToString();
                 }
                 return(ps);
             }
         }
     }
     return(PacketStatus.UNDETERMINED);
 }
Esempio n. 20
0
        public static Message Decode(UDPPacket p)
        {
            var m = new ObjectShape
            {
                AgentID   = p.ReadUUID(),
                SessionID = p.ReadUUID()
            };
            uint c = p.ReadUInt8();

            for (uint i = 0; i < c; ++i)
            {
                m.ObjectData.Add(new Data
                {
                    ObjectLocalID    = p.ReadUInt32(),
                    PathCurve        = p.ReadUInt8(),
                    ProfileCurve     = p.ReadUInt8(),
                    PathBegin        = p.ReadUInt16(),
                    PathEnd          = p.ReadUInt16(),
                    PathScaleX       = p.ReadUInt8(),
                    PathScaleY       = p.ReadUInt8(),
                    PathShearX       = p.ReadUInt8(),
                    PathShearY       = p.ReadUInt8(),
                    PathTwist        = p.ReadInt8(),
                    PathTwistBegin   = p.ReadInt8(),
                    PathRadiusOffset = p.ReadInt8(),
                    PathTaperX       = p.ReadInt8(),
                    PathTaperY       = p.ReadInt8(),
                    PathRevolutions  = p.ReadUInt8(),
                    PathSkew         = p.ReadInt8(),
                    ProfileBegin     = p.ReadUInt16(),
                    ProfileEnd       = p.ReadUInt16(),
                    ProfileHollow    = p.ReadUInt16()
                });
            }
            return(m);
        }
 public static Message Decode(UDPPacket p) => new GroupAccountSummaryReply
 {
     AgentID              = p.ReadUUID(),
     GroupID              = p.ReadUUID(),
     RequestID            = p.ReadUUID(),
     IntervalDays         = p.ReadInt32(),
     CurrentInterval      = p.ReadInt32(),
     StartDate            = p.ReadStringLen8(),
     Balance              = p.ReadInt32(),
     TotalCredits         = p.ReadInt32(),
     TotalDebits          = p.ReadInt32(),
     ObjectTaxCurrent     = p.ReadInt32(),
     LightTaxCurrent      = p.ReadInt32(),
     LandTaxCurrent       = p.ReadInt32(),
     GroupTaxCurrent      = p.ReadInt32(),
     ParcelDirFeeCurrent  = p.ReadInt32(),
     ObjectTaxEstimate    = p.ReadInt32(),
     LightTaxEstimate     = p.ReadInt32(),
     GroupTaxEstimate     = p.ReadInt32(),
     ParcelDirFeeEstimate = p.ReadInt32(),
     NonExemptMembers     = p.ReadInt32(),
     LastTaxDate          = p.ReadStringLen8(),
     TaxDate              = p.ReadStringLen8()
 };
Esempio n. 22
0
        public override void Serialize(UDPPacket p)
        {
            p.WriteUUID(AgentID);
            p.WriteUUID(SessionID);
            p.WriteUUID(GroupID);

            p.WriteUInt8((byte)PCode);
            p.WriteUInt8((byte)Material);
            p.WriteUInt32(AddFlags);
            p.WriteUInt8(PathCurve);
            p.WriteUInt8(ProfileCurve);
            p.WriteUInt16(PathBegin);
            p.WriteUInt16(PathEnd);
            p.WriteUInt8(PathScaleX);
            p.WriteUInt8(PathScaleY);
            p.WriteUInt8(PathShearX);
            p.WriteUInt8(PathShearY);
            p.WriteInt8(PathTwist);
            p.WriteInt8(PathTwistBegin);
            p.WriteInt8(PathRadiusOffset);
            p.WriteInt8(PathTaperX);
            p.WriteInt8(PathTaperY);
            p.WriteUInt8(PathRevolutions);
            p.WriteInt8(PathSkew);
            p.WriteUInt16(ProfileBegin);
            p.WriteUInt16(ProfileEnd);
            p.WriteUInt16(ProfileHollow);
            p.WriteUInt8(BypassRaycast ? (byte)1 : (byte)0);
            p.WriteVector3f(RayStart);
            p.WriteVector3f(RayEnd);
            p.WriteUUID(RayTargetID);
            p.WriteUInt8(RayEndIsIntersection ? (byte)1 : (byte)0);
            p.WriteVector3f(Scale);
            p.WriteLLQuaternion(Rotation);
            p.WriteUInt8(State);
        }
Esempio n. 23
0
        public static Message Decode(UDPPacket p)
        {
            var m = new MapItemReply
            {
                AgentID  = p.ReadUUID(),
                Flags    = (MapAgentFlags)p.ReadUInt32(),
                ItemType = (MapItemType)p.ReadUInt32()
            };
            uint n = p.ReadUInt8();

            while (n-- != 0)
            {
                m.Data.Add(new DataEntry
                {
                    X      = p.ReadUInt32(),
                    Y      = p.ReadUInt32(),
                    ID     = p.ReadUUID(),
                    Extra  = p.ReadInt32(),
                    Extra2 = p.ReadInt32(),
                    Name   = p.ReadStringLen8()
                });
            }
            return(m);
        }
Esempio n. 24
0
    public void DebugAccount(UDPPacket r)
    {
        if (r == null)
        {
            return;
        }
        if (r.Error != 0)
        {
            Debug.LogError("Debug account can not be fetched!");
            return;
        }

        Event x = JsonConvert.DeserializeObject <Event>(r.Response);

        e.User = x.User;
        e.User.Status(UserStatus.Logined);
        Debug.Log("Debug user: "******"Requesting debug match...");
        Event m = new Event
        {
            M = new Game
            {
                ID = debugMatchId
            }
        };
        string jm = JsonConvert.SerializeObject(m);

        UDP.Request(new UDPPacket
        {
            Service = UDPService.Priv,
            Action  = UDPAction.Match,
            Request = jm,
        });
    }
Esempio n. 25
0
        public static Message Decode(UDPPacket p)
        {
            var m = new ObjectDeGrab
            {
                AgentID       = p.ReadUUID(),
                SessionID     = p.ReadUUID(),
                ObjectLocalID = p.ReadUInt32()
            };
            uint c = p.ReadUInt8();

            for (uint i = 0; i < c; ++i)
            {
                m.ObjectData.Add(new Data
                {
                    UVCoord   = p.ReadVector3f(),
                    STCoord   = p.ReadVector3f(),
                    FaceIndex = p.ReadInt32(),
                    Position  = p.ReadVector3f(),
                    Normal    = p.ReadVector3f(),
                    Binormal  = p.ReadVector3f()
                });
            }
            return(m);
        }
Esempio n. 26
0
        public static Message Decode(UDPPacket p)
        {
            var m = new FetchInventoryReply
            {
                AgentID = p.ReadUUID()
            };
            uint n = p.ReadUInt8();

            while (n-- != 0)
            {
                m.ItemData.Add(new ItemDataEntry
                {
                    ItemID        = p.ReadUUID(),
                    FolderID      = p.ReadUUID(),
                    CreatorID     = p.ReadUUID(),
                    OwnerID       = p.ReadUUID(),
                    GroupID       = p.ReadUUID(),
                    BaseMask      = (InventoryPermissionsMask)p.ReadUInt32(),
                    OwnerMask     = (InventoryPermissionsMask)p.ReadUInt32(),
                    GroupMask     = (InventoryPermissionsMask)p.ReadUInt32(),
                    EveryoneMask  = (InventoryPermissionsMask)p.ReadUInt32(),
                    NextOwnerMask = (InventoryPermissionsMask)p.ReadUInt32(),
                    IsGroupOwned  = p.ReadBoolean(),
                    AssetID       = p.ReadUUID(),
                    Type          = (AssetType)p.ReadInt8(),
                    InvType       = (InventoryType)p.ReadInt8(),
                    Flags         = (InventoryFlags)p.ReadUInt32(),
                    SaleType      = (InventoryItem.SaleInfoData.SaleType)p.ReadUInt8(),
                    Name          = p.ReadStringLen8(),
                    Description   = p.ReadStringLen8(),
                    CreationDate  = p.ReadUInt32()
                });
                p.ReadUInt32(); /* checksum */
            }
            return(m);
        }
Esempio n. 27
0
    /// <summary>
    /// Sends a password reset code to user's e-mail (if exists)
    /// </summary>
    /// <param name="r"></param>
    public bool Reset(UDPPacket r = null)
    {
        if (r == null)
        {
            Debug.Log("Resetting password...");

            User user = new User
            {
                Email = uiResetEmail.text,
            };

            UDP.Request(new UDPPacket
            {
                Service = UDPService.Account,
                Action  = UDPAction.Reset,
                Request = JsonConvert.SerializeObject(user),
            });
            return(false);
        }
        else
        {
            if (r.Error != 0)
            {
                if (r.Error >= (int)ServiceError.AccountUnknown)
                {
                    UIMessageGlobal.Open(Language.v["resetfailed"],
                                         Language.v["resetfaileddesc"]);
                    Debug.LogWarning(r.ToString());
                }
                return(false);
            }

            Debug.Log("Password reset link is sent");
            return(true);
        }
    }
Esempio n. 28
0
        public static Message Decode(UDPPacket p)
        {
            var m = new ViewerEffect
            {
                AgentID   = p.ReadUUID(),
                SessionID = p.ReadUUID()
            };
            uint c = p.ReadUInt8();

            for (uint i = 0; i < c; ++i)
            {
                m.Effects.Add(new EffectData
                {
                    ID          = p.ReadUUID(),
                    AgentID     = p.ReadUUID(),
                    Type        = p.ReadUInt8(),
                    Duration    = p.ReadFloat(),
                    EffectColor = new ColorAlpha(p.ReadBytes(4)),
                    TypeData    = p.ReadBytes(p.ReadUInt8())
                });
            }

            return(m);
        }
Esempio n. 29
0
        public static Message Decode(UDPPacket p)
        {
            var m = new LandStatReply
            {
                ReportType       = (LandStatReportEnum)p.ReadUInt32(),
                RequestFlags     = (LandStatFilterFlags)p.ReadUInt32(),
                TotalObjectCount = p.ReadUInt32()
            };
            uint n = p.ReadUInt8();

            while (n-- != 0)
            {
                m.ReportData.Add(new ReportDataEntry
                {
                    TaskLocalID = p.ReadUInt32(),
                    TaskID      = p.ReadUUID(),
                    Location    = p.ReadVector3f(),
                    Score       = p.ReadFloat(),
                    TaskName    = p.ReadStringLen8(),
                    OwnerName   = p.ReadStringLen8()
                });
            }
            return(m);
        }
Esempio n. 30
0
        public static Message Decode(UDPPacket p) => new ObjectAdd
        {
            AgentID   = p.ReadUUID(),
            SessionID = p.ReadUUID(),
            GroupID   = p.ReadUUID(),

            PCode                = (PrimitiveCode)p.ReadUInt8(),
            Material             = (PrimitiveMaterial)p.ReadUInt8(),
            AddFlags             = p.ReadUInt32(),
            PathCurve            = p.ReadUInt8(),
            ProfileCurve         = p.ReadUInt8(),
            PathBegin            = p.ReadUInt16(),
            PathEnd              = p.ReadUInt16(),
            PathScaleX           = p.ReadUInt8(),
            PathScaleY           = p.ReadUInt8(),
            PathShearX           = p.ReadUInt8(),
            PathShearY           = p.ReadUInt8(),
            PathTwist            = p.ReadInt8(),
            PathTwistBegin       = p.ReadInt8(),
            PathRadiusOffset     = p.ReadInt8(),
            PathTaperX           = p.ReadInt8(),
            PathTaperY           = p.ReadInt8(),
            PathRevolutions      = p.ReadUInt8(),
            PathSkew             = p.ReadInt8(),
            ProfileBegin         = p.ReadUInt16(),
            ProfileEnd           = p.ReadUInt16(),
            ProfileHollow        = p.ReadUInt16(),
            BypassRaycast        = 0 != p.ReadUInt8(),
            RayStart             = p.ReadVector3f(),
            RayEnd               = p.ReadVector3f(),
            RayTargetID          = p.ReadUUID(),
            RayEndIsIntersection = 0 != p.ReadUInt8(),
            Scale                = p.ReadVector3f(),
            Rotation             = p.ReadLLQuaternion(),
            State                = p.ReadUInt8()
        };
Esempio n. 31
0
 public override void Serialize(UDPPacket p)
 {
     p.WriteUUID(AgentID);
     p.WriteUUID(SessionID);
     p.WriteBytes(ParcelID.GetBytes());
 }
Esempio n. 32
0
 public static Message Decode(UDPPacket p) => new ParcelInfoRequest
 {
     AgentID   = p.ReadUUID(),
     SessionID = p.ReadUUID(),
     ParcelID  = new ParcelID(p.ReadBytes(16), 0)
 };
Esempio n. 33
0
 public override void Serialize(UDPPacket p)
 {
     p.WriteUUID(AgentID);
     p.WriteUUID(SessionID);
     p.WriteUUID(GroupID);
 }
Esempio n. 34
0
 public static Message Decode(UDPPacket p) => new GroupProfileRequest
 {
     AgentID   = p.ReadUUID(),
     SessionID = p.ReadUUID(),
     GroupID   = p.ReadUUID()
 };
Esempio n. 35
0
        /// <summary>This method handles IPPackets that come from the TAP Device, i.e.,
        /// local system.</summary>
        /// <remarks>Currently this supports HandleMulticast (ip[0] >= 244 &&
        /// ip[0]<=239), HandleDNS (dport = 53 and ip[3] == 1), dhcp (sport 68 and
        /// dport 67.</remarks>
        /// <param name="packet">The packet from the TAP device</param>
        /// <param name="from"> This should always be the tap device</param>
        protected virtual void HandleIPOut(EthernetPacket packet, ISender ret)
        {
            IPPacket ipp = new IPPacket(packet.Payload);

              if(IpopLog.PacketLog.Enabled) {
            ProtocolLog.Write(IpopLog.PacketLog, String.Format(
                          "Outgoing {0} packet::IP src: {1}, IP dst: {2}",
                          ipp.Protocol, ipp.SSourceIP, ipp.SDestinationIP));
              }

              if(!IsLocalIP(ipp.SourceIP)) {
            HandleNewStaticIP(packet.SourceAddress, ipp.SourceIP);
            return;
              }

              UDPPacket udpp = null;
              switch(ipp.Protocol) {
            case IPPacket.Protocols.UDP:
              udpp = new UDPPacket(ipp.Payload);
              if(udpp.SourcePort == _dhcp_client_port && udpp.DestinationPort == _dhcp_server_port) {
            if(HandleDHCP(ipp)) {
              return;
            }
              } else if(udpp.DestinationPort == 53 && ipp.DestinationIP.Equals(_dhcp_server.ServerIP)) {
            if(HandleDNS(ipp)) {
              return;
            }
              }
              break;
              }

              if(ipp.DestinationIP[0] >= 224 && ipp.DestinationIP[0] <= 239) {
            // We don't want to send Brunet multicast packets over IPOP!
            if(udpp != null && udpp.DestinationPort == IPHandler.mc_port) {
              return;
            } else if(HandleMulticast(ipp)) {
              return;
            }
              }

              if(ipp.DestinationIP.Equals(IPPacket.BroadcastAddress)) {
            if(HandleBroadcast(ipp)) {
              return;
            }
              }

              if(HandleOther(ipp)) {
            return;
              }

              if(_dhcp_server == null || ipp.DestinationIP.Equals(_dhcp_server.ServerIP)) {
            return;
              }

              Address target = null;
              try {
            target = _address_resolver.Resolve(ipp.DestinationIP) as AHAddress;
              } catch(AddressResolutionException ex) {
            if(ex.Issue != AddressResolutionException.Issues.DoesNotExist) {
              throw;
            }
            // Otherwise nothing to do, mapping doesn't exist...
              }

              if(target != null) {
            if(IpopLog.PacketLog.Enabled) {
              ProtocolLog.Write(IpopLog.PacketLog, String.Format(
                            "Brunet destination ID: {0}", target));
            }
            SendIP(target, packet.Payload);
            Brunet.Cco.Increment(target);
              }
        }
        /**
        <summary>Implements the ITranslator portion for ManagedAddress..., takes an
        IP Packet, based upon who the originating Brunet Sender was, changes who
        the packet was sent from and then switches the destination address to the
        local nodes address</summary>
        <param name="packet">The IP Packet to translate.</param>
        <param name="from">The Brunet address the packet was sent from.</param>
        <returns>The translated IP Packet.</returns>
        */
        public MemBlock Translate(MemBlock packet, Address from)
        {
            MemBlock source_ip = (MemBlock) _addr_ip[from];
              if(source_ip == null) {
            throw new Exception("Invalid mapping " + from + ".");
              }

              // Attempt to translate a MDNS packet
              IPPacket ipp = new IPPacket(packet);
              MemBlock hdr = packet.Slice(0,12);
              bool fragment = ((packet[6] & 0x1F) | packet[7]) != 0;

              if(ipp.Protocol == IPPacket.Protocols.UDP && !fragment) {
            UDPPacket udpp = new UDPPacket(ipp.Payload);
            // MDNS runs on 5353
            if(udpp.DestinationPort == 5353) {
              DNSPacket dnsp = new DNSPacket(udpp.Payload);
              String ss_ip = DNSPacket.IPMemBlockToString(source_ip);
              bool change = mDnsTranslate(dnsp.Answers, ss_ip);
              change |= mDnsTranslate(dnsp.Authority, ss_ip);
              change |= mDnsTranslate(dnsp.Additional, ss_ip);
              // If we make a change let's make a new packet!
              if(change) {
            dnsp = new DNSPacket(dnsp.ID, dnsp.QUERY, dnsp.OPCODE, dnsp.AA,
                                 dnsp.RA, dnsp.RD, dnsp.Questions, dnsp.Answers,
                                 dnsp.Authority, dnsp.Additional);
            udpp = new UDPPacket(udpp.SourcePort, udpp.DestinationPort,
                                 dnsp.ICPacket);
            ipp = new IPPacket(ipp.Protocol, source_ip, ipp.DestinationIP,
                               hdr, udpp.ICPacket);
            return ipp.Packet;
              }
            }
            else if(udpp.DestinationPort >= 5060 && udpp.DestinationPort < 5100) {
              udpp = SIPTranslate(udpp, source_ip, ipp.SSourceIP,
                              ipp.SDestinationIP);
              ipp = new IPPacket(ipp.Protocol, source_ip, _local_ip, hdr,
                             udpp.ICPacket);
              return ipp.Packet;
            }
              }
              return IPPacket.Translate(packet, source_ip, _local_ip);
        }
Esempio n. 37
0
 public static Message Decode(UDPPacket p) => new EventLocationRequest
 {
     QueryID = p.ReadUUID(),
     EventID = p.ReadUInt32()
 };
Esempio n. 38
0
        /// <summary>This method handles IPPackets that come from the TAP Device, i.e.,
        /// local system.</summary>
        /// <remarks>Currently this supports HandleMulticast (ip[0] >= 244 &&
        /// ip[0]<=239), HandleDNS (dport = 53 and ip[3] == 1), dhcp (sport 68 and
        /// dport 67.</remarks>
        /// <param name="packet">The packet from the TAP device</param>
        /// <param name="from"> This should always be the tap device</param>
        protected virtual void HandleIPOut(EthernetPacket packet, ISender ret)
        {
            IPPacket ipp = new IPPacket(packet.Payload);
              if(IpopLog.PacketLog.Enabled) {
            ProtocolLog.Write(IpopLog.PacketLog, String.Format(
                          "Outgoing {0} packet::IP src: {1}, IP dst: {2}",
                          ipp.Protocol, ipp.SSourceIP, ipp.SDestinationIP));
              }

              if(!IsLocalIP(ipp.SourceIP)) {
            HandleNewStaticIP(packet.SourceAddress, ipp.SourceIP);
            return;
              }

              if(ipp.DestinationIP[0] >= 224 && ipp.DestinationIP[0] <= 239) {
            if(HandleMulticast(ipp)) {
              return;
            }
              }

              switch(ipp.Protocol) {
            case IPPacket.Protocols.UDP:
              UDPPacket udpp = new UDPPacket(ipp.Payload);
              if(udpp.SourcePort == _dhcp_client_port && udpp.DestinationPort == _dhcp_server_port) {
            if(HandleDHCP(ipp)) {
              return;
            }
              } else if(udpp.DestinationPort == 53 &&ipp.DestinationIP.Equals(_dhcp_server.ServerIP)) {
            if(HandleDNS(ipp)) {
              return;
            }
              }
              break;
              }

              if(HandleOther(ipp)) {
            return;
              }

              if(_dhcp_server == null || ipp.DestinationIP.Equals(_dhcp_server.ServerIP)) {
            return;
              }

              AHAddress target = (AHAddress) _address_resolver.Resolve(ipp.DestinationIP);
              if (target != null) {
            if(IpopLog.PacketLog.Enabled) {
              ProtocolLog.Write(IpopLog.PacketLog, String.Format(
                            "Brunet destination ID: {0}", target));
            }
            SendIP(target, packet.Payload);
              }
        }
Esempio n. 39
0
        /// <summary>This is used to process a dhcp packet on the node side, that
        /// includes placing data such as the local Brunet Address, Ipop Namespace,
        /// and other optional parameters in our request to the dhcp server.  When
        /// receiving the results, if it is successful, the results are written to
        /// the TAP device.</summary>
        /// <param name="ipp"> The IPPacket that contains the DHCP Request</param>
        /// <param name="dhcp_params"> an object containing any extra parameters for 
        /// the dhcp server</param>
        /// <returns> true on if dhcp is supported.</returns>
        protected virtual bool HandleDHCP(IPPacket ipp)
        {
            UDPPacket udpp = new UDPPacket(ipp.Payload);
              DHCPPacket dhcp_packet = new DHCPPacket(udpp.Payload);
              MemBlock ether_addr = dhcp_packet.chaddr;

              if(_dhcp_config == null) {
            return true;
              }

              DHCPServer dhcp_server = CheckOutDHCPServer(ether_addr);
              if(dhcp_server == null) {
            return true;
              }

              MemBlock last_ip = null;
              _ether_to_ip.TryGetValue(ether_addr, out last_ip);
              byte[] last_ipb = (last_ip == null) ? null : (byte[]) last_ip;

              WaitCallback wcb = delegate(object o) {
            ProtocolLog.WriteIf(IpopLog.DHCPLog, String.Format(
            "Attemping DHCP for: {0}", Utils.MemBlockToString(ether_addr, '.')));

            DHCPPacket rpacket = null;
            try {
              rpacket = dhcp_server.ProcessPacket(dhcp_packet,
              Brunet.Address.ToString(), last_ipb);
            } catch(Exception e) {
              ProtocolLog.WriteIf(IpopLog.DHCPLog, e.Message);
              CheckInDHCPServer(dhcp_server);
              return;
            }

            /* Check our allocation to see if we're getting a new address */
            MemBlock new_addr = rpacket.yiaddr;
            UpdateMapping(ether_addr, new_addr);

            MemBlock destination_ip = ipp.SourceIP;
            if(destination_ip.Equals(IPPacket.ZeroAddress)) {
              destination_ip = IPPacket.BroadcastAddress;
            }

            UDPPacket res_udpp = new UDPPacket(_dhcp_server_port, _dhcp_client_port, rpacket.Packet);
            IPPacket res_ipp = new IPPacket(IPPacket.Protocols.UDP, rpacket.siaddr,
            destination_ip, res_udpp.ICPacket);
            EthernetPacket res_ep = new EthernetPacket(ether_addr, EthernetPacket.UnicastAddress,
            EthernetPacket.Types.IP, res_ipp.ICPacket);
            Ethernet.Send(res_ep.ICPacket);
            CheckInDHCPServer(dhcp_server);
              };

              ThreadPool.QueueUserWorkItem(wcb);
              return true;
        }
Esempio n. 40
0
        public void SendRTPPacket(string sourceSocket, string destinationSocket)
        {
            try
            {
                //logger.Debug("Attempting to send RTP packet from " + sourceSocket + " to " + destinationSocket + ".");
                FireLogEvent("Attempting to send RTP packet from " + sourceSocket + " to " + destinationSocket + ".");
                
                IPEndPoint sourceEP = IPSocket.GetIPEndPoint(sourceSocket);
                IPEndPoint destEP = IPSocket.GetIPEndPoint(destinationSocket);

                RTPPacket rtpPacket = new RTPPacket(80);
                rtpPacket.Header.SequenceNumber = (UInt16)6500;
                rtpPacket.Header.Timestamp = 100000;

                UDPPacket udpPacket = new UDPPacket(sourceEP.Port, destEP.Port, rtpPacket.GetBytes());
                IPv4Header ipHeader = new IPv4Header(ProtocolType.Udp, Crypto.GetRandomInt(6), sourceEP.Address, destEP.Address);
                IPv4Packet ipPacket = new IPv4Packet(ipHeader, udpPacket.GetBytes());

                byte[] data = ipPacket.GetBytes();

                Socket rawSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
                rawSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);

                rawSocket.SendTo(data, destEP);
            }
            catch (Exception excp)
            {
                logger.Error("Exception SendRTPPacket. " + excp.Message);
            }
        }
Esempio n. 41
0
 public override void Serialize(UDPPacket p)
 {
     p.WriteUUID(QueryID);
     p.WriteUInt32(EventID);
 }
 /// <summary>
 /// Check to see if it's a SIP packet and translates
 /// </summary>
 /// <param name="payload">UDP payload</param>
 /// <param name="source_ip">New source IP</param>
 /// <param name="old_ss_ip">Old source IP</param>
 /// <param name="old_sd_ip">Old destination IP</param>
 /// <returns>Returns a UDP packet</returns>
 public UDPPacket SIPTranslate(UDPPacket udpp, MemBlock source_ip, 
                             string old_ss_ip, string old_sd_ip)
 {
     string new_ss_ip = Utils.MemBlockToString(source_ip, '.');
       string new_sd_ip = Utils.MemBlockToString(_local_ip, '.');
       string packet_id = "SIP/2.0";
       MemBlock payload = ManagedNodeHelper.TextTranslate(udpp.Payload, old_ss_ip,
                                      old_sd_ip, new_ss_ip, new_sd_ip,
                                      packet_id);
       return new UDPPacket(udpp.SourcePort, udpp.DestinationPort, payload);
 }