From 5352b5075e6fac123e5d868b3e87cde538a047e4 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sat, 24 Jan 2009 16:39:05 +0000 Subject: [PATCH] Make it build and fix tests in cygwin --- src/common.c | 6 +++++- src/dns.c | 4 ++++ src/iodine.c | 4 ++++ src/iodined.c | 7 ++++++- src/windows.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile | 2 +- tests/dns.c | 4 ++++ tests/read.c | 4 ++++ 8 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/windows.h diff --git a/src/common.c b/src/common.c index 22b6d38..31639ad 100644 --- a/src/common.c +++ b/src/common.c @@ -15,7 +15,11 @@ */ #include +#ifndef __CYGWIN__ #include +#else +#include "windows.h" +#endif #include #ifdef DARWIN #include @@ -38,7 +42,7 @@ #include "common.h" /* daemon(3) exists only in 4.4BSD or later, and in GNU libc */ -#if !(defined(BSD) && (BSD >= 199306)) && !defined(__GLIBC__) +#if !(defined(__CYGWIN__)) && !(defined(BSD) && (BSD >= 199306)) && !defined(__GLIBC__) static int daemon(int nochdir, int noclose) { int fd, i; diff --git a/src/dns.c b/src/dns.c index df06fd1..670efb6 100644 --- a/src/dns.c +++ b/src/dns.c @@ -15,7 +15,11 @@ */ #include +#ifndef __CYGWIN__ #include +#else +#include "windows.h" +#endif #ifdef DARWIN #include #endif diff --git a/src/iodine.c b/src/iodine.c index 67a9bff..84f948a 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -32,7 +32,11 @@ #include #include #include +#ifndef __CYGWIN__ #include +#else +#include "windows.h" +#endif #ifdef DARWIN #include #endif diff --git a/src/iodined.c b/src/iodined.c index 3295d44..04ac796 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -36,7 +36,11 @@ #include #include #include +#ifndef __CYGWIN__ #include +#else +#include "windows.h" +#endif #ifdef DARWIN #include #endif @@ -799,6 +803,7 @@ read_dns(int fd, struct query *q) memcpy((struct sockaddr*)&q->from, (struct sockaddr*)&from, addrlen); q->fromlen = addrlen; +#ifndef __CYGWIN__ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) { @@ -809,7 +814,7 @@ read_dns(int fd, struct query *q) break; } } - +#endif return strlen(q->name); } else if (r < 0) { /* Error */ diff --git a/src/windows.h b/src/windows.h new file mode 100644 index 0000000..cf98847 --- /dev/null +++ b/src/windows.h @@ -0,0 +1,49 @@ +#define T_A 1 +#define T_NS 2 +#define T_NULL 10 + +#define C_IN 1 + +#define NOERROR 0 +#define SERVFAIL 2 +#define NXDOMAIN 3 +#define NOTIMP 4 +#define REFUSED 5 + +typedef struct { + unsigned id :16; /* query identification number */ +#if BYTE_ORDER == BIG_ENDIAN + /* fields in third byte */ + unsigned qr: 1; /* response flag */ + unsigned opcode: 4; /* purpose of message */ + unsigned aa: 1; /* authoritive answer */ + unsigned tc: 1; /* truncated message */ + unsigned rd: 1; /* recursion desired */ + /* fields in fourth byte */ + unsigned ra: 1; /* recursion available */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ad: 1; /* authentic data from named */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned rcode :4; /* response code */ +#endif +#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN + /* fields in third byte */ + unsigned rd :1; /* recursion desired */ + unsigned tc :1; /* truncated message */ + unsigned aa :1; /* authoritive answer */ + unsigned opcode :4; /* purpose of message */ + unsigned qr :1; /* response flag */ + /* fields in fourth byte */ + unsigned rcode :4; /* response code */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned ad: 1; /* authentic data from named */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ra :1; /* recursion available */ +#endif + /* remaining bytes */ + unsigned qdcount :16; /* number of question entries */ + unsigned ancount :16; /* number of answer entries */ + unsigned nscount :16; /* number of authority entries */ + unsigned arcount :16; /* number of resource entries */ +} HEADER; + diff --git a/tests/Makefile b/tests/Makefile index 79f51f0..6dea799 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -23,5 +23,5 @@ $(TEST): $(OBJS) $(SRCOBJS) clean: @echo "Cleaning tests/" - @rm -f *~ *.core $(TEST) $(OBJS) + @rm -f *~ *.core $(TEST){,exe} $(OBJS) diff --git a/tests/dns.c b/tests/dns.c index 185f158..eec28e4 100644 --- a/tests/dns.c +++ b/tests/dns.c @@ -23,7 +23,11 @@ #include #include #include +#ifndef __CYGWIN__ #include +#else +#include "windows.h" +#endif #include "common.h" #include "dns.h" diff --git a/tests/read.c b/tests/read.c index ab55341..8c7618b 100644 --- a/tests/read.c +++ b/tests/read.c @@ -18,7 +18,11 @@ #include #include #include +#ifndef __CYGWIN__ #include +#else +#include "windows.h" +#endif #ifdef DARWIN #include #endif