From 980bcd68f7e49f8c0a9042f64d62e624f8c5f76b Mon Sep 17 00:00:00 2001
From: Nick Mathewson <nickm@torproject.org>
Date: Fri, 2 Jan 2009 21:21:58 +0000
Subject: [PATCH] Work better with platforms that do not have ipv6 structures, or that do not have sin_len fields, etc.

svn:r986
---
 Makefile.am         |    2 +-
 configure.in        |   49 ++++++++++++++++++++++++++++++++++++++++++-------
 evdns.c             |    7 +------
 evutil.c            |    5 +++++
 ipv6-internal.h     |   37 +++++++++++++++++++++++++++++++++++++
 test/regress_util.c |    5 +++++
 6 files changed, 91 insertions(+), 14 deletions(-)
 create mode 100644 ipv6-internal.h

Index: libevent-1.4.14b-stable/Makefile.am
===================================================================
--- libevent-1.4.14b-stable.orig/Makefile.am	2011-06-25 16:14:52.000000000 +0400
+++ libevent-1.4.14b-stable/Makefile.am	2011-06-25 16:19:15.893312530 +0400
@@ -120,7 +120,7 @@
 CORE_SRC = event.c buffer.c evbuffer.c log.c evutil.c $(SYS_SRC)
 EXTRA_SRC = event_tagging.c http.c evhttp.h http-internal.h evdns.c \
 	evdns.h evrpc.c evrpc.h evrpc-internal.h \
-	strlcpy.c strlcpy-internal.h strlcpy-internal.h
+	strlcpy.c strlcpy-internal.h ipv6-internal.h
 
 libevent_la_SOURCES = $(CORE_SRC) $(EXTRA_SRC)
 libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS)
Index: libevent-1.4.14b-stable/configure.in
===================================================================
--- libevent-1.4.14b-stable.orig/configure.in	2011-06-25 16:14:52.000000000 +0400
+++ libevent-1.4.14b-stable/configure.in	2011-06-25 16:23:04.970448462 +0400
@@ -66,7 +66,7 @@
 
 dnl Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h stdarg.h inttypes.h stdint.h poll.h signal.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h sys/param.h sys/ioctl.h sys/select.h sys/devpoll.h port.h netinet/in6.h sys/socket.h)
+AC_CHECK_HEADERS(fcntl.h stdarg.h inttypes.h stdint.h stddef.h poll.h signal.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h sys/param.h sys/ioctl.h sys/select.h sys/devpoll.h port.h netinet/in.h netinet/in6.h sys/socket.h sys/uio.h arpa/inet.h)
 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
 	AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
 	AC_EGREP_CPP(yes,
@@ -343,17 +343,52 @@
 AC_CHECK_SIZEOF(long long)
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(short)
-AC_CHECK_TYPES([struct in6_addr], , ,
-[#ifdef WIN32
-#include <winsock2.h>
-#else
-#include <sys/types.h>
+AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
+[#include <sys/types.h>
+#ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
+#endif
+#ifdef HAVE_NETINET_IN6_H
+#include <netinet/in6.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
+#ifdef WIN32
+#define WIN32_WINNT 0x400
+#define _WIN32_WINNT 0x400
+#define WIN32_LEAN_AND_MEAN
+#if defined(_MSC_VER) && (_MSC_VER < 1300)
+#include <winsock.h>
+#else
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif
+#endif
+])
+AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
+[#include <sys/types.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
 #ifdef HAVE_NETINET_IN6_H
 #include <netinet/in6.h>
-#endif])
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef WIN32
+#define WIN32_WINNT 0x400
+#define _WIN32_WINNT 0x400
+#define WIN32_LEAN_AND_MEAN
+#if defined(_MSC_VER) && (_MSC_VER < 1300)
+#include <winsock.h>
+#else
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif
+#endif
+])
 
 AC_MSG_CHECKING([for socklen_t])
 AC_TRY_COMPILE([
Index: libevent-1.4.14b-stable/evdns.c
===================================================================
--- libevent-1.4.14b-stable.orig/evdns.c	2010-06-20 17:06:04.000000000 +0400
+++ libevent-1.4.14b-stable/evdns.c	2011-06-25 16:25:05.427045781 +0400
@@ -102,6 +102,7 @@
 #include "evdns.h"
 #include "evutil.h"
 #include "log.h"
+#include "ipv6-internal.h"
 #ifdef WIN32
 #include <winsock2.h>
 #include <windows.h>
@@ -184,12 +185,6 @@
 	char transmit_me;  /* needs to be transmitted */
 };
 
-#ifndef HAVE_STRUCT_IN6_ADDR
-struct in6_addr {
-	u8 s6_addr[16];
-};
-#endif
-
 struct reply {
 	unsigned int type;
 	unsigned int have_answer;
Index: libevent-1.4.14b-stable/ipv6-internal.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ libevent-1.4.14b-stable/ipv6-internal.h	2011-06-25 16:38:19.666984189 +0400
@@ -0,0 +1,36 @@
+/* Internal use only: Fake IPv6 structures and values on platforms that
+ * do not have them */
+
+#ifndef _EVENT_IPV6_INTERNAL_H
+#define _EVENT_IPV6_INTERNAL_H
+
+#include <sys/types.h>
+#include "event-config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _EVENT_HAVE_STRUCT_IN6_ADDR
+struct in6_addr {
+	ev_uint8_t s6_addr[16];
+};
+#endif
+
+#ifndef _EVENT_HAVE_SA_FAMILY_T
+typedef int sa_family_t
+#endif
+
+#ifndef _EVENT_HAVE_STRUCT_SOCKADDR_IN6
+struct sockaddr_in6 {
+	sa_family_t sin6_family;
+	ev_uint16_t sin6_port;
+	struct in6_addr sin6_addr;
+};
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
