示例#1
0
        public void IPEmptyPacketSendUnitTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            UDPPacket  udpPacket = new UDPPacket(4001, 4001, new byte[] { 0x1, 0x2, 0x3, 0x4 });
            IPv4Header header    = new IPv4Header(ProtocolType.Udp, 7890, IPAddress.Parse("194.213.29.54"), IPAddress.Parse("194.213.29.54"));

            byte[] headerData = header.GetBytes();

            foreach (byte headerByte in headerData)
            {
                Console.Write("0x{0:x} ", headerByte);
            }

            Console.WriteLine();

            Socket rawSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

            //rawSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
            rawSocket.SendTo(headerData, new IPEndPoint(IPAddress.Parse("194.213.29.54"), 5060));

            rawSocket.Shutdown(SocketShutdown.Both);
            rawSocket.Close();

            Assert.True(true, "True was false.");
        }
        public void IPHeaderConstructionUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            IPv4Header header = new IPv4Header(ProtocolType.Udp, 4567, IPAddress.Parse("127.0.0.1"), IPAddress.Parse("127.0.0.1"));

            byte[] headerData = header.GetBytes();

            int count = 0;

            foreach (byte headerByte in headerData)
            {
                logger.LogDebug("0x{0,-2:x} ", headerByte);
                count++;
                if (count % 4 == 0)
                {
                    logger.LogDebug("\n");
                }
            }

            logger.LogDebug("\n");

            Assert.True(true, "True was false.");
        }
示例#3
0
        public void IPHeaderConstructionUnitTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            IPv4Header header = new IPv4Header(ProtocolType.Udp, 4567, IPAddress.Parse("194.213.29.54"), IPAddress.Parse("194.213.29.54"));

            byte[] headerData = header.GetBytes();

            int count = 0;

            foreach (byte headerByte in headerData)
            {
                Console.Write("0x{0,-2:x} ", headerByte);
                count++;
                if (count % 4 == 0)
                {
                    Console.Write("\n");
                }
            }

            Console.WriteLine();

            Assert.True(true, "True was false.");
        }