diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/BonDriver_LinuxPT.cpp BonDriverProxy_FreeBSD/BonDriver_LinuxPT.cpp
*** BonDriverProxy_Linux/BonDriver_LinuxPT.cpp	2018-02-24 23:36:20.070226000 +0900
--- BonDriverProxy_FreeBSD/BonDriver_LinuxPT.cpp	2018-02-24 23:34:46.489443000 +0900
***************
*** 6,11 ****
--- 6,16 ----
  static char g_strSpace[32];
  static stChannel g_stChannels[2][MAX_CH];
  static char g_Device[32];
+ #if defined(__FreeBSD__)
+ static char g_PTxLNB[]     = "dev.ptx.?.lnb";
+ static char g_PTxFreq[]    = "dev.ptx.?.??.freq";
+ static char g_PTxSignal[]  = "dev.ptx.?.??.signal";
+ #endif
  static int g_Type;		// 0 : ISDB_S / 1 : ISDB_T
  static BOOL g_MustStop;
  static BOOL g_UseLNB;
***************
*** 114,119 ****
--- 119,139 ----
  			::strncpy(g_Device, p, sizeof(g_Device) - 1);
  			g_Device[sizeof(g_Device) - 1] = '\0';
  			g_MustStop = FALSE;
+ #if defined(__FreeBSD__)
+ 			struct stat st;
+ 			if (::strncmp(g_Device, "/dev/ptx", 8) == 0
+ 			&&  g_Device[8] >= '0' && g_Device[8] <= '9'
+ 			&&  g_Device[9] == '.'
+ 			&&  g_Device[10] >= 's' && g_Device[10] <= 't'
+ 			&&  g_Device[11] >= '0' && g_Device[11] <= '1'
+ 			&&  g_Device[12] == '\0'
+ 			&&  stat(g_Device, &st) == 0) {
+ 				g_Type = (g_Device[10] == 's')? 0 : 1;
+ 				g_PTxLNB[8] = g_PTxSignal[8]  = g_PTxFreq[8]  = g_Device[8];
+ 				              g_PTxSignal[10] = g_PTxFreq[10] = g_Device[10];
+ 				              g_PTxSignal[11] = g_PTxFreq[11] = g_Device[11];
+ 			}
+ #else
  			if ((p = ::strstr(g_Device, "video")) != NULL)	// PT
  				g_Type = (::atoi(p + 5) / 2) % 2;
  			else
***************
*** 134,139 ****
--- 154,160 ----
  				}
  				cBonDriverLinuxPT::m_sbPT = FALSE;
  			}
+ #endif
  			if (g_Type == 0)
  				p = (char *)"BS/CS110";
  			else
***************
*** 360,367 ****
--- 381,394 ----
  		return FALSE;
  	if (m_sbPT == FALSE)
  		PLEX::InitPlexTuner(m_fd);
+ #if defined(__FreeBSD__)
+ 	int lnb = 2;
+ 	if (g_UseLNB && (g_Type == 0) && (::sysctlbyname(g_PTxLNB, NULL, NULL, &lnb, sizeof(lnb)) < 0))
+ 		::fprintf(stderr, "LNB ON failed: %s\n", g_Device);
+ #else
  	if (g_UseLNB && (g_Type == 0) && (::ioctl(m_fd, LNB_ENABLE, 2) < 0))
  		::fprintf(stderr, "LNB ON failed: %s\n", g_Device);
+ #endif
  	m_bTuner = TRUE;
  	return TRUE;
  }
***************
*** 375,384 ****
--- 402,419 ----
  			m_bStopTsRead = TRUE;
  			::pthread_join(m_hTsRead, NULL);
  			m_hTsRead = 0;
+ #if !defined(__FreeBSD__)
  			::ioctl(m_fd, STOP_REC, 0);
+ #endif
  		}
+ #if defined(__FreeBSD__)
+ 		int lnb = 0;
+ 		if (g_UseLNB && (g_Type == 0) && (::sysctlbyname(g_PTxLNB, NULL, NULL, &lnb, sizeof(lnb)) < 0))
+ 			::fprintf(stderr, "LNB OFF failed: %s\n", g_Device);
+ #else
  		if (g_UseLNB && (g_Type == 0) && (::ioctl(m_fd, LNB_DISABLE, 0) < 0))
  			::fprintf(stderr, "LNB OFF failed: %s\n", g_Device);
+ #endif
  		::close(m_fd);
  		m_bTuner = FALSE;
  		m_fd = -1;
***************
*** 537,549 ****
--- 572,595 ----
  			m_bStopTsRead = TRUE;
  			::pthread_join(m_hTsRead, NULL);
  			m_hTsRead = 0;
+ #if !defined(__FreeBSD__)
  			::ioctl(m_fd, STOP_REC, 0);
+ #endif
+ 		}
+ #if defined(__FreeBSD__)
+ 		int freq = g_stChannels[g_Type][dwChannel].freq.frequencyno | (g_stChannels[g_Type][dwChannel].freq.slot << 16);
+ 		if (::sysctlbyname(g_PTxFreq, NULL, NULL, &freq, sizeof(freq)) < 0)
+ 		{
+ 			::fprintf(stderr, "SetChannel() sysctl(%s) error: %s\n", g_PTxFreq, g_Device);
+ 			goto err;
  		}
+ #else
  		if (::ioctl(m_fd, SET_CHANNEL, &(g_stChannels[g_Type][dwChannel].freq)) < 0)
  		{
  			::fprintf(stderr, "SetChannel() ioctl(SET_CHANNEL) error: %s\n", g_Device);
  			goto err;
  		}
+ #endif
  	}
  
  	{
***************
*** 605,616 ****
--- 651,664 ----
  	ts.tv_sec = 0;
  	ts.tv_nsec = WAIT_TIME * 1000 * 1000;
  
+ #if !defined(__FreeBSD__)
  	if (::ioctl(pLinuxPT->m_fd, START_REC, 0) < 0)
  	{
  		::fprintf(stderr, "TsReader() ioctl(START_REC) error: %s\n", g_Device);
  		ret = 302;
  		goto end;
  	}
+ #endif
  
  	// TS読み込みループ
  	pTsBuf = new BYTE[TS_BUFSIZE];
***************
*** 624,632 ****
--- 672,687 ----
  		if (((now - before) >= 1000) || pLinuxPT->m_bUpdateCNR)
  		{
  			float f = 0;
+ #if defined(__FreeBSD__)
+ 			int signal = 0;
+ 			size_t siglen = sizeof(signal);
+ 			if (::sysctlbyname(g_PTxSignal, &signal, &siglen, NULL, 0) < 0)
+ 				::fprintf(stderr, "TsReader() sysctl(%s) error: %s\n", g_PTxSignal, g_Device);
+ #else
  			int signal;
  			if (::ioctl(pLinuxPT->m_fd, GET_SIGNAL_STRENGTH, &signal) < 0)
  				::fprintf(stderr, "TsReader() ioctl(GET_SIGNAL_STRENGTH) error: %s\n", g_Device);
+ #endif
  			else
  			{
  				if (g_Type == 0)
***************
*** 669,675 ****
--- 724,732 ----
  		pos += len;
  	}
  	delete[] pTsBuf;
+ #if !defined(__FreeBSD__)
  end:
+ #endif
  	if (g_UseServiceID)
  	{
  		pLinuxPT->m_StopTsSplit.Set();
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/BonDriver_LinuxPT.h BonDriverProxy_FreeBSD/BonDriver_LinuxPT.h
*** BonDriverProxy_Linux/BonDriver_LinuxPT.h	2018-02-24 23:36:20.070304000 +0900
--- BonDriverProxy_FreeBSD/BonDriver_LinuxPT.h	2018-02-24 23:34:46.489650000 +0900
***************
*** 8,13 ****
--- 8,16 ----
  #include <math.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+ #if defined(__FreeBSD__)
+ #include <sys/sysctl.h>
+ #endif
  #include <sys/time.h>
  #include <sys/ioctl.h>
  #include <fcntl.h>
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/BonDriver_Proxy.h BonDriverProxy_FreeBSD/BonDriver_Proxy.h
*** BonDriverProxy_Linux/BonDriver_Proxy.h	2018-02-24 23:36:20.071037000 +0900
--- BonDriverProxy_FreeBSD/BonDriver_Proxy.h	2018-02-23 20:10:31.122235000 +0900
***************
*** 6,11 ****
--- 6,14 ----
  #include <string.h>
  #include <sys/time.h>
  #include <sys/socket.h>
+ #if defined(__FreeBSD__)
+ #include <netinet/in.h>
+ #endif
  #include <sys/ioctl.h>
  #include <netdb.h>
  #include <arpa/inet.h>
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/BonDriverProxy.h BonDriverProxy_FreeBSD/BonDriverProxy.h
*** BonDriverProxy_Linux/BonDriverProxy.h	2018-02-24 23:36:20.067556000 +0900
--- BonDriverProxy_FreeBSD/BonDriverProxy.h	2018-02-23 19:46:11.832856000 +0900
***************
*** 15,20 ****
--- 15,23 ----
  #include <errno.h>
  #include <sys/time.h>
  #include <sys/socket.h>
+ #if defined(__FreeBSD__)
+ #include <netinet/in.h>
+ #endif
  #include <netdb.h>
  #include <arpa/inet.h>
  #include <dlfcn.h>
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/BonDriverProxyEx.h BonDriverProxy_FreeBSD/BonDriverProxyEx.h
*** BonDriverProxy_Linux/BonDriverProxyEx.h	2018-02-24 23:36:20.068444000 +0900
--- BonDriverProxy_FreeBSD/BonDriverProxyEx.h	2018-02-23 20:08:56.177051000 +0900
***************
*** 16,21 ****
--- 16,24 ----
  #include <time.h>
  #include <sys/time.h>
  #include <sys/socket.h>
+ #if defined(__FreeBSD__)
+ #include <netinet/in.h>
+ #endif
  #include <netdb.h>
  #include <arpa/inet.h>
  #include <dlfcn.h>
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/Makefile BonDriverProxy_FreeBSD/Makefile
*** BonDriverProxy_Linux/Makefile	2018-02-24 23:36:20.072114000 +0900
--- BonDriverProxy_FreeBSD/Makefile	2018-02-23 20:31:37.992050000 +0900
***************
*** 4,15 ****
  
  SRCDIR = .
  LDFLAGS =
! LIBS = -ldl
  SRCS = BonDriverProxy.cpp BonDriverProxyEx.cpp sample.cpp
  SOSRCS = BonDriver_Proxy.cpp BonDriver_Splitter.cpp
  ifneq ($(UNAME), Darwin)
  	SOSRCS += BonDriver_LinuxPT.cpp BonDriver_DVB.cpp
  endif
  
  ifeq ($(UNAME), Darwin)
  all: server serverex client sample util
--- 4,23 ----
  
  SRCDIR = .
  LDFLAGS =
! ifeq ($(UNAME), FreeBSD)
! LIBS = -lpthread
! else
! LIBS = -lld
! endif
  SRCS = BonDriverProxy.cpp BonDriverProxyEx.cpp sample.cpp
  SOSRCS = BonDriver_Proxy.cpp BonDriver_Splitter.cpp
  ifneq ($(UNAME), Darwin)
+ ifeq ($(UNAME), FreeBSD)
+ 	SOSRCS += BonDriver_LinuxPT.cpp
+ else
  	SOSRCS += BonDriver_LinuxPT.cpp BonDriver_DVB.cpp
  endif
+ endif
  
  ifeq ($(UNAME), Darwin)
  all: server serverex client sample util
***************
*** 19,25 ****
--- 27,37 ----
  server: BonDriverProxy
  serverex: BonDriverProxyEx
  client: BonDriver_Proxy.$(EXT)
+ ifeq ($(UNAME),FreeBSD)
+ driver: BonDriver_LinuxPT.$(EXT) BonDriver_Splitter.$(EXT)
+ else
  driver: BonDriver_LinuxPT.$(EXT) BonDriver_DVB.$(EXT) BonDriver_Splitter.$(EXT)
+ endif
  
  BonDriverProxy: BonDriverProxy.o
  	$(CXX) $(CXXFLAGS) -rdynamic -o $@ $^ $(LIBS)
***************
*** 43,49 ****
  	$(CXX) $(CXXFLAGS) -rdynamic -o $@ $^ $(LIBS)
  
  util:
! 	@cd util; make
  
  %.$(EXT).o: %.cpp .depend
  	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ADDCOMPILEFLAGS) -fPIC -c -o $@ $<
--- 55,61 ----
  	$(CXX) $(CXXFLAGS) -rdynamic -o $@ $^ $(LIBS)
  
  util:
! 	@cd util; $(MAKE)
  
  %.$(EXT).o: %.cpp .depend
  	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ADDCOMPILEFLAGS) -fPIC -c -o $@ $<
***************
*** 54,60 ****
  clean:
  	$(RM) *.o *.so *.dylib BonDriverProxy BonDriverProxyEx sample .depend
  	$(RM) -r *.dSYM
! 	@cd util; make clean
  distclean: clean
  
  dep: .depend
--- 66,72 ----
  clean:
  	$(RM) *.o *.so *.dylib BonDriverProxy BonDriverProxyEx sample .depend
  	$(RM) -r *.dSYM
! 	@cd util; $(MAKE) clean
  distclean: clean
  
  dep: .depend
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/Makefile.in BonDriverProxy_FreeBSD/Makefile.in
*** BonDriverProxy_Linux/Makefile.in	2018-02-24 23:36:20.072205000 +0900
--- BonDriverProxy_FreeBSD/Makefile.in	2018-02-22 20:56:48.062622000 +0900
***************
*** 8,13 ****
--- 8,23 ----
  	EXT = dylib
  	ADDCOMPILEFLAGS = -pthread
  else
+ 
+ ifeq ($(UNAME), FreeBSD)
+ 	CXX = c++
+ 	CPPFLAGS =
+ 	CXXFLAGS = -Wall -pthread
+ 	CFLAGS = -Wall
+ 	SOFLAGS = -shared
+ 	EXT = so
+ 	ADDCOMPILEFLAGS =
+ else
  	CXX = g++
  	CPPFLAGS = -DLINUX
  	CXXFLAGS = -Wall -pthread
***************
*** 17,22 ****
--- 27,34 ----
  	ADDCOMPILEFLAGS =
  endif
  
+ endif
+ 
  ifeq ($(BUILD), DEBUG)
  	CPPFLAGS += -DDEBUG
  	CXXFLAGS += -g -O0
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/util/cinfo.cpp BonDriverProxy_FreeBSD/util/cinfo.cpp
*** BonDriverProxy_Linux/util/cinfo.cpp	2018-02-24 23:36:20.073428000 +0900
--- BonDriverProxy_FreeBSD/util/cinfo.cpp	2018-02-23 20:15:56.072957000 +0900
***************
*** 3,8 ****
--- 3,11 ----
  #include <stdlib.h>
  #include <string.h>
  #include <sys/socket.h>
+ #if defined(__FreeBSD__)
+ #include <netinet/in.h>
+ #endif
  #include <sys/ioctl.h>
  #include <netdb.h>
  #include <arpa/inet.h>
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/util/Makefile BonDriverProxy_FreeBSD/util/Makefile
*** BonDriverProxy_Linux/util/Makefile	2018-02-24 23:36:20.073223000 +0900
--- BonDriverProxy_FreeBSD/util/Makefile	2018-02-22 21:00:22.131755000 +0900
***************
*** 4,10 ****
--- 4,12 ----
  
  SRCDIR = .
  LDFLAGS =
+ ifneq ($(UNAME), FreeBSD)
  LIBS = -ldl
+ endif
  ifeq ($(UNAME), Darwin)
  	LIBS += -liconv
  endif
diff -c -x .git -x .gitignore -r BonDriverProxy_Linux/util/udpsend.c BonDriverProxy_FreeBSD/util/udpsend.c
*** BonDriverProxy_Linux/util/udpsend.c	2018-02-24 23:36:20.074201000 +0900
--- BonDriverProxy_FreeBSD/util/udpsend.c	2018-02-23 20:16:42.845210000 +0900
***************
*** 7,12 ****
--- 7,15 ----
  #include <stdlib.h>
  #include <string.h>
  #include <sys/socket.h>
+ #if defined(__FreeBSD__)
+ #include <netinet/in.h>
+ #endif
  #include <netdb.h>
  #include <arpa/inet.h>
  
