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>
20 #include <linux/sockios.h>
21 #include <arpa/inet.h>
31 #include <libubox/uloop.h>
36 uint8_t mdns_buf
[MDNS_BUF_LEN
];
39 char mdns_hostname
[HOSTNAME_LEN
];
40 char mdns_hostname_local
[HOSTNAME_LEN
+ 6];
43 rand_time_delta(uint32_t t
)
46 int fd
= open("/dev/urandom", O_RDONLY
);
51 if (read(fd
, &val
, sizeof(val
)) == sizeof(val
)) {
55 val
= t
+ (rand() % range
) - (range
/ 2);
65 void get_hostname(void)
67 struct utsname utsname
;
70 mdns_hostname_local
[0] = 0;
72 if (uname(&utsname
) < 0)
75 snprintf(mdns_hostname
, sizeof(mdns_hostname
), "%s", utsname
.nodename
);
76 snprintf(mdns_hostname_local
, sizeof(mdns_hostname_local
), "%s.local", utsname
.nodename
);
80 memdup(const void *d
, int l
)