SF Patch Tracker [ 2969188 ] 1.8.0: patch for FreeBSD compilation

Submitted By: Nick Leverton (leveret)
	Fix the order of header inclusion for FreeBSD.



git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@504 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2010-03-20 22:09:23 +00:00
parent 0c578f7962
commit cbbbb14e21
9 changed files with 88 additions and 51 deletions

View File

@ -2,6 +2,11 @@
Version 1.8.0
*******************************************************************************
2010-03-20 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* SF Patch Tracker [ 2969188 ] 1.8.0: patch for FreeBSD compilation
Submitted By: Nick Leverton (leveret)
Fix the order of header inclusion for FreeBSD.
2010-03-20 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Forward port of svn revision 502:
SF Patch Tracker [ 2836704 ] Search for nested serviceList (not

View File

@ -58,7 +58,12 @@
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
#else /* WIN32 */
#include <sys/param.h>
#include <sys/time.h> /* for gettimeofday() */
#if defined(__OSX__) || defined(__APPLE__) || defined(__NetBSD__)
#include <sys/resource.h> /* for setpriority() */
#endif
#endif

View File

@ -38,6 +38,9 @@
* \file
*/
#if ! defined(WIN32)
#include <sys/param.h>
#endif
#include "UpnpGlobal.h" /* For EXPORT_SPEC */
@ -55,7 +58,7 @@ extern "C" {
#endif
#ifdef __FreeBSD__
#if defined(BSD)
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#endif

View File

@ -35,6 +35,10 @@
*/
#if ! defined(WIN32)
#include <sys/param.h>
#endif
#include "ThreadPool.h"
@ -228,7 +232,7 @@ static void FreeThreadPoolJob( ThreadPool *tp, ThreadPoolJob *tpj )
* Sets the scheduling policy of the current process.
* Internal only.
* Parameters:
* PolocyType in
* PolicyType in
* Returns:
* 0 on success, nonzero on failure
* Returns result of GetLastError() on failure.
@ -239,17 +243,19 @@ static int SetPolicyType( PolicyType in )
#ifdef __CYGWIN__
/* TODO not currently working... */
return 0;
#elif defined(__OSX__) || defined(__APPLE__)
#elif defined(__OSX__) || defined(__APPLE__) || defined(__NetBSD__)
setpriority(PRIO_PROCESS, 0, 0);
return 0;
#elif defined(WIN32)
return sched_setscheduler(0, in);
#elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0
struct sched_param current;
int sched_result;
sched_getparam(0, &current);
current.sched_priority = DEFAULT_SCHED_PARAM;
return sched_setscheduler( 0, in, &current );
sched_result = sched_setscheduler(0, in, &current);
return (-1 != sched_result || EPERM == errno) ? 0 : -1;
#else
return 0;
#endif
@ -278,6 +284,7 @@ static int SetPriority( ThreadPriority priority )
int actPriority = 0;
int midPriority = 0;
struct sched_param newPriority;
int sched_result;
pthread_getschedparam( ithread_self(), &currentPolicy, &newPriority );
minPriority = sched_get_priority_min( currentPolicy );
@ -299,7 +306,8 @@ static int SetPriority( ThreadPriority priority )
newPriority.sched_priority = actPriority;
return pthread_setschedparam(ithread_self(), currentPolicy, &newPriority );
sched_result = pthread_setschedparam(ithread_self(), currentPolicy, &newPriority);
return (0 == sched_result || EPERM == errno) ? 0 : -1;
#else
return 0;
#endif
@ -399,7 +407,7 @@ static void SetSeed()
gettimeofday(&t, NULL);
#if defined(WIN32)
srand( ( unsigned int )t.tv_usec + (unsigned int)ithread_get_current_thread_id().p );
#elif defined(__FreeBSD__) || defined(__OSX__) || defined(__APPLE__)
#elif defined(BSD) || defined(__OSX__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
srand( ( unsigned int )t.tv_usec + (unsigned int)ithread_get_current_thread_id() );
#elif defined(__linux__) || defined(__sun) || defined(__CYGWIN__) || defined(__GLIBC__)
srand( ( unsigned int )t.tv_usec + ithread_get_current_thread_id() );
@ -1525,11 +1533,8 @@ void ThreadPoolPrintStats(ThreadPoolStats *stats)
return;
}
#ifdef __FreeBSD__
printf("ThreadPoolStats at Time: %d\n", StatsTime(NULL));
#else /* __FreeBSD__ */
printf("ThreadPoolStats at Time: %ld\n", StatsTime(NULL));
#endif /* __FreeBSD__ */
/* some OSses time_t length may depending on platform, promote it to long for safety */
printf("ThreadPoolStats at Time: %ld\n", (long)StatsTime(NULL));
printf("High Jobs pending: %d\n", stats->currentJobsHQ);
printf("Med Jobs Pending: %d\n", stats->currentJobsMQ);
printf("Low Jobs Pending: %d\n", stats->currentJobsLQ);

View File

@ -15,6 +15,13 @@
#include <winsock2.h>
#include <Ws2tcpip.h>
#else
#include <sys/param.h>
#if (defined(BSD) && BSD >= 199306) || defined (__FreeBSD_kernel__)
#include <ifaddrs.h>
/* Do not move or remove the include below for "sys/socket"!
* Will break FreeBSD builds. */
#include <sys/socket.h>
#endif
#include <netinet/in.h>
#endif

View File

@ -50,6 +50,17 @@
#ifdef WIN32
/* Do not include these files */
#else
#include <sys/param.h>
#if defined(_sun)
#include <fcntl.h>
#include <sys/sockio.h>
#elif defined(BSD) && BSD >= 199306
#include <ifaddrs.h>
/* Do not move or remove the include below for "sys/socket"!
* Will break FreeBSD builds. */
#include <sys/socket.h>
#endif
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
@ -58,17 +69,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <unistd.h>
#if defined(_sun)
#include <sys/sockio.h>
#include <fcntl.h>
#elif defined(BSD) && BSD >= 199306
#include <ifaddrs.h>
#endif
#endif
@ -2961,7 +2962,7 @@ int UpnpGetIfInfo(const char *IfName)
inet_ntop(AF_INET, &v4_addr, gIF_IPV4, sizeof(gIF_IPV4));
inet_ntop(AF_INET6, &v6_addr, gIF_IPV6, sizeof(gIF_IPV6));
#elif (defined(BSD) && BSD >= 199306)
#elif (defined(BSD) && BSD >= 199306) || defined(__FreeBSD_kernel__)
struct ifaddrs *ifap, *ifa;
struct in_addr v4_addr;
struct in6_addr v6_addr;
@ -3478,7 +3479,7 @@ int getlocalhostname(char *out, const int out_len)
h = gethostbyname(out);
if (h != NULL) {
memcpy(&LocalAddr.sin_addr, h->h_addr_list[0], 4);
p = inet_ntop(AF_INET, &LocalAddr.sin_addr, tempstr, 16);
p = inet_ntop(AF_INET, &LocalAddr.sin_addr, tempstr, sizeof(tempstr));
if (p) {
strncpy(out, p, out_len);
} else {
@ -3492,9 +3493,8 @@ int getlocalhostname(char *out, const int out_len)
ret = UPNP_E_INIT;
}
#elif (defined(BSD) && BSD >= 199306)
#elif (defined(BSD) && BSD >= 199306) || defined(__FreeBSD_kernel__)
struct ifaddrs *ifap, *ifa;
char tempstr[16];
if (getifaddrs(&ifap) != 0) {
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
@ -3517,7 +3517,9 @@ int getlocalhostname(char *out, const int out_len)
htonl(INADDR_LOOPBACK)) {
continue;
}
p = inet_ntop(AF_INET, &LocalAddr.sin_addr, tempstr, 16);
p = inet_ntop(AF_INET,
&((struct sockaddr_in *)(ifa->ifa_addr))->sin_addr,
tempstr, sizeof(tempstr));
if (p) {
strncpy(out, p, out_len);
} else {
@ -3596,7 +3598,7 @@ int getlocalhostname(char *out, const int out_len)
}
close(LocalSock);
p = inet_ntop(AF_INET, &LocalAddr.sin_addr, tempstr, 16);
p = inet_ntop(AF_INET, &LocalAddr.sin_addr, tempstr, sizeof(tempstr));
if (p) {
strncpy(out, p, out_len);
} else {

View File

@ -668,9 +668,10 @@ static int get_miniserver_sockets(
}
} else {
if (listenfd4 != INVALID_SOCKET) {
unsigned short orig_listen_port4 = listen_port4;
do {
serverAddr4->sin_port = htons(listen_port4++);
sockError = bind(listenfd4, (struct sockaddr *)&__ss_v4, sizeof(__ss_v4));
sockError = bind(listenfd4, (struct sockaddr *)serverAddr4, sizeof(*serverAddr4));
if (sockError == -1) {
#ifdef WIN32
errCode = WSAGetLastError();
@ -683,7 +684,7 @@ static int get_miniserver_sockets(
} else {
errCode = 0;
}
} while ( errCode != 0 );
} while ( errCode != 0 && (listen_port4 >= orig_listen_port4) );
if (sockError == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
@ -699,9 +700,10 @@ static int get_miniserver_sockets(
}
if (listenfd6 != INVALID_SOCKET) {
unsigned short orig_listen_port6 = listen_port6;
do {
serverAddr6->sin6_port = htons(listen_port6++);
sockError = bind(listenfd6, (struct sockaddr *)&__ss_v6, sizeof(__ss_v6));
sockError = bind(listenfd6, (struct sockaddr *)serverAddr6, sizeof(*serverAddr6));
if (sockError == -1) {
#ifdef WIN32
errCode = WSAGetLastError();
@ -714,7 +716,7 @@ static int get_miniserver_sockets(
} else {
errCode = 0;
}
} while (errCode != 0);
} while (errCode != 0 && (listen_port6 >= orig_listen_port6));
if (sockError == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);

View File

@ -38,6 +38,10 @@
* \file
*/
#if !defined(WIN32)
#include <sys/param.h>
#endif
#include "UpnpGlobal.h" /* for */
#include "UpnpInet.h"
@ -48,6 +52,9 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#if defined(BSD)
#include <sys/socket.h>
#endif
#include <sys/types.h>
#include <time.h>

View File

@ -29,6 +29,9 @@
*
**************************************************************************/
#if !defined(WIN32)
#include <sys/param.h>
#endif
#include "config.h"
@ -1061,7 +1064,7 @@ int create_ssdp_sock_v4( SOCKET* ssdpSock )
return UPNP_E_SOCKET_ERROR;
}
#if defined(__FreeBSD__) || defined(__OSX__) || defined(__APPLE__)
#if defined(BSD) || defined(__OSX__) || defined(__APPLE__)
onOff = 1;
ret = setsockopt( *ssdpSock, SOL_SOCKET, SO_REUSEPORT,
(char *)&onOff, sizeof(onOff) );
@ -1074,14 +1077,13 @@ int create_ssdp_sock_v4( SOCKET* ssdpSock )
return UPNP_E_SOCKET_ERROR;
}
#endif /* __FreeBSD__ */
#endif /* BSD */
memset( &__ss, 0, sizeof( __ss ) );
ssdpAddr4->sin_family = AF_INET;
// ssdpAddr.sin_addr.s_addr = inet_addr(gIF_IPV4);
ssdpAddr4->sin_addr.s_addr = htonl( INADDR_ANY );
ssdpAddr4->sin_port = htons( SSDP_PORT );
ret = bind( *ssdpSock, (struct sockaddr *)&__ss, sizeof(__ss) );
ret = bind( *ssdpSock, (struct sockaddr *)ssdpAddr4, sizeof(*ssdpAddr4) );
if ( ret == -1 ) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
@ -1187,7 +1189,7 @@ int create_ssdp_sock_v6( SOCKET* ssdpSock )
return UPNP_E_SOCKET_ERROR;
}
#if defined(__FreeBSD__) || defined(__OSX__) || defined(__APPLE__)
#if defined(BSD) || defined(__OSX__) || defined(__APPLE__)
onOff = 1;
ret = setsockopt( *ssdpSock, SOL_SOCKET, SO_REUSEPORT,
(char*)&onOff, sizeof (onOff) );
@ -1200,15 +1202,14 @@ int create_ssdp_sock_v6( SOCKET* ssdpSock )
return UPNP_E_SOCKET_ERROR;
}
#endif /* __FreeBSD__ */
#endif /* BSD */
memset( &__ss, 0, sizeof( __ss ) );
ssdpAddr6->sin6_family = AF_INET6;
ssdpAddr6->sin6_addr = in6addr_any;
//inet_pton( AF_INET6, gIF_IPV6, &ssdpAddr6->sin6_addr );
ssdpAddr6->sin6_scope_id = gIF_INDEX;
ssdpAddr6->sin6_port = htons( SSDP_PORT );
ret = bind( *ssdpSock, (struct sockaddr *)&__ss, sizeof(__ss) );
ret = bind( *ssdpSock, (struct sockaddr *)ssdpAddr6, sizeof(*ssdpAddr6) );
if ( ret == -1 ) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__,