X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=examples%2Fbrowse-services.c;h=f2707fdd1e798c100750dec03aabf8dd739575ed;hb=280e0fa69dc03706a24bf7128422443cb37d08ab;hp=bb8eed82f761b52cd7f0555c5c08d588b7d9e250;hpb=3a625af272ee8c6f878ba4d44ed1c741a1582395;p=catta diff --git a/examples/browse-services.c b/examples/browse-services.c index bb8eed8..f2707fd 100644 --- a/examples/browse-services.c +++ b/examples/browse-services.c @@ -70,13 +70,16 @@ static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, Avah we free it. If the server is terminated before the callback function is called the server will free the resolver for us. */ - avahi_service_resolver_new(s, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, resolve_callback, s); + if (!(avahi_service_resolver_new(s, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, resolve_callback, s))) + g_message("Failed to resolve service '%s': %s", name, avahi_strerror(avahi_server_errno(s))); } int main(int argc, char*argv[]) { AvahiServerConfig config; AvahiServer *server = NULL; AvahiServiceBrowser *sb; + gint error; + int ret = 1; /* Do not publish any local records */ avahi_server_config_init(&config); @@ -86,18 +89,31 @@ int main(int argc, char*argv[]) { config.publish_domain = FALSE; /* Allocate a new server */ - server = avahi_server_new(NULL, &config, NULL, NULL); + server = avahi_server_new(NULL, &config, NULL, NULL, &error); /* Free the configuration data */ avahi_server_config_free(&config); + /* Check wether creating the server object succeeded */ + if (!server) { + g_message("Failed to create server: %s", avahi_strerror(error)); + goto fail; + } + /* Create the service browser */ - sb = avahi_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, browse_callback, server); + if (!(sb = avahi_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, browse_callback, server))) { + g_message("Failed to create service browser: %s", avahi_strerror(avahi_server_errno(server))); + goto fail; + } /* Run the main loop */ main_loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(main_loop); + ret = 0; + +fail: + /* Cleanup things */ if (sb) avahi_service_browser_free(sb); @@ -108,5 +124,5 @@ int main(int argc, char*argv[]) { if (main_loop) g_main_loop_unref(main_loop); - return 0; + return ret; }