diff --git a/apps/app_intercom.c b/apps/app_intercom.c
index 6312bcc69309cd72cc89576fc2e2019aa257dcaa..bf139e0b9a9eb4062dd3724bcac927b33cbcb9ed 100755
--- a/apps/app_intercom.c
+++ b/apps/app_intercom.c
@@ -26,7 +26,11 @@
 #include <stdlib.h>
 #include <pthread.h>
 #include <sys/time.h>
+#ifdef __linux__
 #include <linux/soundcard.h>
+#else
+#include <soundcard.h>
+#endif
 #include <netinet/in.h>
 
 #define DEV_DSP "/dev/dsp"
diff --git a/channels/chan_oss.c b/channels/chan_oss.c
index 9f942e272cbf33d991694a8dc69188b640021563..ffbbbdef8c499da6539012b965fe9f5015e95cf5 100755
--- a/channels/chan_oss.c
+++ b/channels/chan_oss.c
@@ -33,7 +33,11 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#ifdef __linux
 #include <linux/soundcard.h>
+#else
+#include <soundcard.h>
+#endif
 #include "busy.h"
 #include "ringtone.h"
 #include "ring10.h"
diff --git a/formats/format_g729.c b/formats/format_g729.c
index 5d4aeab4acd67358a04058e5de00186d4c80e997..ee6f6ab508ce5512f1789fbc069372bb0b83e8ae 100755
--- a/formats/format_g729.c
+++ b/formats/format_g729.c
@@ -25,7 +25,11 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#ifdef __linux__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
 
 /* Some Ideas for this code came from makeg729e.c by Jeffery Chilton */
 
diff --git a/formats/format_gsm.c b/formats/format_gsm.c
index 87bd91bc44d001e02a4ae8e7f02920fa70954b79..5f7b74b00fea78c744aa5bd6d07b4bd4b6efaa4d 100755
--- a/formats/format_gsm.c
+++ b/formats/format_gsm.c
@@ -25,7 +25,11 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#ifdef __linux__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
 
 /* Some Ideas for this code came from makegsme.c by Jeffery Chilton */
 
diff --git a/formats/format_jpeg.c b/formats/format_jpeg.c
index 2d9b3e47313296877f8d84f8efd03cb73def83c2..7e646f89489dc419623f3716a14b4bc48e24c5d9 100755
--- a/formats/format_jpeg.c
+++ b/formats/format_jpeg.c
@@ -26,8 +26,11 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#ifdef __linux__
 #include <endian.h>
-
+#else
+#include <machine/endian.h>
+#endif
 
 
 static char *desc = "JPEG (Joint Picture Experts Group) Image Format";
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index 28daed68fa42a4cedb8d10c31e70bcfb85ef8a99..14931dfdf3965ddffbc96e3099c983ce9602ecb0 100755
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -25,7 +25,11 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#ifdef __linux__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
 
 #define BUF_SIZE 160		/* 160 samples */
 
diff --git a/formats/format_pcm_alaw.c b/formats/format_pcm_alaw.c
index 129e292b3e0084d3985e711b390e29409533f6bf..9a4f6658665cfa46835344555adafc2516c30329 100755
--- a/formats/format_pcm_alaw.c
+++ b/formats/format_pcm_alaw.c
@@ -27,7 +27,11 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#ifdef __linux__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
 
 #define BUF_SIZE 160		/* 160 samples */
 
diff --git a/formats/format_vox.c b/formats/format_vox.c
index 0a4c7c025f757b9de8594624d8e578b6e29eaab0..3848f47c05fb8ec5762671722e926b57c23131e0 100755
--- a/formats/format_vox.c
+++ b/formats/format_vox.c
@@ -25,7 +25,11 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#ifdef __linux__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
 
 #define BUF_SIZE 80		/* 160 samples */
 
diff --git a/formats/format_wav.c b/formats/format_wav.c
index 876714ad794f76ad0f487d6b972d37401a5edd2c..2dc547119656dfb2ef0adb5ce387f58d2b05b3ae 100755
--- a/formats/format_wav.c
+++ b/formats/format_wav.c
@@ -25,7 +25,11 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#ifdef __linux__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
 
 /* Some Ideas for this code came from makewave.c by Jeffery Chilton */
 
diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c
index 527a4014a5633a9ed05188d7f81cd8004a86068e..fc6323b670db2cb4b47206409e4da8d37f72fe40 100755
--- a/formats/format_wav_gsm.c
+++ b/formats/format_wav_gsm.c
@@ -25,7 +25,11 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#ifdef __linux__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
 #include "msgsm.h"
 
 /* Some Ideas for this code came from makewave.c by Jeffery Chilton */
diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h
index c23ed71ceccc467be59a9212b3cc3e500d3676f6..e89891bb1c4d035a0e0db256626e6ad8fb12f59b 100755
--- a/include/asterisk/frame.h
+++ b/include/asterisk/frame.h
@@ -20,7 +20,11 @@
 extern "C" {
 #endif
 
+#ifdef __linux__
 #include <endian.h>
+#else
+#include <machine/endian.h>
+#endif
 #include <sys/types.h>
 
 //! Data structure associated with a single frame of data