return result;
}
-
-
/**
* Returns the int value of the given (hex) digit
*/
*/
const char * ldns_version(void);
+/**
+ * Implements serial arith. RFC 1982
+ * \param[in] s1 the first serial
+ * \param[in] s2 the second serial
+ * \return 0 if s1 == s2
+ * \return -1 if s1 < s2
+ * \return +1 if s1 > s2
+ * \return -2 undef
+ */
+int ldns_serial(uint32_t s1, uint32_t s2);
#endif /* !_UTIL_H */
HEADER = config.h
TESTS = run-test0 run-test7 run-test18 run-test19 run-test20 \
dname-label-test notify run-test-read-zone \
- rrsig-test
+ rrsig-test serial
.PHONY: all clean realclean
all: $(TESTS)
-lua: lua-rns
-
run-test0: run-test0.o
$(LINK) -o $@ $+
notify: notify.o
$(LINK) -o $@ $+
-lua-rns: lua-rns.o
- $(LINK) `lua-config --libs` -o $@ $+
-
-lua-rns.o: lua-rns.c
- $(COMPILE) `lua-config --include` -c $<
+serial: serial.o
+ $(LINK) -o $@ $+
## implicit rule
%.o: %.c $(HEADER)
ldns_rdf *incep, *expir;
time_t t_incep, t_expir, t_now;
+ uint32_t tweemacht = 1;
+
+ tweemacht = tweemacht << 31;
+ tweemacht = tweemacht * 2 - 1;
+
+ printf("tweemacht %u\n", tweemacht);
sig = ldns_rr_new_frm_str("jelte.nlnetlabs.nl. 18000 IN RRSIG NSEC RSASHA1 3 18000 20050913235001 20050814235001 43791 nlnetlabs.nl. epWGR0WkhWQ1h0eXvU89W57xwI0xuUlWtvvUnABQVmUfZ2nGllIy2KLR5cfgpB5UH7beASrAo78AlPddPCnH50OYNjllesDy9HLderQtjQoi47SPPluLC6v3Fwqq64Zv0wf2fPzJqDSnOOrQPVzIuB3IDv5XD4M5t8Vze8QZ8lA=", 0, NULL);
--- /dev/null
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif /* HAVE_STDINT_H */
+
+#include <ldns/dns.h>
+
+void
+test_serial(uint32_t a, uint32_t b)
+{
+ printf("%d : %d\n", a, b);
+
+ printf("%d\n",
+ ldns_serial(a,b));
+}
+
+int
+main(void)
+{
+ /* serial tests */
+ test_serial(1, 1);
+ test_serial(1, 2);
+ test_serial(2, 1);
+ test_serial(0, 0);
+
+
+}
+
{
return (char*)LDNS_VERSION;
}
+
+/* compare according to RFC 1982 (32 bits)
+ * it either return 0 meaning
+ * equal
+ * 0: s1 == s2
+ * -1: s1 < s2
+ * +1: s1 > s2
+ * something else (-2 in this case) meaning undef
+ */
+int
+ldns_serial(uint32_t s1, uint32_t s2)
+{
+ uint32_t power;
+
+ /* calculate 2^(SERIAL_BITS - 1) */
+ power = 1;
+ power = power << 31;
+ power = power * 2 - 1;
+
+ /* equality */
+ if (s1 == s2) {
+ return 0;
+ }
+
+ /* s1 is less than s2 */
+ /* (i1 < i2 and i2 - i1 < 2^(SERIAL_BITS - 1)) */
+ if (s1 < s2 &&
+ ((s2 - s1) < power)) {
+ return -1;
+ }
+ /* i1 > i2 and i1 - i2 > 2^(SERIAL_BITS - 1)) */
+ if (s1 > s2 &&
+ ((s1 - s2) > power)) {
+ return -1;
+ }
+
+ /* s1 is more than s2 */
+ /* (i1 < i2 and i2 - i1 > 2^(SERIAL_BITS - 1)) */
+ if (s1 < s2 &&
+ ((s2 - s1) > power)) {
+ return +1;
+ }
+ /* (i1 > i2 and i1 - i2 < 2^(SERIAL_BITS - 1)) */
+ if (s1 > s2 &&
+ ((s1 - s2) < power)) {
+ return +1;
+ }
+
+ /* unknown */
+ return -2;
+}