From 18e2b5ed1ffb3e7c5dfec8ff41b3027163f680ed Mon Sep 17 00:00:00 2001
From: Leonid Evdokimov <leon@darkk.net.ru>
Date: Wed, 12 Sep 2012 02:05:39 +0400
Subject: [PATCH 09/12] Fix compilation on Ubuntu 10.04 LTS and (hopefully)
 Debian squeeze[1]

fixes #28, fixes #22, fixes #24
[1] current "stable" release
---
 libc-compat.h     | 25 +++++++++++++++++++++++++
 libevent-compat.h | 11 +++++++++++
 redsocks.c        |  1 +
 redudp.c          |  1 +
 utils.c           |  1 +
 5 files changed, 39 insertions(+)
 create mode 100644 libc-compat.h
 create mode 100644 libevent-compat.h

diff --git a/libc-compat.h b/libc-compat.h
new file mode 100644
index 0000000..adcf63b
--- /dev/null
+++ b/libc-compat.h
@@ -0,0 +1,25 @@
+#ifndef UUID_67C91670_FCCB_4855_BDF7_609F1EECB8B4
+#define UUID_67C91670_FCCB_4855_BDF7_609F1EECB8B4
+
+/* all these definitions, are included into bits/in.h from libc6-dev 2.15-0ubuntu10
+ * from Ubuntu 12.04 and is not included into libc6-dev 2.11.1-0ubuntu7.10 from
+ * Ubuntu 10.04.
+ * linux/in.h is not included directly because of lots of redefinitions,
+ * extracting single value from linux/in.h is not done because it looks like
+ * autotools reinvention */
+#ifndef IP_ORIGDSTADDR
+#   warning Using hardcoded value for IP_ORIGDSTADDR as libc headers do not define it.
+#   define IP_ORIGDSTADDR 20
+#endif
+
+#ifndef IP_RECVORIGDSTADDR
+#   warning Using hardcoded value for IP_RECVORIGDSTADDR as libc headers do not define it.
+#   define IP_RECVORIGDSTADDR IP_ORIGDSTADDR
+#endif
+
+#ifndef IP_TRANSPARENT
+#   warning Using hardcoded value for IP_TRANSPARENT as libc headers do not define it.
+#   define IP_TRANSPARENT 19
+#endif
+
+#endif // 67C91670_FCCB_4855_BDF7_609F1EECB8B4
diff --git a/libevent-compat.h b/libevent-compat.h
new file mode 100644
index 0000000..a7f1ca1
--- /dev/null
+++ b/libevent-compat.h
@@ -0,0 +1,11 @@
+#ifndef UUID_FC148CFA_5ECC_488E_8A62_CD39406C9F1E
+#define UUID_FC148CFA_5ECC_488E_8A62_CD39406C9F1E
+
+/* evutil_socket_t is macros in libevent-2.0, not typedef, libevent-1.4 is
+ * still supported because of Ubuntu 10.04 LTS */
+#ifndef evutil_socket_t
+#   warning Using hardcoded value for evutil_socket_t as libevent headers do not define it.
+#   define evutil_socket_t int
+#endif
+
+#endif // FC148CFA_5ECC_488E_8A62_CD39406C9F1E
diff --git a/redsocks.c b/redsocks.c
index ba5eab2..878576f 100644
--- a/redsocks.c
+++ b/redsocks.c
@@ -33,6 +33,7 @@
 #include "base.h"
 #include "redsocks.h"
 #include "utils.h"
+#include "libevent-compat.h"
 
 
 #define REDSOCKS_RELAY_HALFBUFF  4096
diff --git a/redudp.c b/redudp.c
index 262af3e..05460dc 100644
--- a/redudp.c
+++ b/redudp.c
@@ -32,6 +32,7 @@
 #include "main.h"
 #include "redsocks.h"
 #include "redudp.h"
+#include "libc-compat.h"
 
 #define redudp_log_error(client, prio, msg...) \
 	redsocks_log_write_plain(__FILE__, __LINE__, __func__, 0, &(client)->clientaddr, get_destaddr(client), prio, ## msg)
diff --git a/utils.c b/utils.c
index 31c6894..7de3969 100644
--- a/utils.c
+++ b/utils.c
@@ -25,6 +25,7 @@
 #include "log.h"
 #include "utils.h"
 #include "redsocks.h" // for redsocks_close
+#include "libc-compat.h"
 
 int red_recv_udp_pkt(int fd, char *buf, size_t buflen, struct sockaddr_in *inaddr, struct sockaddr_in *toaddr)
 {
-- 
1.9.1

