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>
39 signal_shutdown(int signal
)
47 signal(SIGPIPE
, SIG_IGN
);
48 signal(SIGTERM
, signal_shutdown
);
49 signal(SIGKILL
, signal_shutdown
);
53 rand_time_delta(uint32_t t
)
56 int fd
= open("/dev/urandom", O_RDONLY
);
61 if (read(fd
, &val
, sizeof(val
)) == sizeof(val
)) {
65 val
= t
+ (rand() % range
) - (range
/ 2);
78 static struct utsname utsname
;
80 if (uname(&utsname
) < 0)
83 return utsname
.nodename
;
87 memdup(const void *d
, int l
)