/// <summary> /// Возвращает байтовое представление пакета. /// </summary> /// <returns></returns> public byte[] GetPacketBytes() { List <byte> bytes = new List <byte>(); bytes.AddRange(BitConverter.GetBytes(Number)); bytes.AddRange(IpAddress.GetAddressBytes()); bytes.AddRange(BitConverter.GetBytes((Int16)Port)); bytes.Add((byte)State); bytes.AddRange(Information); return(bytes.ToArray()); }
public IPAddress GetNetworkAddress() { uint mask = ~(uint.MaxValue >> GetMaskSize()); byte[] ipBytes = IpAddress.GetAddressBytes(); byte[] maskBytes = BitConverter.GetBytes(mask).Reverse().ToArray(); byte[] networkIpBytes = new byte[ipBytes.Length]; for (int i = 0; i < ipBytes.Length; i++) { networkIpBytes[i] = (byte)(ipBytes[i] & maskBytes[i]); } return(new IPAddress(networkIpBytes)); }
public byte[] GetIpBytes() { return(IpAddress.GetAddressBytes()); }
private string getBinaryIp() { return(string.Join(".", IpAddress.GetAddressBytes().Select(s => Convert.ToString(s, 2).PadLeft(8, '0')))); }
public override void WriteTo(System.IO.Stream stream) { BinaryHelper.Write(stream, (uint)4); BinaryHelper.Write(stream, IpAddress.GetAddressBytes()); }