System.Net.Topology.IPAddressExtensions.GetBroadcastAddress C# (CSharp) Method

GetBroadcastAddress() public static method

Gets the broadcast address of an T:System.Net.IPAddress.
public static GetBroadcastAddress ( this address, NetMask mask ) : IPAddress
address this The address
mask NetMask The net mask of the network
return IPAddress
        public static IPAddress GetBroadcastAddress(this IPAddress address, NetMask mask)
        {
            if (address == null)
                throw new ArgumentNullException("address");
            if (mask == null)
                throw new ArgumentNullException("mask");

            if (address.AddressFamily != Sockets.AddressFamily.InterNetwork)
                throw new NotSupportedException(OnlyIPv4Supported);

            // TODO: Test

            var ipBytes = address.GetAddressBytes();
            var notMaskBytes = mask.GetMaskBytes().Not();

            var broadcastAddressBytes = notMaskBytes.Or(ipBytes);
            return new IPAddress(broadcastAddressBytes);
        }