Snarf.Udp.UdpListener.GetNetworkAddress C# (CSharp) Метод

GetNetworkAddress() публичный статический Метод

public static GetNetworkAddress ( IPAddress address, IPAddress subnetMask ) : IPAddress
address System.Net.IPAddress
subnetMask System.Net.IPAddress
Результат System.Net.IPAddress
        public static IPAddress GetNetworkAddress(IPAddress address, IPAddress subnetMask)
        {
            byte[] ipAdressBytes = address.GetAddressBytes();
            byte[] subnetMaskBytes = subnetMask.GetAddressBytes();

            if (ipAdressBytes.Length != subnetMaskBytes.Length)
                throw new ArgumentException("Lengths of IP address and subnet mask do not match.");

            byte[] broadcastAddress = new byte[ipAdressBytes.Length];
            for (int i = 0; i < broadcastAddress.Length; i++) {
                broadcastAddress[i] = (byte)(ipAdressBytes[i] & (subnetMaskBytes[i]));
            }
            return new IPAddress(broadcastAddress);
        }