In the avahi-client C-API there is the concept of a Service Browser and a 
Record Browser. Service Browser sounds like what you are using now:

| AvahiServiceBrowser* avahi_service_browser_new | ( | AvahiClient *  | client, 
|
|  |  | AvahiIfIndex  | interface, |
|  |  | AvahiProtocol  | protocol, |
|  |  | const char *  | type, |
|  |  | const char *  | domain, |
|  |  | AvahiLookupFlags  | flags, |
|  |  | AvahiServiceBrowserCallback  | callback, |
|  |  | void *  | userdata  |
|  | ) |


The type being for example _http._tcp. Whereas a Record Browser looks like this:

| AvahiRecordBrowser* avahi_record_browser_new | ( | AvahiClient *  | client, |
|  |  | AvahiIfIndex  | interface, |
|  |  | AvahiProtocol  | protocol, |
|  |  | const char *  | name, |
|  |  | uint16_t  | clazz, |
|  |  | uint16_t  | type, |
|  |  | AvahiLookupFlags  | flags, |
|  |  | AvahiRecordBrowserCallback  | callback, |
|  |  | void *  | userdata  |
|  | ) |


I wonder if that is a more generic mDNS browser? Unfortunately the parameters, 
and what a "record" is, is not explained in the online documentation. I'll have 
a look in the source to see if I can find out more.
Regards,Jonathan 

     On Tuesday, 25 November 2014, 13:17, Michael Jones <av...@jonesmz.com> 
wrote:
   

 


Hi Michael,
I'm looking at your ZConfBrowserWidget and I see that it needs a service type. 
Technically I believe from what I've been reading the mDNS host announcements 
are different to an DNS-SD service, although they are both announced in a 
similar way.Is there a "service type" that catches the mDNS hostname 
announcements?
Regards,
Jonathan

     On Friday, 21 November 2014, 15:08, Jonathan Fitt <jonf...@yahoo.com> 
wrote:


 Thanks! I'll give that a go and let you know how it goes. 
Jonathan
On Nov 21, 2014, at 1:25 PM, Michael Jones <av...@jonesmz.com> wrote:




Hello,I am looking for a way for a Linux machine to tell when I return home. My 
idea is that my iPhone will always do an mDNS announcement when it joins my 
home wifi. So I'm looking for a way to watch for mDNS announcements and perform 
and action if the right one is seen. Obviously the avahi-daemon is watching 
these all the time and updating its cache, so I was thinking that there might 
be a good place to start. However the only command line way I can see to get to 
the avahi-daemon cache is to send a SIGUSR1 to get it to dump to 
/var/log/syslog. Then I can look at the timestamp to determine the last time it 
registered and compare with now. That seems quite ugly though, and I don't like 
the idea of continually dumping to syslog.
So is there a way to make it more event driven with the avahi-daemon? I think 
from looking at the D-Bus API that might be the way to go?If it is the right 
approach, I would appreciate it if someone knew of a related chunk of source 
that I could use as a starting point.
Thanks!Jonathan



Write a small program that uses the Avahi API. A very high level wrapper for 
the Avahi API is: https://github.com/johanneshilden/qtzeroconf

Using that, you can detect your phone joining your home network in under 10 
lines of code.
Create the service browser object
Connect that new object to a qt slot that'll respond to the new service joining 
your network, Tell the service browser object which services to listen for.

>From there, you can do whatever you want with the information. Perhaps you 
>would want to send some kind of DBus signal to let other programs know.

I'm afraid I haven't investigated the DBus API, so I'm not certain I can give 
you any advice in that direction, but I have written apps using the high level 
Qt API that I linked above, and I've never had any trouble with it.

--Michael Jone


Hi Jonathan 


That's a good question. I actually don't know. The qtzeroconf library isn't 
actually mine, originally. I made a lot of modifications to it (Here: 
https://github.com/jonesmz/qtzeroconf) that take advantage of Qt5 and C++11, 
but those changes aren't compatible with older versions of Qt, so I didn't want 
to recommend it to you.

If you feel like poking around at the Avahi C API and can demonstrate how to 
get mDNS host announcements out of the Avahi C api, I'd be willing to add 
support for that to my version of the qtzeroconf library (though, it'll still 
not be compatible with Qt4 or older versions of C++, so you might end up 
needing to backport the changes to the original authors github project.)

If you want to work just with what the current qtzeroconf library can do, you 
can just make your phone advertise an avahi service. Perhaps give the protocol 
name something like "_phone._tcp" or something. 

Another thing to keep in mind, I don't know whether Avahi will automatically 
detect your phone on the local network unless your phone's operating system 
automatically sends that announcement. As far as I know, Android doesn't do 
that. I don't know about the other phone OS's.

Best of luck, and let me know if you want to investigate the host announcement 
support in qtzeroconf.

--Michael Jones

_______________________________________________
avahi mailing list
avahi@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/avahi


   
_______________________________________________
avahi mailing list
avahi@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/avahi

Reply via email to