private void OnServiceResolved(object o, ServiceResolvedEventArgs args) { string name = args.Service.Name; Log.DebugFormat("Managed to resolve DAAP share {0}.", args.Service.Name); bool password_required = false; // iTunes tacks this on to indicate a passsword protected share. Ugh. if (name.EndsWith("_PW")) { name = name.Substring(0, name.Length - 3); password_required = true; } IResolvableService service = (IResolvableService)args.Service; foreach (TxtRecordItem item in service.TxtRecord) { if (item.Key.ToLower() == "password") { password_required = item.ValueString.ToLower() == "true"; } else if (item.Key.ToLower() == "machine name") { name = item.ValueString; } } IPAddress address = args.Service.HostEntry.AddressList[0]; Log.DebugFormat("OnServiceResolved provided {0}", address); // XXX: Workaround a Mono bug where we can't resolve IPv6 addresses properly if (services.ContainsKey(name) && address.AddressFamily == AddressFamily.InterNetworkV6) { // Only skip this service if it resolves to a IPv6 address, and we already have info // for this service already. Log.Debug("Skipping service", "already have IPv4 address."); return; } else if (!services.ContainsKey(name) && address.AddressFamily == AddressFamily.InterNetworkV6) { // This is the first address we've resolved, however, it's an IPv6 address. // Try and resolve the hostname in hope that it'll end up as an IPv4 address - it doesn't // really matter if it still ends up with an IPv6 address, we're not risking anything. foreach (IPAddress addr in Dns.GetHostEntry(args.Service.HostEntry.HostName).AddressList) { if (addr.AddressFamily == AddressFamily.InterNetwork) { address = addr; } } } Log.DebugFormat("Using address {0}", address); Daap.Service svc = new Daap.Service(address, (ushort)service.Port, name, password_required); if (services.ContainsKey(name)) { services[name] = svc; } else { services.Add(name, svc); } if (Found != null) { Found(this, new ServiceArgs(svc)); } }
private void OnServiceResolved(object o, ServiceResolvedEventArgs args) { string name = args.Service.Name; Log.DebugFormat ("Managed to resolve DAAP share {0}.", args.Service.Name); bool password_required = false; // iTunes tacks this on to indicate a passsword protected share. Ugh. if (name.EndsWith ("_PW")) { name = name.Substring (0, name.Length - 3); password_required = true; } IResolvableService service = (IResolvableService) args.Service; foreach(TxtRecordItem item in service.TxtRecord) { if(item.Key.ToLower () == "password") { password_required = item.ValueString.ToLower () == "true"; } else if (item.Key.ToLower () == "machine name") { name = item.ValueString; } } IPAddress address = args.Service.HostEntry.AddressList[0]; Log.DebugFormat ("OnServiceResolved provided {0}", address); // XXX: Workaround a Mono bug where we can't resolve IPv6 addresses properly if (services.ContainsKey (name) && address.AddressFamily == AddressFamily.InterNetworkV6) { // Only skip this service if it resolves to a IPv6 address, and we already have info // for this service already. Log.Debug ("Skipping service", "already have IPv4 address."); return; } else if (!services.ContainsKey (name) && address.AddressFamily == AddressFamily.InterNetworkV6) { // This is the first address we've resolved, however, it's an IPv6 address. // Try and resolve the hostname in hope that it'll end up as an IPv4 address - it doesn't // really matter if it still ends up with an IPv6 address, we're not risking anything. try { foreach (IPAddress addr in Dns.GetHostEntry (args.Service.HostEntry.HostName).AddressList) { if (addr.AddressFamily == AddressFamily.InterNetwork) { address = addr; } } } catch (SocketException) { Log.WarningFormat ("Unable to resolve IPv6 host {0}", args.Service.HostEntry.HostName); } } Log.DebugFormat ("Using address {0}", address); Daap.Service svc = new Daap.Service (address, (ushort)service.Port, name, password_required); if (services.ContainsKey (name)) { services[name] = svc; } else { services.Add (name, svc); } if (Found != null) Found (this, new ServiceArgs (svc)); }