4 * Lars Fenneberg <lf@elemental.net>
6 * This software is Copyright 1996,1997 by the above mentioned author(s),
9 * The license which is distributed with this software in the file COPYRIGHT
10 * applies to this software. If your distribution is missing this file, you
11 * may request it from <pekkas@netcore.fi>.
24 tv
.tv_sec
= (time_t)(msecs
/ 1000.0);
25 tv
.tv_usec
= (suseconds_t
)((msecs
- tv
.tv_sec
* 1000.0) * 1000.0);
27 select(0,(fd_set
*)NULL
,(fd_set
*)NULL
,(fd_set
*)NULL
, &tv
);
31 rand_between(double lower
, double upper
)
33 return ((upper
- lower
) / (RAND_MAX
+ 1.0) * rand() + lower
);
37 print_addr(struct in6_addr
*addr
, char *str
)
41 /* XXX: overflows 'str' if it isn't big enough */
42 res
= inet_ntop(AF_INET6
, (void *)addr
, str
, INET6_ADDRSTRLEN
);
46 flog(LOG_ERR
, "print_addr: inet_ntop: %s", strerror(errno
));
47 strcpy(str
, "[invalid address]");
51 /* Check if an in6_addr exists in the rdnss list */
53 check_rdnss_presence(struct AdvRDNSS
*rdnss
, struct in6_addr
*addr
)
56 if ( !memcmp(&rdnss
->AdvRDNSSAddr1
, addr
, sizeof(struct in6_addr
))
57 || !memcmp(&rdnss
->AdvRDNSSAddr2
, addr
, sizeof(struct in6_addr
))
58 || !memcmp(&rdnss
->AdvRDNSSAddr3
, addr
, sizeof(struct in6_addr
)) )
59 break; /* rdnss address found in the list */
61 rdnss
= rdnss
->next
; /* no match */
63 return (rdnss
!= NULL
);
66 /* Check if a suffix exists in the dnssl list */
68 check_dnssl_presence(struct AdvDNSSL
*dnssl
, const char *suffix
)
72 for (i
= 0; i
< dnssl
->AdvDNSSLNumber
; i
++) {
73 if (strcmp(dnssl
->AdvDNSSLSuffixes
[i
], suffix
) == 0)
74 break; /* suffix found in the list */
76 if (i
!= dnssl
->AdvDNSSLNumber
)
79 dnssl
= dnssl
->next
; /* no match */
81 return (dnssl
!= NULL
);
84 /* Like read(), but retries in case of partial read */
86 readn(int fd
, void *buf
, size_t count
)
90 int r
= read(fd
, buf
, count
);
98 buf
= (char *)buf
+ r
;
105 /* Like write(), but retries in case of partial write */
107 writen(int fd
, const void *buf
, size_t count
)
111 int r
= write(fd
, buf
, count
);
119 buf
= (const char *)buf
+ r
;