コード例 #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.IsTrue(true, "True was false.");
            }
コード例 #2
0
        public byte[] GetBytes()
        {
            byte[] packet = new byte[Header.Length * 2];
            Buffer.BlockCopy(Header.GetBytes(), 0, packet, 0, Header.HeaderLength * 4);
            Buffer.BlockCopy(Payload, 0, packet, Header.HeaderLength * 4, Payload.Length);

            return(packet);
        }
コード例 #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.IsTrue(true, "True was false.");
            }