2 * $Id: util.c,v 1.10 2008/10/15 05:34:35 psavola Exp $
5 * Lars Fenneberg <lf@elemental.net>
7 * This software is Copyright 1996,1997 by the above mentioned author(s),
10 * The license which is distributed with this software in the file COPYRIGHT
11 * applies to this software. If your distribution is missing this file, you
12 * may request it from <pekkas@netcore.fi>.
25 tv
.tv_sec
= (time_t)(msecs
/ 1000.0);
26 tv
.tv_usec
= (suseconds_t
)((msecs
- tv
.tv_sec
* 1000.0) * 1000.0);
28 select(0,(fd_set
*)NULL
,(fd_set
*)NULL
,(fd_set
*)NULL
, &tv
);
32 rand_between(double lower
, double upper
)
34 return ((upper
- lower
) / (RAND_MAX
+ 1.0) * rand() + lower
);
38 print_addr(struct in6_addr
*addr
, char *str
)
42 /* XXX: overflows 'str' if it isn't big enough */
43 res
= inet_ntop(AF_INET6
, (void *)addr
, str
, INET6_ADDRSTRLEN
);
47 flog(LOG_ERR
, "print_addr: inet_ntop: %s", strerror(errno
));
48 strcpy(str
, "[invalid address]");
52 /* Check if an in6_addr exists in the rdnss list */
54 check_rdnss_presence(struct AdvRDNSS
*rdnss
, struct in6_addr
*addr
)
57 if ( !memcmp(&rdnss
->AdvRDNSSAddr1
, addr
, sizeof(struct in6_addr
))
58 || !memcmp(&rdnss
->AdvRDNSSAddr2
, addr
, sizeof(struct in6_addr
))
59 || !memcmp(&rdnss
->AdvRDNSSAddr3
, addr
, sizeof(struct in6_addr
)) )
60 break; /* rdnss address found in the list */
62 rdnss
= rdnss
->next
; /* no match */
64 return (rdnss
!= NULL
);
67 /* Like read(), but retries in case of partial read */
69 readn(int fd
, void *buf
, size_t count
)
73 int r
= read(fd
, buf
, count
);
81 buf
= (char *)buf
+ r
;
88 /* Like write(), but retries in case of partial write */
90 writen(int fd
, const void *buf
, size_t count
)
94 int r
= write(fd
, buf
, count
);
102 buf
= (const char *)buf
+ r
;