Ejemplo n.º 1
0
        /// <summary>
        /// Compares the host components of two URLs. </summary>
        /// <param name="u1"> the URL of the first host to compare </param>
        /// <param name="u2"> the URL of the second host to compare </param>
        /// <returns>  {@code true} if and only if they
        /// are equal, {@code false} otherwise.
        /// @since 1.3 </returns>
        protected internal virtual bool HostsEqual(URL u1, URL u2)
        {
            InetAddress a1 = GetHostAddress(u1);
            InetAddress a2 = GetHostAddress(u2);

            // if we have internet address for both, compare them
            if (a1 != null && a2 != null)
            {
                return(a1.Equals(a2));
                // else, if both have host names, compare them
            }
            else if (u1.Host != null && u2.Host != null)
            {
                return(u1.Host.EqualsIgnoreCase(u2.Host));
            }
            else
            {
                return(u1.Host == null && u2.Host == null);
            }
        }
Ejemplo n.º 2
0
            public override sealed bool Equals(Object obj)
            {
                if (obj == null || !(obj is InetSocketAddressHolder))
                {
                    return(false);
                }
                InetSocketAddressHolder that = (InetSocketAddressHolder)obj;
                bool sameIP;

                if (Addr != null)
                {
                    sameIP = Addr.Equals(that.Addr);
                }
                else if (Hostname != null)
                {
                    sameIP = (that.Addr == null) && Hostname.EqualsIgnoreCase(that.Hostname);
                }
                else
                {
                    sameIP = (that.Addr == null) && (that.Hostname == null);
                }
                return(sameIP && (Port_Renamed == that.Port_Renamed));
            }
Ejemplo n.º 3
0
 public virtual void Send(DatagramPacket p, sbyte ttl)
 {
     if (Closed)
     {
         throw new SocketException("Socket is closed");
     }
     CheckAddress(p.Address, "send");
     lock (TtlLock)
     {
         lock (p)
         {
             if (ConnectState == ST_NOT_CONNECTED)
             {
                 // Security manager makes sure that the multicast address
                 // is allowed one and that the ttl used is less
                 // than the allowed maxttl.
                 SecurityManager security = System.SecurityManager;
                 if (security != null)
                 {
                     if (p.Address.MulticastAddress)
                     {
                         security.CheckMulticast(p.Address, ttl);
                     }
                     else
                     {
                         security.CheckConnect(p.Address.HostAddress, p.Port);
                     }
                 }
             }
             else
             {
                 // we're connected
                 InetAddress packetAddress = null;
                 packetAddress = p.Address;
                 if (packetAddress == null)
                 {
                     p.Address = ConnectedAddress;
                     p.Port    = ConnectedPort;
                 }
                 else if ((!packetAddress.Equals(ConnectedAddress)) || p.Port != ConnectedPort)
                 {
                     throw new SecurityException("connected address and packet address" + " differ");
                 }
             }
             sbyte dttl = TTL;
             try
             {
                 if (ttl != dttl)
                 {
                     // set the ttl
                     Impl.TTL = ttl;
                 }
                 // call the datagram method to send
                 Impl.Send(p);
             }
             finally
             {
                 // set it back to default
                 if (ttl != dttl)
                 {
                     Impl.TTL = dttl;
                 }
             }
         } // synch p
     }     //synch ttl
 }         //method