2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <sys/types.h>
18 #include <libubox/uloop.h>
26 #define TTL_TIMEOUT 75
37 static struct uloop_timeout announce
;
38 struct uloop_fd
*announce_fd
;
39 static int announce_state
;
40 int announce_ttl
= 75 * 60;
43 announce_timer(struct uloop_timeout
*timeout
)
47 snprintf(host
, sizeof(host
), "%s.local", hostname
);
49 switch (announce_state
) {
53 dns_send_question(announce_fd
, host
, TYPE_ANY
);
54 uloop_timeout_set(timeout
, 250);
58 case STATE_PROBE_WAIT
:
59 uloop_timeout_set(timeout
, 500);
64 if (cache_host_is_known(host
)) {
65 fprintf(stderr
, "the host %s already exists. stopping announce service\n", host
);
71 service_announce(announce_fd
);
72 uloop_timeout_set(timeout
, announce_ttl
* 800);
78 announce_init(struct uloop_fd
*u
)
80 announce_state
= STATE_PROBE1
;
81 announce
.cb
= announce_timer
;
83 uloop_timeout_set(&announce
, 100);