# along with this program; if not, write to the Free Software Foundation.
LIBOBJS= types.o event.o query.o reply.o general.o setup.o transmit.o \
- parse.o poll.o check.o addrfam.o
+ parse.o poll.o check.o addrfam.o nextid.o
#define MAXUDP 2
+struct nextid_state {
+ unsigned fallback;
+};
+
+extern void adns__nextid_init(struct nextid_state *nextid);
+extern int adns__nextid_nextid(adns_state ads);
+
struct adns__state {
adns_initflags iflags;
adns_logcallbackfn *logfn;
int configerrno;
struct query_queue udpw, tcpw, childw, output, intdone;
adns_query forallnext;
- unsigned nextid;
+ struct nextid_state nextid;
int tcpsocket;
struct udpsocket { int af; int fd; } udpsockets[MAXUDP];
int nudpsockets;
--- /dev/null
+/*
+ * nextid.c
+ * - obtain query ids (platform-dependent)
+ */
+/*
+ * This file is part of adns, which is Copyright Ian Jackson
+ * and contributors (see the file INSTALL for full details).
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation.
+ */
+
+#include "internal.h"
+
+/* stubs */
+
+static void good_init(struct nextid_state *state) { }
+
+static int32_t good_nextid(adns_state ads) {
+ return -1;
+}
+
+/* entrypoints */
+
+void adns__nextid_init(struct nextid_state *state) {
+ good_init(state);
+ state->fallback= 0x311f;
+}
+
+int adns__nextid_nextid(adns_state ads) {
+ int r= good_nextid(ads);
+ if (r >= 0) return r;
+
+ return (ads->nextid.fallback++) & 0x0ffff;
+}
+
+
--- /dev/null
+/*
+ * nextid.c
+ * - obtain query ids (platform-dependent)
+ */
+/*
+ * This file is part of adns, which is Copyright Ian Jackson
+ * and contributors (see the file INSTALL for full details).
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation.
+ */
+
+#include "internal.h"
+
+struct nextid_state {
+ unsigned nextid;
+};
+
+static void adns__nextid_init(struct nextid_state *nextid) {
+ nextid->nextid= 0x311f;
+}
+
+static int adns__nextid_nextid(struct nextid_state *nextid) {
+ return (nextid->nextid++) & 0x0ffff;
+}
LIST_INIT(ads->output);
LIST_INIT(ads->intdone);
ads->forallnext= 0;
- ads->nextid= 0x311f;
+ adns__nextid_init(&ads->nextid);
ads->nudpsockets= 0;
ads->tcpsocket= -1;
adns__vbuf_init(&ads->tcpsend);
vb->used= 0;
MKQUERY_START(vb);
- *id_r= id= (ads->nextid++) & 0x0ffff;
+ *id_r= id= adns__nextid_nextid(ads);
MKQUERY_ADDW(id);
MKQUERY_ADDB(0x01); /* QR=Q(0), OPCODE=QUERY(0000), !AA, !TC, RD */
MKQUERY_ADDB(0x00); /* !RA, Z=000, RCODE=NOERROR(0000) */