コード例 #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 IPv4Packet(IPv4Header header, byte[] payload)
        {
            Header  = header;
            Payload = payload;

            Header.Length = Header.HeaderLength * 2 + Payload.Length / 2;
        }
コード例 #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.");
            }