From 98533cbccc4795c42949b6228024a16f2eb14a76 Mon Sep 17 00:00:00 2001
From: James Golovich <james@gnuinter.net>
Date: Mon, 19 Apr 2004 08:11:51 +0000
Subject: [PATCH] OpenBSD portability enhancements (bug 1002)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2708 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 Makefile                 |  4 ++++
 aesopt.h                 |  5 ++++-
 channels/Makefile        | 21 +++++++++++++++++----
 channels/chan_h323.c     |  7 ++++++-
 channels/h323/Makefile   |  8 +++++++-
 include/asterisk/frame.h |  3 +++
 md5.c                    |  6 +++++-
 7 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index de525120e0..cf131e732f 100755
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,10 @@ PROC=$(shell uname -m)
 else
 ifeq (${OSARCH},FreeBSD)
 PROC=$(shell uname -m)
+else
+ifeq (${OSARCH},OpenBSD)
+PROC=$(shell uname -m)
+endif
 endif
 endif
 # Pentium Pro Optimize
diff --git a/aesopt.h b/aesopt.h
index 799c8a694d..936ccd4ca7 100755
--- a/aesopt.h
+++ b/aesopt.h
@@ -148,7 +148,10 @@
 
 /*  PLATFORM SPECIFIC INCLUDES */
 
-#if defined( __FreeBSD__ ) || defined( __OpenBSD__ )
+#if defined( __OpenBSD__ )
+#  include <machine/types.h>
+#  include <sys/endian.h>
+#elif defined( __FreeBSD__ )
 #  include <sys/types.h>
 #  include <sys/endian.h>
 #elif defined( BSD ) && ( BSD >= 199103 )
diff --git a/channels/Makefile b/channels/Makefile
index fea205ebfc..66964ffcc6 100755
--- a/channels/Makefile
+++ b/channels/Makefile
@@ -33,6 +33,19 @@ CHANNEL_LIBS=chan_modem.so chan_sip.so \
 #
 #CHANNEL_LIBS+=chan_vofr
 
+ifeq (${OSARCH},OpenBSD)
+MYSQLLIB=-L/usr/local/lib/mysql -lmysqlclient
+CFLAGS+=-I/usr/local/include
+PTLIB=-lpt_OpenBSD_x86_r
+H323LIB=-lh323_OpenBSD_x86_r
+CHANH323LIB=-L/usr/local/lib
+else
+MYSQLLIB=-L/usr/lib/mysql -lmysqlclient
+PTLIB=-lpt_linux_x86_r
+H323LIB=-lh323_linux_x86_r
+CHANH323LIB=-ldl
+endif
+
 ifneq (${OSARCH},Darwin)
 CHANNEL_LIBS+=chan_oss.so
 endif
@@ -117,14 +130,14 @@ endif
 
 chan_iax2.so: chan_iax2.o iax2-parser.o
 ifeq ($(USE_MYSQL_FRIENDS),1)
-	$(CC) $(SOLINK) -o $@ chan_iax2.o iax2-parser.o -L/usr/lib/mysql -lmysqlclient -lz
+	$(CC) $(SOLINK) -o $@ chan_iax2.o iax2-parser.o $(MYSQLLIB) -lz
 else
 	$(CC) $(SOLINK) -o $@ chan_iax2.o iax2-parser.o
 endif
 
 chan_iax.so: chan_iax.o
 ifeq ($(USE_MYSQL_FRIENDS),1)
-	$(CC) $(SOLINK) -o $@ chan_iax.o -L/usr/lib/mysql -lmysqlclient -lz
+	$(CC) $(SOLINK) -o $@ chan_iax.o $(MYSQLLIB) -lz
 else
 	$(CC) $(SOLINK) -o $@ chan_iax.o
 endif
@@ -137,7 +150,7 @@ chan_zap.so: chan_zap.o
 
 chan_sip.so: chan_sip.o
 ifeq ($(USE_MYSQL_FRIENDS),1)
-	$(CC) $(SOLINK) -o $@ chan_sip.o -L/usr/lib/mysql -lmysqlclient -lz
+	$(CC) $(SOLINK) -o $@ chan_sip.o $(MYSQLLIB) -lz
 else
 	$(CC) $(SOLINK) -o $@ chan_sip.o
 endif
@@ -158,7 +171,7 @@ chan_vpb.so: chan_vpb.o
 	 $(CXX) $(SOLINK) -o $@ $< -lvpb -lpthread -lm -ldl
 
 chan_h323.so: chan_h323.o h323/libchanh323.a
-	$(CC) $(SOLINK) -o $@ $< h323/libchanh323.a -L$(PWLIBDIR)/lib  -lpt_linux_x86_r -L$(OPENH323DIR)/lib -lh323_linux_x86_r -L/usr/lib -lpthread -ldl -lcrypto -lssl -lexpat
+	$(CC) $(SOLINK) -o $@ $< h323/libchanh323.a $(CHANH323LIB) -L$(PWLIBDIR)/lib $(PTLIB) -L$(OPENH323DIR)/lib $(H323LIB) -L/usr/lib -lpthread -lcrypto -lssl -lexpat
 
 
 #chan_modem.so : chan_modem.o
diff --git a/channels/chan_h323.c b/channels/chan_h323.c
index b29f6977be..1dd16da4c1 100755
--- a/channels/chan_h323.c
+++ b/channels/chan_h323.c
@@ -55,7 +55,12 @@
 #include <netdb.h>
 #include <sys/signal.h>
 #include <netinet/ip.h>
-
+#ifdef __OpenBSD__
+#include <netinet/in_systm.h>
+#ifndef IPTOS_MINCOST
+#define IPTOS_MINCOST 0x02
+#endif
+#endif
 
 #include "h323/chan_h323.h"
 
diff --git a/channels/h323/Makefile b/channels/h323/Makefile
index cd796b1530..d07ae7c3b9 100755
--- a/channels/h323/Makefile
+++ b/channels/h323/Makefile
@@ -26,9 +26,15 @@ CFLAGS += -march=$(shell uname -m) -DPBYTE_ORDER=PLITTLE_ENDIAN
 #
 # Only change below if you know WTF your doing
 #
+OSARCH=$(shell uname -s)
 CFLAGS += -DNDEBUG -DDO_CRASH -DDEBUG_THREADS
 CFLAGS += -pipe -Wall -fPIC -Wmissing-prototypes -Wmissing-declarations 
-CFLAGS += -DP_LINUX  -D_REENTRANT -D_GNU_SOURCE
+CFLAGS += -D_REENTRANT -D_GNU_SOURCE
+ifeq (${OSARCH},OpenBSD)
+CFLAGS += -DP_OPENBSD=200311
+else
+CFLAGS += -DP_LINUX
+endif
 CFLAGS += -DP_HAS_SEMAPHORES -DP_SSL -DP_PTHREADS
 CFLAGS += -DPHAS_TEMPLATES -DPTRACING -DP_USE_PRAGMA
 CFLAGS += -I../../include
diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h
index c2409a8dae..0bec024bbe 100755
--- a/include/asterisk/frame.h
+++ b/include/asterisk/frame.h
@@ -30,6 +30,9 @@ extern "C" {
 #ifdef __linux__
 #include <endian.h>
 #elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
+#if defined(__OpenBSD__)
+#include <machine/types.h>
+#endif /* __OpenBSD__ */
 #include <machine/endian.h>
 #define __BYTE_ORDER BYTE_ORDER
 #define __LITTLE_ENDIAN LITTLE_ENDIAN
diff --git a/md5.c b/md5.c
index bdbb03ff75..abb277ac01 100755
--- a/md5.c
+++ b/md5.c
@@ -1,6 +1,10 @@
 /* MD5 checksum routines used for authentication.  Not covered by GPL, but
    in the public domain as per the copyright below */
-#if defined( __FreeBSD__ ) || defined( __OpenBSD__ )
+#if defined( __OpenBSD__ )
+#  include <machine/types.h>
+#  include <sys/endian.h>
+#elif defined( __FreeBSD__ )
+#  include <sys/types.h>
 #  include <sys/endian.h>
 #elif defined( BSD ) && ( BSD >= 199103 )
 #  include <machine/endian.h>
-- 
GitLab