예제 #1
0
        private int LoadBootP(byte[] bytes, int index)
        {
            if (bytes == null || bytes != null && bytes.Length < 240)
            {
                IsActualDhcp = false;
                return(0);
            }

            BootPMessageType = bytes[index++];
            HType            = (HardwareType)bytes[index++];
            HLen             = bytes[index++];
            Hops             = bytes[index++];
            XId        = BitConverter.ToUInt32(new[] { bytes[index + 3], bytes[index + 2], bytes[index + 1], bytes[index] }, 0);
            index     += 4;
            Secs       = BitConverter.ToUInt16(new[] { bytes[index + 1], bytes[index] }, 0);
            index     += 2;
            BootPFlags = BitConverter.ToUInt16(new[] { bytes[index + 1], bytes[index] }, 0);
            index     += 2;
            CIAddr     = new IPAddress(new byte[] { bytes[index], bytes[index + 1], bytes[index + 2], bytes[index + 3] });
            index     += 4;
            YIAddr     = new IPAddress(new byte[] { bytes[index], bytes[index + 1], bytes[index + 2], bytes[index + 3] });
            index     += 4;
            SIAddr     = new IPAddress(new byte[] { bytes[index], bytes[index + 1], bytes[index + 2], bytes[index + 3] });
            index     += 4;
            GIAddr     = new IPAddress(new byte[] { bytes[index], bytes[index + 1], bytes[index + 2], bytes[index + 3] });
            index     += 4;

            CHAddr = new byte[16];
            var tempAddr = new byte[6];

            for (byte i = 0; i < 16; i++)
            {
                CHAddr[i] = bytes[index + i];
                if (i < 6)
                {
                    tempAddr[i] = bytes[index + i];
                }
            }
            index          += 16;
            CHAddrTruncated = new MacAddress(tempAddr);

            ServerName = ByteOps.GetAsciiString(bytes, index, 64);
            index     += 64;

            BootFileName = ByteOps.GetAsciiString(bytes, index, 128);
            index       += 128;

            MagicCookie  = BitConverter.ToUInt32(new[] { bytes[index + 3], bytes[index + 2], bytes[index + 1], bytes[index] }, 0);
            IsActualDhcp = MagicCookie == 0x63825363;
            return(index);
        }
예제 #2
0
        public static MacAddress Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new System.ArgumentNullException("text");
            }
            text = text.Replace("-", "");
            if (text.Length != 12)
            {
                throw new System.ArgumentException("Invalid MAC address length.");
            }
            var number = ulong.Parse(text, System.Globalization.NumberStyles.HexNumber);
            var bytes  = BitConverter.GetBytes(number);

            Array.Reverse(bytes);
            var mac = new MacAddress(bytes.SubArray(2, 6));

            return(mac);
        }