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>
34 uint8_t mdns_buf
[MDNS_BUF_LEN
];
37 char mdns_hostname
[HOSTNAME_LEN
];
38 char mdns_hostname_local
[HOSTNAME_LEN
+ 6];
41 rand_time_delta(uint32_t t
)
44 int fd
= open("/dev/urandom", O_RDONLY
);
49 if (read(fd
, &val
, sizeof(val
)) == sizeof(val
)) {
53 val
= t
+ (rand() % range
) - (range
/ 2);
63 void get_hostname(void)
65 struct utsname utsname
;
68 mdns_hostname_local
[0] = 0;
70 if (uname(&utsname
) < 0)
73 snprintf(mdns_hostname
, sizeof(mdns_hostname
), "%s", utsname
.nodename
);
74 snprintf(mdns_hostname_local
, sizeof(mdns_hostname_local
), "%s.local", utsname
.nodename
);