]> git.meshlink.io Git - catta/blobdiff - avahi-core/avahi-test.c
document that AVAHI_PROTO_xxx is no longer defined to be identical with AF_xxx
[catta] / avahi-core / avahi-test.c
index 0490c84972256e88466ddbfb9d964581499f2b05..754988c8407567429867a72efd5a1d50a3b35d64 100644 (file)
 #include <avahi-common/malloc.h>
 #include <avahi-common/simple-watch.h>
 #include <avahi-common/alternative.h>
+#include <avahi-common/timeval.h>
+
 #include <avahi-core/core.h>
 #include <avahi-core/log.h>
 #include <avahi-core/publish.h>
 #include <avahi-core/lookup.h>
+#include <avahi-core/dns-srv-rr.h>
 
 static AvahiSEntryGroup *group = NULL;
 static AvahiServer *server = NULL;
@@ -71,7 +74,6 @@ static const char *browser_event_to_string(AvahiBrowserEvent event) {
         case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CACHE_EXHAUSTED";
         case AVAHI_BROWSER_ALL_FOR_NOW : return "ALL_FOR_NOW";
         case AVAHI_BROWSER_FAILURE : return "FAILURE";
-        case AVAHI_BROWSER_NOT_FOUND : return "NOT_FOUND";
     }
 
     abort();
@@ -80,8 +82,6 @@ static const char *browser_event_to_string(AvahiBrowserEvent event) {
 static const char *resolver_event_to_string(AvahiResolverEvent event) {
     switch (event) {
         case AVAHI_RESOLVER_FOUND: return "FOUND";
-        case AVAHI_RESOLVER_TIMEOUT: return "TIMEOUT";
-        case AVAHI_RESOLVER_NOT_FOUND: return "NOT_FOUND";
         case AVAHI_RESOLVER_FAILURE: return "FAILURE";
     }
     abort();
@@ -124,7 +124,8 @@ static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntry
 
 static void server_callback(AvahiServer *s, AvahiServerState state, void* userdata) {
 
-     avahi_log_debug("server state: %i", state); 
+    server = s;
+    avahi_log_debug("server state: %i", state); 
     
     if (state == AVAHI_SERVER_RUNNING) {
         avahi_log_debug("Server startup complete. Host name is <%s>. Service cookie is %u", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s));
@@ -164,22 +165,22 @@ static void create_entries(int new_name) {
         service_name = n;
     }
     
-    if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, service_name, "_http._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
+    if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_http._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
         avahi_log_error("Failed to add HTTP service");
         goto fail;
     }
 
-    if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, service_name, "_ftp._tcp", NULL, NULL, 21, "foo", NULL) < 0) {
+    if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_ftp._tcp", NULL, NULL, 21, "foo", NULL) < 0) {
         avahi_log_error("Failed to add FTP service");
         goto fail;
     }
 
-    if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, service_name, "_webdav._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
+    if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0,service_name, "_webdav._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
         avahi_log_error("Failed to add WEBDAV service");
         goto fail;
     }
 
-    if (avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &a), 53) < 0) {
+    if (avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, NULL, AVAHI_DNS_SERVER_RESOLVE, avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &a), 53) < 0) {
         avahi_log_error("Failed to add new DNS Server address");
         goto fail;
     }
@@ -203,7 +204,7 @@ static void hnr_callback(
     const AvahiAddress *a,
     AvahiLookupResultFlags flags,
     void* userdata) {
-    char t[64];
+    char t[AVAHI_ADDRESS_STR_MAX];
 
     if (a)
         avahi_address_snprint(t, sizeof(t), a);
@@ -220,7 +221,7 @@ static void ar_callback(
     const char *hostname,
     AvahiLookupResultFlags flags,
     void* userdata) {
-    char t[64];
+    char t[AVAHI_ADDRESS_STR_MAX];
 
     avahi_address_snprint(t, sizeof(t), a);
 
@@ -283,7 +284,7 @@ static void sr_callback(
     if (event != AVAHI_RESOLVER_FOUND)
         avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain_name, resolver_event_to_string(event));
     else {
-        char t[64], *s;
+        char t[AVAHI_ADDRESS_STR_MAX], *s;
         
         avahi_address_snprint(t, sizeof(t), a);
 
@@ -304,7 +305,7 @@ static void dsb_callback(
     AvahiLookupResultFlags flags,
     void* userdata) {
     
-    char t[64] = "n/a";
+    char t[AVAHI_ADDRESS_STR_MAX] = "n/a";
     
     if (a)
         avahi_address_snprint(t, sizeof(t), a);
@@ -364,9 +365,7 @@ int main(int argc, char *argv[]) {
     avahi_elapse_time(&tv, 1000*60, 0);
     poll_api->timeout_new(poll_api, &tv, quit_timeout_callback, simple_poll);
 
-    for (;;)
-        if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
-            break;
+    avahi_simple_poll_loop(simple_poll);
 
     avahi_s_record_browser_free(r);
     avahi_s_host_name_resolver_free(hnr);