Beispiel #1
0
        public void EnsureEncodedCorrectly()
        {
            var xMacSender = new MACAddress(new byte[]
                                            {
                                                00,
                                                0x50,
                                                0x56,
                                                0xc0,
                                                0x00,
                                                0x01
                                            });
            var xIPSender = new Address(192, 168, 17, 1);
            var xMacTarget = MACAddress.Broadcast;
            var xIPTarget = new Address(192, 168, 17, 102);
            var xArpTargetMac = new MACAddress(new byte[6]);

            var xPacket = new ARPRequest_Ethernet(xMacSender, xIPSender, xMacTarget, xIPTarget, xArpTargetMac);

            var xExpectedPacket =
                "FF FF FF FF FF FF 00 50 " +
                "56 C0 00 01 08 06 00 01 " +
                "08 00 06 04 00 01 00 50 " +
                "56 C0 00 01 C0 A8 11 01 " +
                "00 00 00 00 00 00 C0 A8 " +
                "11 66";
            Approvals.Verify(Utilities.PrettyPrint(xPacket.RawData));
            //Approvals.VerifyBinaryFile(xPacket.RawData, "bin");
            //Assert.AreEqual(xExpectedPacket, Utilities.PrettyPrint(xPacket.RawData));
        }
Beispiel #2
0
        protected EthernetPacket(MACAddress dest, MACAddress src, UInt16 type, int packet_size)
        {
            mRawData = new byte[packet_size];
            for (int i = 0; i < 6; i++)
            {
                mRawData[i] = dest.bytes[i];
                mRawData[6 + i] = src.bytes[i];
            }

            mRawData[12] = (byte)(type >> 8);
            mRawData[13] = (byte)(type >> 0);
            initFields();
        }
Beispiel #3
0
 protected override void initFields()
 {
     Sys.Console.WriteLine("ARPPacket_Ethernet.initFields() called");
     base.initFields();
     mSenderMAC = new MACAddress(mRawData, 22);
     mSenderIP = new Address(mRawData, 28);
     global::System.Console.WriteLine("SenderIP created");
     if (SenderIP == null)
     {
         global::System.Console.WriteLine("But its already null again");
     }
     mTargetMAC = new MACAddress(mRawData, 32);
     mTargetIP = new Address(mRawData, 38);
 }
Beispiel #4
0
        protected ARPPacket_Ethernet(UInt16 operation, MACAddress senderMAC, Address senderIP,
            MACAddress targetMAC, Address targetIP, int packet_size, MACAddress arpTargetMAC)
            : base(targetMAC, senderMAC, 1, 0x0800, 6, 4, operation, packet_size)
        {
            for (int i = 0; i < 6; i++)
            {
                mRawData[22 + i] = senderMAC.bytes[i];
                mRawData[32 + i] = arpTargetMAC.bytes[i];
            }
            for (int i = 0; i < 4; i++)
            {
                mRawData[28 + i] = senderIP.address[i];
                mRawData[38 + i] = targetIP.address[i];
            }

            initFields();
        }
Beispiel #5
0
 static MACAddress()
 {
     var xBroadcastArray = new byte[6];
     xBroadcastArray[0] = 0xFF;
     xBroadcastArray[1] = 0xFF;
     xBroadcastArray[2] = 0xFF;
     xBroadcastArray[3] = 0xFF;
     xBroadcastArray[4] = 0xFF;
     xBroadcastArray[5] = 0xFF;
     Broadcast = new MACAddress(xBroadcastArray);
     var xNoneArray = new byte[6];
     xNoneArray[0] = 0x00;
     xNoneArray[1] = 0x00;
     xNoneArray[2] = 0x00;
     xNoneArray[3] = 0x00;
     xNoneArray[4] = 0x00;
     xNoneArray[5] = 0x00;
     None = new MACAddress(xNoneArray);
 }
Beispiel #6
0
        internal static void Update(IPv4.Address ipAddress, MACAddress macAddress)
        {
            ensureCacheExists();
            if (ipAddress == null)
            {
              global::System.Console.Write("");
            }
            UInt32 ip_hash = ipAddress.Hash;
            if (ip_hash == 0)
            {
                return;
            }

            if (cache.ContainsKey(ip_hash) == false)
            {
                cache.Add(ip_hash, macAddress);
            }
            else
            {
                cache[ip_hash] = macAddress;
            }
        }
Beispiel #7
0
        public AMDPCNetII(PCIDeviceNormal device)
            : base()
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get AMD PCNet card");
            }

            this.pciCard = device;
            this.pciCard.Claimed = true;
            this.pciCard.EnableDevice();

            this.io = new AMDPCNetIIIOGroup((ushort)this.pciCard.BaseAddresses[0].BaseAddress());
            this.io.RegisterData.DWord = 0;

            // Get the EEPROM MAC Address and set it as the devices MAC
            byte[] eeprom_mac = new byte[6];
            UInt32 result = io.MAC1.DWord;
            eeprom_mac[0] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[1] = BinaryHelper.GetByteFrom32bit(result, 8);
            eeprom_mac[2] = BinaryHelper.GetByteFrom32bit(result, 16);
            eeprom_mac[3] = BinaryHelper.GetByteFrom32bit(result, 24);
            result = io.MAC2.DWord;
            eeprom_mac[4] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[5] = BinaryHelper.GetByteFrom32bit(result, 8);

            mac = new MACAddress(eeprom_mac);

            mInitBlock = new ManagedMemoryBlock(28, 4);
            mRxDescriptor = new ManagedMemoryBlock(256, 16);
            mTxDescriptor = new ManagedMemoryBlock(256, 16);

            mInitBlock.Write32(0x00, (0x4 << 28) | (0x4 << 20));
            mInitBlock.Write32(0x04, (UInt32)(eeprom_mac[0] | (eeprom_mac[1] << 8) | (eeprom_mac[2] << 16) | (eeprom_mac[3] << 24)));
            mInitBlock.Write32(0x08, (UInt32)(eeprom_mac[4] | (eeprom_mac[5] << 8)));
            mInitBlock.Write32(0x0C, 0x0);
            mInitBlock.Write32(0x10, 0x0);
            mInitBlock.Write32(0x14, mRxDescriptor.Offset);
            mInitBlock.Write32(0x18, mTxDescriptor.Offset);

            InitializationBlockAddress = mInitBlock.Offset;
            SoftwareStyleRegister = 0x03;

            mRxBuffers = new List<ManagedMemoryBlock>();
            mTxBuffers = new List<ManagedMemoryBlock>();
            for (uint rxd = 0; rxd < 16; rxd++)
            {
                uint xOffset = rxd * 16;

                ManagedMemoryBlock buffer = new ManagedMemoryBlock(2048);
                mRxDescriptor.Write32(xOffset + 8, buffer.Offset);
                UInt16 buffer_len = (UInt16)(~buffer.Size);
                buffer_len++;
                UInt32 flags = (UInt32)(buffer_len & 0x0FFF) | 0xF000 | 0x80000000;
                mRxDescriptor.Write32(xOffset + 4, flags);
                mRxBuffers.Add(buffer);
            }
            for (uint txd = 0; txd < 16; txd++)
            {
                uint xOffset = txd * 16;

                ManagedMemoryBlock buffer = new ManagedMemoryBlock(2048);
                mTxDescriptor.Write32(xOffset + 8, buffer.Offset);
                mTxBuffers.Add(buffer);
            }

            mNextTXDesc = 0;

            // Setup our Receive and Transmit Queues
            mTransmitBuffer = new Queue<byte[]>();
            mRecvBuffer = new Queue<byte[]>();

            INTs.SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt);
        }
Beispiel #8
0
        private IPPacket(MACAddress srcMAC, MACAddress destMAC, UInt16 dataLength, byte protocol,
            Address source, Address dest)
            : base(destMAC, srcMAC, 0x0800, dataLength + 14 + 20)
        {
            mRawData[14] = 0x45;
            mRawData[15] = 0;
            ipLength = (UInt16)(dataLength + 20);
            ipHeaderLength = 5;
            mRawData[16] = (byte)((ipLength >> 8) & 0xFF);
            mRawData[17] = (byte)((ipLength >> 0) & 0xFF);
            fragmentID = NextIPFragmentID;
            mRawData[18] = (byte)((fragmentID >> 8) & 0xFF);
            mRawData[19] = (byte)((fragmentID >> 0) & 0xFF);
            mRawData[20] = 0x00;
            mRawData[21] = 0x00;
            mRawData[22] = 0x80;
            mRawData[23] = protocol;
            mRawData[24] = 0x00;
            mRawData[25] = 0x00;
            for (int b = 0; b < 4; b++)
            {
                mRawData[26 + b] = source.address[b];
                mRawData[30 + b] = dest.address[b];
            }
            ipCRC = CalcIPCRC(20);
            mRawData[24] = (byte)((ipCRC >> 8) & 0xFF);
            mRawData[25] = (byte)((ipCRC >> 0) & 0xFF);

            initFields();
        }
Beispiel #9
0
        protected ARPPacket(MACAddress dest, MACAddress src, UInt16 hwType, UInt16 protoType,
            byte hwLen, byte protoLen, UInt16 operation, int packet_size)
            : base(dest, src, 0x0806, packet_size)
        {
            mRawData[14] = (byte)(hwType >> 8);
            mRawData[15] = (byte)(hwType >> 0);
            mRawData[16] = (byte)(protoType >> 8);
            mRawData[17] = (byte)(protoType >> 0);
            mRawData[18] = hwLen;
            mRawData[19] = protoLen;
            mRawData[20] = (byte)(operation >> 8);
            mRawData[21] = (byte)(operation >> 0);

            initFields();
        }
Beispiel #10
0
 protected virtual void initFields()
 {
     destMAC = new MACAddress(mRawData, 0);
     srcMAC = new MACAddress(mRawData, 6);
     aEtherType = (UInt16)((mRawData[12] << 8) | mRawData[13]);
 }
Beispiel #11
0
 internal ARPReply_Ethernet(MACAddress ourMAC, Address ourIP, MACAddress targetMAC, Address targetIP)
     : base(2, ourMAC, ourIP, targetMAC, targetIP, 42, MACAddress.None)
 { }
Beispiel #12
0
 internal ARPRequest_Ethernet(MACAddress ourMAC, Address ourIP, MACAddress targetMAC, Address targetIP, MACAddress arpTargetMAC)
     : base(1, ourMAC, ourIP, targetMAC, targetIP, 42, arpTargetMAC)
 { }
Beispiel #13
0
 public MACAddress(MACAddress m)
     : this(m.bytes)
 {
 }