Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serviceframework IsLocal 判断不完善导致循环 #14

Open
wsky opened this issue Aug 31, 2012 · 1 comment
Open

serviceframework IsLocal 判断不完善导致循环 #14

wsky opened this issue Aug 31, 2012 · 1 comment
Assignees
Labels

Comments

@wsky
Copy link
Member

wsky commented Aug 31, 2012

public string GetServiceDescription(ServiceConfig service)
        {
            return this.IsLocal(service.HostUri)
                ? this.Resolve<IServiceDescriptionRender>().Render(service)
                : this._remoteHandle.GetServiceDescription(service);
        }

IsLocal 判断不完善导致循环

使用machinename和ip时

@ghost ghost assigned wsky Aug 31, 2012
@wsky
Copy link
Member Author

wsky commented Nov 22, 2012

sample in remoting corechannel.cs

// This helper function Checks whether the remote IP Adress is actually a local address 
        internal static bool IsLocalIpAddress(IPAddress remoteAddress)
        { 
            if (s_MachineIpAddress == null) 
            {
                String hostName = GetMachineName(); 

                // NOTE: We intentionally allow exceptions from these api's
                //  propagate out to the caller.
                IPHostEntry ipEntries = Dns.GetHostEntry(hostName); 
                // If there is only one entry we should cache it
                if(ipEntries != null && ipEntries.AddressList.Length == 1) 
                { 
                    if (Socket.OSSupportsIPv4)
                    { 
                        s_MachineIpAddress = GetMachineAddress(ipEntries, AddressFamily.InterNetwork);
                    }
                    else
                    { 
                        s_MachineIpAddress = GetMachineAddress(ipEntries, AddressFamily.InterNetworkV6);
                    } 
                } 
                else
                { 
                    return IsLocalIpAddress(ipEntries, remoteAddress.AddressFamily, remoteAddress);
                }
            }
            return s_MachineIpAddress.Equals(remoteAddress); 
        }

        //This helper function compares and IpAddress with all addresses in IpHostEntry 
        internal static bool IsLocalIpAddress(IPHostEntry host, AddressFamily addressFamily, IPAddress remoteAddress)
        { 
            if (host != null)
            {
                IPAddress[] addressList = host.AddressList;
                for (int i = 0; i < addressList.Length; i++) 
                {
                    if (addressList[i].AddressFamily == addressFamily) 
                    { 
                        if(addressList[i].Equals(remoteAddress))
                            return true; 
                    }
                }
            }
            return false; 
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant