2009-08-28 14:18:18 +00:00
|
|
|
/*
|
|
|
|
* uhub - A tiny ADC p2p connection hub
|
2012-10-02 13:49:27 +00:00
|
|
|
* Copyright (C) 2007-2012, Jan Vidar Krey
|
2009-08-28 14:18:18 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAVE_UHUB_SYSTEM_H
|
|
|
|
#define HAVE_UHUB_SYSTEM_H
|
|
|
|
|
2009-09-14 10:24:18 +00:00
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
|
2009-08-28 14:18:18 +00:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif
|
|
|
|
|
2011-12-09 13:24:21 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__)
|
2010-02-10 22:45:51 +00:00
|
|
|
#define BSD_LIKE
|
|
|
|
#endif
|
|
|
|
|
2011-01-02 01:39:25 +00:00
|
|
|
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER)
|
2009-08-28 14:18:18 +00:00
|
|
|
#ifndef WINSOCK
|
|
|
|
#define WINSOCK
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-01-24 23:20:59 +00:00
|
|
|
#if defined(__CYGWIN__) || defined(__MINGW32__)
|
|
|
|
#define HAVE_SSIZE_T
|
|
|
|
#define NEED_GETOPT
|
|
|
|
#endif
|
|
|
|
|
2009-08-28 14:18:18 +00:00
|
|
|
#ifdef WINSOCK
|
2011-02-05 16:11:23 +00:00
|
|
|
#ifndef FD_SETSIZE
|
|
|
|
#define FD_SETSIZE 4096
|
|
|
|
#endif
|
2009-08-28 14:18:18 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#else
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2010-01-28 00:35:09 +00:00
|
|
|
|
|
|
|
#ifndef __sun__
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
|
|
|
|
2009-08-28 14:18:18 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#if !defined(WIN32)
|
2012-05-10 21:24:42 +00:00
|
|
|
#include <inttypes.h>
|
2011-01-02 01:39:25 +00:00
|
|
|
#include <unistd.h>
|
2009-08-28 14:18:18 +00:00
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#define HAVE_STRNDUP
|
2010-05-30 21:33:06 +00:00
|
|
|
#define HAVE_DLOPEN
|
2011-01-02 01:39:25 +00:00
|
|
|
#define HAVE_GETOPT
|
|
|
|
#define HAVE_SSIZE_T
|
2010-05-30 21:33:06 +00:00
|
|
|
#include <dlfcn.h>
|
2010-01-28 00:29:34 +00:00
|
|
|
#ifndef __HAIKU__
|
2009-08-28 14:18:18 +00:00
|
|
|
#define HAVE_MEMMEM
|
2010-01-28 00:29:34 +00:00
|
|
|
#endif
|
2009-08-28 14:18:18 +00:00
|
|
|
#define HAVE_GETRLIMIT
|
|
|
|
#endif
|
|
|
|
|
2012-05-11 14:45:07 +00:00
|
|
|
/* printf support for size_t and uint64_t */
|
2009-08-28 14:18:18 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
#define PRINTF_SIZE_T "%Iu"
|
2012-05-11 14:45:07 +00:00
|
|
|
#define PRINTF_UINT64_T "%I64u"
|
2009-08-28 14:18:18 +00:00
|
|
|
#else
|
|
|
|
#define PRINTF_SIZE_T "%zu"
|
2012-05-11 14:45:07 +00:00
|
|
|
#define PRINTF_UINT64_T ("%" PRIu64)
|
2009-08-28 14:18:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SSL_SUPPORT
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#endif
|
|
|
|
|
2012-10-02 13:49:27 +00:00
|
|
|
#include "version.h"
|
2009-08-28 14:18:18 +00:00
|
|
|
|
|
|
|
#define uhub_assert assert
|
|
|
|
|
2010-01-07 19:55:13 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#define USE_EPOLL
|
|
|
|
#include <sys/epoll.h>
|
2010-01-26 22:30:32 +00:00
|
|
|
#endif
|
|
|
|
|
2010-02-10 22:45:51 +00:00
|
|
|
#ifdef BSD_LIKE
|
2011-12-09 16:01:02 +00:00
|
|
|
/*
|
2010-01-26 22:30:32 +00:00
|
|
|
#define USE_KQUEUE
|
|
|
|
#include <sys/event.h>
|
2011-12-09 16:01:02 +00:00
|
|
|
*/
|
2010-01-26 22:30:32 +00:00
|
|
|
#endif
|
|
|
|
|
2010-01-20 16:26:23 +00:00
|
|
|
#define USE_SELECT
|
2010-01-27 16:48:16 +00:00
|
|
|
#ifndef WINSOCK
|
2010-01-20 16:26:23 +00:00
|
|
|
#include <sys/select.h>
|
2009-12-09 16:27:46 +00:00
|
|
|
#endif
|
2009-08-28 14:18:18 +00:00
|
|
|
|
2010-02-10 22:45:51 +00:00
|
|
|
#if defined(BSD_LIKE) || defined(__sun__)
|
2009-08-28 14:18:18 +00:00
|
|
|
#undef HAVE_STRNDUP
|
|
|
|
#undef HAVE_MEMMEM
|
|
|
|
#endif
|
|
|
|
|
2011-01-02 01:39:25 +00:00
|
|
|
#ifdef HAVE_GETOPT
|
|
|
|
#include <getopt.h>
|
|
|
|
#endif
|
2010-02-10 22:45:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Detect operating system info.
|
|
|
|
* See: http://predef.sourceforge.net/
|
|
|
|
*/
|
|
|
|
#if defined(__linux__)
|
|
|
|
#define OPSYS "Linux"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(__MINGW32__) || defined(_WIN64) || defined(__WIN32__) || defined(__WINDOWS__)
|
|
|
|
#define OPSYS "Windows"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
|
|
|
#define OPSYS "MacOSX"
|
|
|
|
#endif
|
|
|
|
|
2011-12-09 13:24:21 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2010-02-10 22:45:51 +00:00
|
|
|
#define OPSYS "FreeBSD"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
#define OPSYS "OpenBSD"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__NetBSD__)
|
|
|
|
#define OPSYS "NetBSD"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__sun__)
|
|
|
|
#if defined(__SVR4) || defined(__svr4__)
|
|
|
|
#define OPSYS "Solaris"
|
|
|
|
#else
|
|
|
|
#define OPSYS "SunOS"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HAIKU__)
|
|
|
|
#define OPSYS "Haiku"
|
|
|
|
#endif
|
|
|
|
|
2011-12-09 13:31:02 +00:00
|
|
|
#if defined(__GNU__)
|
|
|
|
#define OPSYS "Hurd"
|
|
|
|
#endif
|
|
|
|
|
2010-02-10 22:45:51 +00:00
|
|
|
/* Detect CPUs */
|
|
|
|
#if defined(__alpha__) || defined(__alpha)
|
|
|
|
#define CPUINFO "Alpha"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) || defined(_M_X64)
|
|
|
|
#define CPUINFO "AMD64"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(__TARGET_ARCH_ARM)
|
|
|
|
#define CPUINFO "ARM"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__i386__) || defined(__i386) || defined(i386) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__THW_INTEL__)
|
|
|
|
#define CPUINFO "i386"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(__ia64) || defined(_M_IA64)
|
|
|
|
#define CPUINFO "IA64"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__hppa__) || defined(__hppa)
|
|
|
|
#define CPUINFO "PARISC"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__m68k__) || defined(M68000)
|
|
|
|
#define CPUINFO "M68K"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__mips__) || defined(mips) || defined(__mips) || defined(__MIPS__)
|
|
|
|
#define CPUINFO "MIPS"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(__powerpc) || defined(__powerpc__)
|
|
|
|
#define CPUINFO "PowerPC"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__sparc__) || defined(__sparc)
|
|
|
|
#define CPUINFO "SPARC"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__sh__)
|
|
|
|
#define CPUINFO "SuperH"
|
|
|
|
#endif
|
|
|
|
|
2011-12-09 13:31:02 +00:00
|
|
|
#if defined(__s390__) || defined(__s390x__)
|
|
|
|
#define CPUINFO "s390"
|
|
|
|
#endif
|
|
|
|
|
2010-02-10 22:45:51 +00:00
|
|
|
/* Misc */
|
2009-08-28 14:18:18 +00:00
|
|
|
#ifdef MSG_NOSIGNAL
|
|
|
|
#define UHUB_SEND_SIGNAL MSG_NOSIGNAL
|
|
|
|
#else
|
|
|
|
#ifdef MSG_NOPIPE
|
|
|
|
#define UHUB_SEND_SIGNAL MSG_NOPIPE
|
|
|
|
#else
|
|
|
|
#define UHUB_SEND_SIGNAL 0
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INET6_ADDRSTRLEN
|
|
|
|
#define INET6_ADDRSTRLEN 46
|
|
|
|
#endif
|
|
|
|
|
2010-01-28 00:07:05 +00:00
|
|
|
#ifndef MIN
|
2009-08-28 14:18:18 +00:00
|
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
2010-01-28 00:07:05 +00:00
|
|
|
#endif
|
2009-08-28 14:18:18 +00:00
|
|
|
|
2010-01-28 00:07:05 +00:00
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
#endif
|
2009-08-28 14:18:18 +00:00
|
|
|
|
2011-01-02 01:39:25 +00:00
|
|
|
#ifndef HAVE_SSIZE_T
|
|
|
|
typedef int ssize_t;
|
|
|
|
#define HAVE_SSIZE_T
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
typedef unsigned __int32 uint32_t;
|
|
|
|
typedef unsigned __int64 uint64_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define strdup _strdup
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#define strcasecmp _stricmp
|
|
|
|
#define strncasecmp _strnicmp
|
|
|
|
#define atoll _atoi64
|
2011-01-02 23:12:40 +00:00
|
|
|
#include <io.h>
|
|
|
|
#define open _open
|
|
|
|
#define close _close
|
|
|
|
#define read _read
|
2011-01-06 11:25:44 +00:00
|
|
|
#define NEED_GETOPT
|
2011-01-02 01:39:25 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-07 23:00:32 +00:00
|
|
|
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER)
|
|
|
|
#define PLUGIN_API __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
#define PLUGIN_API
|
|
|
|
#endif
|
2009-08-28 14:18:18 +00:00
|
|
|
#endif /* HAVE_UHUB_SYSTEM_H */
|