]> git.meshlink.io Git - catta/blob - libavahi-core/main.c
move the sources to libavahi-core/
[catta] / libavahi-core / main.c
1 #include <sys/socket.h>
2 #include <netinet/in.h>
3 #include <arpa/inet.h>
4 #include <stdlib.h>
5
6 #include "avahi.h"
7
8 static gboolean quit_timeout(gpointer data) {
9     g_main_loop_quit(data);
10     return FALSE;
11 }
12
13 static gboolean dump_timeout(gpointer data) {
14     AvahiServer *Avahi = data;
15     avahi_server_dump(Avahi, stdout);
16     return TRUE;
17 }
18
19 static void subscription(AvahiSubscription *s, AvahiRecord *r, gint interface, guchar protocol, AvahiSubscriptionEvent event, gpointer userdata) {
20     gchar *t;
21     
22     g_assert(s);
23     g_assert(r);
24     g_assert(interface > 0);
25     g_assert(protocol != AF_UNSPEC);
26
27     g_message("SUBSCRIPTION: record [%s] on %i.%i is %s", t = avahi_record_to_string(r), interface, protocol,
28               event == AVAHI_SUBSCRIPTION_NEW ? "new" : (event == AVAHI_SUBSCRIPTION_CHANGE ? "changed" : "removed"));
29
30     g_free(t);
31 }
32
33 static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata) {
34     g_message("entry group state: %i", state);
35 }
36
37 int main(int argc, char *argv[]) {
38     AvahiServer *avahi;
39     gchar *r;
40     GMainLoop *loop = NULL;
41     AvahiSubscription *s;
42     AvahiKey *k;
43     AvahiEntryGroup *g;
44
45     avahi = avahi_server_new(NULL);
46
47 /*     g = avahi_entry_group_new(avahi, entry_group_callback, NULL);  */
48     
49 /*    avahi_server_add_text(avahi, g, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE, NULL, "hallo", NULL); */
50 /*      avahi_server_add_service(avahi, g, 0, AF_UNSPEC, "_http._tcp", "gurke", NULL, NULL, 80, "foo", NULL);  */
51     
52 /*     avahi_entry_group_commit(g);  */
53
54     avahi_server_dump(avahi, stdout);
55     
56     
57 /*     k = avahi_key_new("ecstasy.local.", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_ANY); */
58 /*     s = avahi_subscription_new(avahi, k, 0, AF_UNSPEC, subscription, NULL); */
59 /*     avahi_key_unref(k); */
60
61     loop = g_main_loop_new(NULL, FALSE);
62     
63   /*   g_timeout_add(1000*20, dump_timeout, Avahi); */
64 /*     g_timeout_add(1000*30, quit_timeout, loop); */
65     
66     g_main_loop_run(loop);
67     g_main_loop_unref(loop);
68
69 /*     avahi_subscription_free(s); */
70     /* avahi_entry_group_free(g);  */
71     avahi_server_free(avahi);
72     
73     return 0;
74 }