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/socket.h>
15 #include <sys/ioctl.h>
16 #include <sys/types.h>
18 #include <sys/utsname.h>
19 #include <arpa/inet.h>
29 #include <libubox/uloop.h>
30 #include <libubox/utils.h>
35 uint8_t mdns_buf
[MDNS_BUF_LEN
];
38 char mdns_hostname
[HOSTNAME_LEN
];
39 char mdns_hostname_local
[HOSTNAME_LEN
+ 6];
42 rand_time_delta(uint32_t t
)
45 int fd
= open("/dev/urandom", O_RDONLY
);
50 if (read(fd
, &val
, sizeof(val
)) == sizeof(val
)) {
54 val
= t
+ (rand() % range
) - (range
/ 2);
64 void get_hostname(void)
66 struct utsname utsname
;
69 mdns_hostname_local
[0] = 0;
71 if (uname(&utsname
) < 0)
74 snprintf(mdns_hostname
, sizeof(mdns_hostname
), "%s", utsname
.nodename
);
75 snprintf(mdns_hostname_local
, sizeof(mdns_hostname_local
), "%s.local", utsname
.nodename
);
78 time_t monotonic_time(void)
81 clock_gettime(CLOCK_MONOTONIC
, &ts
);