diff --git a/mdns.c b/mdns.c index 3f44ac2..213ff1f 100644 --- a/mdns.c +++ b/mdns.c @@ -32,7 +32,13 @@ #include #include #include + +#ifdef _WIN32 +#include +#include +#else #include +#endif #define DEFAULT_TTL 120 diff --git a/mdns.h b/mdns.h index 609abf8..e56fc2a 100644 --- a/mdns.h +++ b/mdns.h @@ -32,7 +32,12 @@ #include #include #include + +#ifdef _WIN32 +#include +#else #include +#endif #define MALLOC_ZERO_STRUCT(x, type) \ x = malloc(sizeof(struct type)); \ diff --git a/mdnsd.c b/mdnsd.c index b481665..c3820c2 100644 --- a/mdnsd.c +++ b/mdnsd.c @@ -26,15 +26,23 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef _WIN32 +#include +#include +#define LOG_ERR 3 +#define pipe(fds) _pipe(fds, 4096, _O_BINARY) +#else +#include #include #include #include #include #include +#include +#endif #include #include -#include #include #include #include @@ -44,7 +52,6 @@ #include #include #include -#include /* * Define a proper IP socket level if not already done. @@ -426,7 +433,11 @@ static void main_loop(struct mdnsd *svr) { free(pkt_buffer); +#ifdef _WIN32 + closesocket(svr->sockfd); +#else close(svr->sockfd); +#endif svr->stop_flag = 2; } @@ -582,8 +593,13 @@ void mdnsd_stop(struct mdnsd *s) { while (s->stop_flag != 2) select(0, NULL, NULL, NULL, &tv); +#ifdef _WIN32 + closesocket(s->notify_pipe[0]); + closesocket(s->notify_pipe[1]); +#else close(s->notify_pipe[0]); close(s->notify_pipe[1]); +#endif pthread_mutex_destroy(&s->data_lock); rr_group_destroy(s->group); diff --git a/testmdnsd.c b/testmdnsd.c index 08e6e60..ebe607d 100644 --- a/testmdnsd.c +++ b/testmdnsd.c @@ -26,8 +26,16 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef _WIN32 +#include +#include +#include +#else #include +#include #include +#endif + #include #include "mdns.h" #include "mdnsd.h" @@ -52,8 +60,21 @@ int main(int argc, char *argv[]) { mdnsd_add_rr(svr, a2_e); struct rr_entry *aaaa_e = NULL; - struct in6_addr v6addr; - inet_pton(AF_INET6, "fe80::e2f8:47ff:fe20:28e0", &v6addr); + + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET6; + hints.ai_flags = AI_NUMERICHOST; + struct addrinfo* results; + getaddrinfo( + "fe80::e2f8:47ff:fe20:28e0", + NULL, + &hints, + &results); + struct sockaddr_in6* addr = (struct sockaddr_in6*)results->ai_addr; + struct in6_addr v6addr = addr->sin6_addr; + freeaddrinfo(results); + aaaa_e = rr_create_aaaa(create_nlabel(hostname), &v6addr); mdnsd_add_rr(svr, aaaa_e);