]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
file correction
authorMiek Gieben <miekg@NLnetLabs.nl>
Wed, 11 May 2005 10:13:26 +0000 (10:13 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Wed, 11 May 2005 10:13:26 +0000 (10:13 +0000)
ldns/dns.h.in [deleted file]
ldns/util.h.in [new file with mode: 0644]

diff --git a/ldns/dns.h.in b/ldns/dns.h.in
deleted file mode 100644 (file)
index a728728..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * dns.h -- defines for the Domain Name System
- *
- * Copyright (c) 2001-2005, NLnet Labs. All rights reserved.
- *
- * See LICENSE for the license.
- *
- * A bunch of defines that are used in the DNS
- */
-
-#ifndef _DNS_H_
-#define _DNS_H_
-
-#include <ldns/config.h>
-#include <ldns/util.h>
-#include <ldns/buffer.h>
-#include <ldns/common.h>
-#include <ldns/dname.h>
-#include <ldns/dnssec.h>
-#include <ldns/error.h>
-#include <ldns/higher.h>
-#include <ldns/host2str.h>
-#include <ldns/host2wire.h>
-#include <ldns/net.h>
-#include <ldns/packet.h>
-#include <ldns/rdata.h>
-#include <ldns/resolver.h>
-#include <ldns/rr.h>
-#include <ldns/str2host.h>
-#include <ldns/wire2host.h>
-#include <ldns/rr_functions.h>
-#include <ldns/keys.h>
-#include <ldns/parse.h>
-
-#define LDNS_IP4ADDRLEN      (32/8)
-#define LDNS_IP6ADDRLEN      (128/8)
-#define LDNS_PORT      53
-#define LDNS_ROOT_LABEL        '\0'
-#define LDNS_DEFTTL            3600
-
-/* lookup tables for standard DNS stuff  */
-
-/* Taken from RFC 2538, section 2.1.  */
-extern ldns_lookup_table ldns_certificate_types[];
-/* Taken from RFC 2535, section 7.  */
-extern ldns_lookup_table ldns_algorithms[];
-/* rr types  */
-extern ldns_lookup_table ldns_rr_classes[];
-/* if these are used elsewhere */
-extern ldns_lookup_table ldns_rcodes[];
-extern ldns_lookup_table ldns_opcodes[];
-
-#endif /* _DNS_H_ */
diff --git a/ldns/util.h.in b/ldns/util.h.in
new file mode 100644 (file)
index 0000000..1cf0bab
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * util.h
+ *  
+ * helper function header file
+ * 
+ * a Net::DNS like library for C
+ * 
+ * (c) NLnet Labs, 2004
+ * 
+ * See the file LICENSE for the license
+ */
+
+#ifndef _UTIL_H
+#define _UTIL_H
+
+#define dprintf(X,Y) fprintf(stderr, (X), (Y))
+/* #define     dprintf(X, Y)  */
+
+#define LDNS_VERSION "@PACKAGE_VERSION@"
+
+/**
+ * splint static inline workaround
+ */
+#ifdef S_SPLINT_S
+#define INLINE 
+#else
+#define INLINE static inline
+#endif
+
+/**
+ * Memory management macro's
+ */
+#define LDNS_MALLOC(type)              LDNS_XMALLOC(type, 1)
+
+#define LDNS_XMALLOC(type, count)      ((type *) malloc((count) * sizeof(type)))
+
+#define LDNS_REALLOC(ptr, type)                LDNS_XREALLOC((ptr), type, 1)
+
+#define LDNS_XREALLOC(ptr, type, count)                                \
+       ((type *) realloc((ptr), (count) * sizeof(type)))
+
+#define LDNS_FREE(ptr) \
+       do { free((ptr)); (ptr) = NULL; } while (0)
+
+#define LDNS_DEP     printf("DEPRECATED FUNCTION!\n");
+
+/*
+ * Copy data allowing for unaligned accesses in network byte order
+ * (big endian).
+ */
+INLINE uint16_t
+read_uint16(const void *src)
+{
+#ifdef ALLOW_UNALIGNED_ACCESSES
+       return ntohs(*(uint16_t *) src);
+#else
+       uint8_t *p = (uint8_t *) src;
+       return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
+#endif
+}
+
+INLINE uint32_t
+read_uint32(const void *src)
+{
+#ifdef ALLOW_UNALIGNED_ACCESSES
+       return ntohl(*(uint32_t *) src);
+#else
+       uint8_t *p = (uint8_t *) src;
+       return (  ((uint32_t) p[0] << 24)
+               | ((uint32_t) p[1] << 16)
+               | ((uint32_t) p[2] << 8)
+               |  (uint32_t) p[3]);
+#endif
+}
+
+/*
+ * Copy data allowing for unaligned accesses in network byte order
+ * (big endian).
+ */
+INLINE void
+write_uint16(void *dst, uint16_t data)
+{
+#ifdef ALLOW_UNALIGNED_ACCESSES
+       * (uint16_t *) dst = htons(data);
+#else
+       uint8_t *p = (uint8_t *) dst;
+       p[0] = (uint8_t) ((data >> 8) & 0xff);
+       p[1] = (uint8_t) (data & 0xff);
+#endif
+}
+
+INLINE void
+write_uint32(void *dst, uint32_t data)
+{
+#ifdef ALLOW_UNALIGNED_ACCESSES
+       * (uint32_t *) dst = htonl(data);
+#else
+       uint8_t *p = (uint8_t *) dst;
+       p[0] = (uint8_t) ((data >> 24) & 0xff);
+       p[1] = (uint8_t) ((data >> 16) & 0xff);
+       p[2] = (uint8_t) ((data >> 8) & 0xff);
+       p[3] = (uint8_t) (data & 0xff);
+#endif
+}
+
+/* warning. */
+INLINE void
+write_uint64_as_uint48(void *dst, uint64_t data)
+{
+       uint8_t *p = (uint8_t *) dst;
+       p[0] = (uint8_t) ((data >> 40) & 0xff);
+       p[1] = (uint8_t) ((data >> 32) & 0xff);
+       p[2] = (uint8_t) ((data >> 24) & 0xff);
+       p[3] = (uint8_t) ((data >> 16) & 0xff);
+       p[4] = (uint8_t) ((data >> 8) & 0xff);
+       p[5] = (uint8_t) (data & 0xff);
+}
+
+/* A general purpose lookup table */
+typedef struct lookup_table ldns_lookup_table;
+struct lookup_table {
+        int id;
+        const char *name;
+};
+  
+/**
+ * Looks up the table entry by name, returns NULL if not found.
+ */
+ldns_lookup_table *ldns_lookup_by_name(ldns_lookup_table table[],
+                                       const char *name);
+
+/**
+ * Looks up the table entry by id, returns NULL if not found.
+ */
+ldns_lookup_table *ldns_lookup_by_id(ldns_lookup_table table[], int id);
+
+/**
+ * Returns the value of the specified bit
+ * The bits are counted from left to right, so bit #0 is the
+ * left most bit.
+ */
+int get_bit(uint8_t bits[], size_t index);
+
+
+/**
+ * Returns the value of the specified bit
+ * The bits are counted from right to left, so bit #0 is the
+ * right most bit.
+ */
+int get_bit_r(uint8_t bits[], size_t index);
+
+/**
+ * Returns the value of a to the power of b
+ * (or 1 of b < 1)
+ */
+long power(long a, long b); 
+
+/**
+ * Returns the int value of the given (hex) digit
+ */
+int hexdigit_to_int(char ch);
+
+/**
+ * Returns the char (hex) representation of the given int
+ */
+char int_to_hexdigit(int ch);
+
+/**
+ *
+ */
+char * ldns_version(void);
+
+#endif /* !_UTIL_H */