What is the hostname while invoking GetAddrInfo(…) in Bonjour 1.0

廉价感情. 提交于 2019-12-20 04:06:31

问题


I scanned through my local home network using Bonjour 1.0(.NET) for services with regtype = "_http._tcp":

 DNSSDService service = new DNSSDService();
            DNSSDEventManager eventManager = new DNSSDEventManager();
            eventManager.ServiceFound += new _IDNSSDEvents_ServiceFoundEventHandler(eventManager_ServiceFound);
            DNSSDService browse = service.Browse(0, 0, "_http._tcp", null, eventManager);

When I find the service the method: static void eventManager_ServiceFound(DNSSDService browser, DNSSDFlags flags, uint ifIndex, string serviceName, string regtype, string domain) is invoked.

Then in that method I want to use method: DNSSDService GetAddrInfo(DNSSDFlags glags, uint ifIndex, DNSSDAddressFamily addressFamily,string hostname, DNSSDEventManager eventManager) to get to know service's ip address and port.

The problem is that I do not know know what string hostname should be and thus I do not get any results: ** Please look at the: ???WHAT HERE?? in the code**

 static void eventManager_ServiceFound(DNSSDService browser, DNSSDFlags flags, uint ifIndex, string serviceName, string regtype, string domain) {
            Console.WriteLine("browser: " + browser + "\nDNSSDFlags " +  flags+ "\nifIndex " + ifIndex +"\nserviceName: " + serviceName + "\nregtype: " +regtype+ "\ndomain: "+ domain);
            DNSSDEventManager eventManager = new DNSSDEventManager();
            eventManager.AddressFound += new _IDNSSDEvents_AddressFoundEventHandler(eventManager_AddressFound);
            DNSSDAddressFamily family = new DNSSDAddressFamily();
            browser.GetAddrInfo(flags, ifIndex, family, ???WHAT HERE???, eventManager);
        }

        private static void eventManager_AddressFound(DNSSDService service, DNSSDFlags flags, uint ifIndex, string hostname, DNSSDAddressFamily addressFamily, string address, uint ttl) {
            Console.WriteLine("----------------------------------------");
            Console.WriteLine("FOUND THE ADDRESS");
            Console.WriteLine("----------------------------------------");
        }

Output:

browser: System.__ComObject
DNSSDFlags 2
ifIndex 32
serviceName: AXIS M1011-W - 00408CBEEAE5
regtype: _http._tcp.
domain: local.

Full code:

using Bonjour;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1 {
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            DNSSDService service = new DNSSDService();
            DNSSDEventManager eventManager = new DNSSDEventManager();
            eventManager.ServiceFound += new _IDNSSDEvents_ServiceFoundEventHandler(eventManager_ServiceFound);
         //   DNSSDService browse = service.Browse(0, 0, "_axis-video._tcp", null, eventManager);
            DNSSDService browse = service.Browse(0, 0, "_http._tcp", null, eventManager);


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        static void eventManager_ServiceFound(DNSSDService browser, DNSSDFlags flags, uint ifIndex, string serviceName, string regtype, string domain) {
            Console.WriteLine("browser: " + browser + "\nDNSSDFlags " +  flags+ "\nifIndex " + ifIndex +"\nserviceName: " + serviceName + "\nregtype: " +regtype+ "\ndomain: "+ domain);
            DNSSDEventManager eventManager = new DNSSDEventManager();
            eventManager.AddressFound += new _IDNSSDEvents_AddressFoundEventHandler(eventManager_AddressFound);
            DNSSDAddressFamily family = new DNSSDAddressFamily();
            browser.GetAddrInfo(flags, ifIndex, family, ?????WHAT HERE?????, eventManager);
        }

        private static void eventManager_AddressFound(DNSSDService service, DNSSDFlags flags, uint ifIndex, string hostname, DNSSDAddressFamily addressFamily, string address, uint ttl) {
            Console.WriteLine("----------------------------------------");
            Console.WriteLine("FOUND ADDRESS");
            Console.WriteLine("----------------------------------------");
        }



    }
}

回答1:


Something that I'd check first is the TXT record associated with the _http._tcp record. From the screenshot you have the _axis-video._tcp selected and it shows you the macaddress associated with it. Many _http._tcp entries record the url needed to get to it, or the port/ipaddress needed. I'd dig into that first.

Otherwise you may have to resolve the macaddress into an ipaddress. I googled and come with http://www.mostthingsweb.com/2011/11/reading-arp-entries-with-c/



来源:https://stackoverflow.com/questions/21065459/what-is-the-hostname-while-invoking-getaddrinfo-in-bonjour-1-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!