Parses and creates Stun packets as defined by RFC 5389.
Пример #1
0
        public void TestResponse()
        {
            byte[] response = new byte[] { 0x01, 0x01, 0x00, 0x18, 0x21, 0x12, 0xa4,
                                           0x42, 0x99, 0x7b, 0x63, 0x08, 0x17, 0x9d, 0x00, 0xbc, 0xe9, 0xb5, 0x9f,
                                           0x57, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0xe1, 0x6e, 0x46, 0xb9, 0x63,
                                           0xb6, 0x00, 0x04, 0x00, 0x08, 0x00, 0x01, 0x4b, 0x66, 0x4a, 0x7d, 0x5f,
                                           0x7e };
            MemBlock   resp    = MemBlock.Reference(response);
            StunPacket from_mb = new StunPacket(resp);

            List <StunPacket.Attribute> attrs = new List <StunPacket.Attribute>(2);

            attrs.Add(new StunPacket.AttributeAddress(
                          StunPacket.Attribute.AttributeType.MappedAddress,
                          IPAddress.Parse("70.185.99.182"),
                          57710));
            attrs.Add(new StunPacket.AttributeAddress(
                          StunPacket.Attribute.AttributeType.SourceAddress,
                          IPAddress.Parse("74.125.95.126"),
                          19302));
            StunPacket from_input = new StunPacket(StunPacket.ClassType.Response,
                                                   StunPacket.MessageType.Binding, attrs);

            from_input = new StunPacket(from_input.Data);

            Assert.AreEqual(from_mb.Attributes.Count, from_input.Attributes.Count, "Attributes");
            for (int i = 0; i < from_mb.Attributes.Count; i++)
            {
                Assert.AreEqual(from_mb.Attributes[i].Data, from_input.Attributes[i].Data, "Attribute " + i);
            }
            Assert.AreEqual(from_mb.Message, from_input.Message, "Message");
            Assert.AreEqual(from_mb.Class, from_input.Class, "Class");
            Assert.AreEqual(from_mb.Data.Length, from_input.Data.Length, "Length");
        }
Пример #2
0
        public void TestRequest()
        {
            byte[] request = new byte[] { 0x00, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4,
                                          0x42, 0x99, 0x7b, 0x63, 0x08, 0x17, 0x9d, 0x00, 0xbc, 0xe9, 0xb5, 0x9f,
                                          0x57 };
            MemBlock   req        = MemBlock.Reference(request);
            StunPacket from_mb    = new StunPacket(req);
            StunPacket from_input = new StunPacket(StunPacket.ClassType.Request,
                                                   StunPacket.MessageType.Binding, StunPacket.EMPTY_ATTRIBUTES);

            from_input = new StunPacket(from_input.Data);

            Assert.AreEqual(from_mb.Attributes, from_input.Attributes, "Attributes");
            Assert.AreEqual(from_mb.Message, from_input.Message, "Message");
            Assert.AreEqual(from_mb.Class, from_input.Class, "Class");
            Assert.AreEqual(from_mb.Data.Length, from_input.Data.Length, "Length");
        }
Пример #3
0
        public void TestResponse()
        {
            byte[] response = new byte[] {0x01, 0x01, 0x00, 0x18, 0x21, 0x12, 0xa4,
            0x42, 0x99, 0x7b, 0x63, 0x08, 0x17, 0x9d, 0x00, 0xbc, 0xe9, 0xb5, 0x9f,
            0x57, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0xe1, 0x6e, 0x46, 0xb9, 0x63,
            0xb6, 0x00, 0x04, 0x00, 0x08, 0x00, 0x01, 0x4b, 0x66, 0x4a, 0x7d, 0x5f,
            0x7e};
              MemBlock resp = MemBlock.Reference(response);
              StunPacket from_mb = new StunPacket(resp);

              List<StunPacket.Attribute> attrs = new List<StunPacket.Attribute>(2);
              attrs.Add(new StunPacket.AttributeAddress(
              StunPacket.Attribute.AttributeType.MappedAddress,
              IPAddress.Parse("70.185.99.182"),
              57710));
              attrs.Add(new StunPacket.AttributeAddress(
              StunPacket.Attribute.AttributeType.SourceAddress,
              IPAddress.Parse("74.125.95.126"),
              19302));
              StunPacket from_input = new StunPacket(StunPacket.ClassType.Response,
              StunPacket.MessageType.Binding, attrs);
              from_input = new StunPacket(from_input.Data);

              Assert.AreEqual(from_mb.Attributes.Count, from_input.Attributes.Count, "Attributes");
              for(int i = 0; i < from_mb.Attributes.Count; i++) {
            Assert.AreEqual(from_mb.Attributes[i].Data, from_input.Attributes[i].Data, "Attribute " + i);
              }
              Assert.AreEqual(from_mb.Message, from_input.Message, "Message");
              Assert.AreEqual(from_mb.Class, from_input.Class, "Class");
              Assert.AreEqual(from_mb.Data.Length, from_input.Data.Length, "Length");
        }
Пример #4
0
        public void TestRequest()
        {
            byte[] request = new byte[] {0x00, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4,
            0x42, 0x99, 0x7b, 0x63, 0x08, 0x17, 0x9d, 0x00, 0xbc, 0xe9, 0xb5, 0x9f,
            0x57};
              MemBlock req = MemBlock.Reference(request);
              StunPacket from_mb = new StunPacket(req);
              StunPacket from_input = new StunPacket(StunPacket.ClassType.Request,
              StunPacket.MessageType.Binding, StunPacket.EMPTY_ATTRIBUTES);
              from_input = new StunPacket(from_input.Data);

              Assert.AreEqual(from_mb.Attributes, from_input.Attributes, "Attributes");
              Assert.AreEqual(from_mb.Message, from_input.Message, "Message");
              Assert.AreEqual(from_mb.Class, from_input.Class, "Class");
              Assert.AreEqual(from_mb.Data.Length, from_input.Data.Length, "Length");
        }