summaryrefslogtreecommitdiff
path: root/accel-pppd/ipv6_dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd/ipv6_dns.c')
-rw-r--r--accel-pppd/ipv6_dns.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/accel-pppd/ipv6_dns.c b/accel-pppd/ipv6_dns.c
new file mode 100644
index 00000000..bb1d13f3
--- /dev/null
+++ b/accel-pppd/ipv6_dns.c
@@ -0,0 +1,33 @@
+#include <limits.h>
+
+#include "triton.h"
+#include "ipv6_dns.h"
+
+#include "memdebug.h"
+
+int __export ipv6_dns_reserve(struct ipv6_dns_t *dns, unsigned int count)
+{
+ struct in6_addr *addr;
+ unsigned int capacity;
+
+ if (count <= dns->capacity)
+ return 0;
+
+ capacity = dns->capacity;
+ if (!capacity)
+ capacity = IPV6_DNS_INITIAL_CAPACITY;
+ while (capacity < count) {
+ /* Doubling past this would wrap around and spin forever */
+ if (capacity > UINT_MAX / 2)
+ return -1;
+ capacity *= 2;
+ }
+
+ addr = _realloc(dns->addr, capacity * sizeof(*addr));
+ if (!addr)
+ return -1;
+
+ dns->addr = addr;
+ dns->capacity = capacity;
+ return 0;
+}