예제 #1
0
		/// <summary>
		/// Determines whether the IP address is in the same subnet as the
		/// specified IP address.
		/// </summary>
		/// <param name="address">The IPAddress instance this is being called
		/// for.</param>
		/// <param name="other">The IP address to determine whether it is in the same
		/// subnet.</param>
		/// <param name="netmask">The subnetmask to apply.</param>
		/// <returns>true if both IP address are located in the same subnet; Otherwise
		/// false.</returns>
		/// <exception cref="ArgumentNullException">The other parameter or the netmask
		/// parameter is null.</exception>
		/// <exception cref="ArgumentException">The netmask and IP address must be
		/// of the same address family.</exception>
		/// <remarks>This is an extension method for the IPAddress class.</remarks>
		public static bool InSameSubnet(this IPAddress address, IPAddress other,
			IPAddress netmask) {
			other.ThrowIfNull("other");
			netmask.ThrowIfNull("netmask");

			return address.And(netmask).Equals(other.And(netmask));
		}