diff options
-rw-r--r-- | agent/Makefile.am | 8 | ||||
-rw-r--r-- | agent/address.h | 1 | ||||
-rw-r--r-- | agent/agent.c | 7 | ||||
-rw-r--r-- | agent/interfaces.c | 24 | ||||
-rw-r--r-- | agent/pseudotcp.c | 49 | ||||
-rw-r--r-- | configure.ac | 17 | ||||
-rw-r--r-- | socket/tcp-bsd.c | 2 | ||||
-rw-r--r-- | socket/udp-bsd.c | 4 | ||||
-rw-r--r-- | stun/Makefile.am | 4 | ||||
-rw-r--r-- | stun/rand.c | 5 | ||||
-rw-r--r-- | stun/tools/Makefile.am | 4 | ||||
-rw-r--r-- | stun/tools/stunbdc.c | 14 | ||||
-rw-r--r-- | stun/tools/stund.c | 2 | ||||
-rw-r--r-- | stun/usages/bind.c | 4 | ||||
-rw-r--r-- | stun/usages/bind.h | 2 | ||||
-rw-r--r-- | stun/usages/turn.h | 2 | ||||
-rw-r--r-- | stun/win32_common.h | 3 | ||||
-rw-r--r-- | tests/Makefile.am | 2 |
18 files changed, 101 insertions, 53 deletions
diff --git a/agent/Makefile.am b/agent/Makefile.am index 3a7e37f..6ba95e5 100644 --- a/agent/Makefile.am +++ b/agent/Makefile.am @@ -18,7 +18,9 @@ AM_CFLAGS = \ -I $(top_srcdir)/socket \ -I $(top_srcdir)/stun -COMMON_LDADD = libagent.la $(GLIB_LIBS) (GUPNP_LIBS) +if WINDOWS + AM_CFLAGS += -DWINVER=0x0501 # _WIN32_WINNT_WINXP +endif dist_noinst_DATA = agent-signals-marshal.list noinst_LTLIBRARIES = libagent.la @@ -71,3 +73,7 @@ libagent_la_DEPENDENCIES = \ $(top_builddir)/stun/libstun.la pkginclude_HEADERS = agent.h candidate.h debug.h address.h interfaces.h pseudotcp.h + +if WINDOWS + libagent_la_LIBADD += -lws2_32 +endif diff --git a/agent/address.h b/agent/address.h index 2318bcb..17c5b3e 100644 --- a/agent/address.h +++ b/agent/address.h @@ -55,7 +55,6 @@ #ifdef G_OS_WIN32 #include <winsock2.h> #include <ws2tcpip.h> -#include <wspiapi.h> #else #include <sys/types.h> #include <sys/socket.h> diff --git a/agent/agent.c b/agent/agent.c index e447543..9b6a0b8 100644 --- a/agent/agent.c +++ b/agent/agent.c @@ -50,7 +50,8 @@ #include <errno.h> #ifdef G_OS_WIN32 -#include <winsock2.h> +# include <winsock2.h> +# define EWOULDBLOCK WSAEWOULDBLOCK #else #include <sys/socket.h> #include <netinet/in.h> @@ -2878,13 +2879,13 @@ void _priv_set_socket_tos (NiceAgent *agent, NiceSocket *sock, gint tos) { if (setsockopt (sock->fileno, IPPROTO_IP, - IP_TOS, &tos, sizeof (tos)) < 0) { + IP_TOS, (const char *) &tos, sizeof (tos)) < 0) { nice_debug ("Agent %p: Could not set socket ToS", agent, g_strerror (errno)); } #ifdef IPV6_TCLASS if (setsockopt (sock->fileno, IPPROTO_IPV6, - IPV6_TCLASS, &tos, sizeof (tos)) < 0) { + IPV6_TCLASS, (const char *) &tos, sizeof (tos)) < 0) { nice_debug ("Agent %p: Could not set IPV6 socket ToS", agent, g_strerror (errno)); } diff --git a/agent/interfaces.c b/agent/interfaces.c index 01046d1..d5d4f4d 100644 --- a/agent/interfaces.c +++ b/agent/interfaces.c @@ -350,6 +350,20 @@ nice_interfaces_get_ip_for_interface (gchar *interface_name) #include <winsock2.h> #include <Iphlpapi.h> +// Should be in Iphlpapi.h, but mingw doesn't seem to have these +// Values copied directly from: +// http://msdn.microsoft.com/en-us/library/aa366845(v=vs.85).aspx +// (Title: MIB_IPADDRROW structure) + +#ifndef MIB_IPADDR_DISCONNECTED +#define MIB_IPADDR_DISCONNECTED 0x0008 +#endif + +#ifndef MIB_IPADDR_DELETED +#define MIB_IPADDR_DELETED 0x0040 +#endif + +#if 0 static gboolean started_wsa_engine = FALSE; /* @@ -383,6 +397,7 @@ SOCKET nice_interfaces_get_WSA_socket () return sock; } +#endif GList * nice_interfaces_get_local_interfaces () { @@ -450,7 +465,7 @@ GList * nice_interfaces_get_local_ips (gboolean include_loopback) continue; } - ipstr = g_strdup_printf ("%d.%d.%d.%d", + ipstr = g_strdup_printf ("%lu.%lu.%lu.%lu", (ipaddr->dwAddr ) & 0xFF, (ipaddr->dwAddr >> 8) & 0xFF, (ipaddr->dwAddr >> 16) & 0xFF, @@ -471,8 +486,11 @@ GList * nice_interfaces_get_local_ips (gboolean include_loopback) /* * returns ip address as an utf8 string */ +// Source for idx's type (Was IF_INDEX): +// http://msdn.microsoft.com/en-us/library/aa366836(v=VS.85).aspx +// (Title: MIB_IFROW structure) static gchar * -win32_get_ip_for_interface (IF_INDEX idx) +win32_get_ip_for_interface (DWORD idx) { ULONG size = 0; PMIB_IPADDRTABLE ip_table; @@ -491,7 +509,7 @@ win32_get_ip_for_interface (IF_INDEX idx) PMIB_IPADDRROW ipaddr = &ip_table->table[i]; if (ipaddr->dwIndex == idx && !(ipaddr->wType & (MIB_IPADDR_DISCONNECTED | MIB_IPADDR_DELETED))) { - ret = g_strdup_printf ("%d.%d.%d.%d", + ret = g_strdup_printf ("%lu.%lu.%lu.%lu", (ipaddr->dwAddr ) & 0xFF, (ipaddr->dwAddr >> 8) & 0xFF, (ipaddr->dwAddr >> 16) & 0xFF, diff --git a/agent/pseudotcp.c b/agent/pseudotcp.c index 377aa54..ce701d2 100644 --- a/agent/pseudotcp.c +++ b/agent/pseudotcp.c @@ -64,11 +64,19 @@ */ #include <stdlib.h> -#include <arpa/inet.h> #include <errno.h> #include <string.h> #include <glib.h> +#ifdef G_OS_WIN32 +# include <winsock2.h> +# define ECONNABORTED WSAECONNABORTED +# define ENOTCONN WSAENOTCONN +# define EWOULDBLOCK WSAEWOULDBLOCK +# define ECONNRESET WSAECONNRESET +#else +# include <arpa/inet.h> +#endif #include "pseudotcp.h" @@ -176,17 +184,10 @@ const guint16 PACKET_MAXIMUMS[] = { ////////////////////////////////////////////////////////////////////// // Helper Functions ////////////////////////////////////////////////////////////////////// - -static guint32 -min (guint32 first, guint32 second) -{ - return (first < second? first:second); -} -static guint32 -max (guint32 first, guint32 second) -{ - return (first > second? first:second); -} +#ifndef G_OS_WIN32 +# define min(first, second) ((first) < (second) ? (first) : (second)) +# define max(first, second) ((first) > (second) ? (first) : (second)) +#endif static guint32 bound(guint32 lower, guint32 middle, guint32 upper) @@ -792,16 +793,16 @@ packet(PseudoTcpSocket *self, guint32 seq, guint8 flags, g_assert(HEADER_SIZE + len <= MAX_PACKET); - *((uint32_t *) buffer) = htonl(priv->conv); - *((uint32_t *) (buffer + 4)) = htonl(seq); - *((uint32_t *) (buffer + 8)) = htonl(priv->rcv_nxt); + *((guint32 *) buffer) = htonl(priv->conv); + *((guint32 *) (buffer + 4)) = htonl(seq); + *((guint32 *) (buffer + 8)) = htonl(priv->rcv_nxt); buffer[12] = 0; buffer[13] = flags; - *((uint16_t *) (buffer + 14)) = htons((uint16_t)priv->rcv_wnd); + *((guint16 *) (buffer + 14)) = htons((guint16)priv->rcv_wnd); // Timestamp computations - *((uint32_t *) (buffer + 16)) = htonl(now); - *((uint32_t *) (buffer + 20)) = htonl(priv->ts_recent); + *((guint32 *) (buffer + 16)) = htonl(now); + *((guint32 *) (buffer + 20)) = htonl(priv->ts_recent); priv->ts_lastack = priv->rcv_nxt; if (data != NULL) @@ -839,14 +840,14 @@ parse(PseudoTcpSocket *self, const guint8 * buffer, guint32 size) if (size < 12) return FALSE; - seg.conv = ntohl(*(uint32_t *)buffer); - seg.seq = ntohl(*(uint32_t *)(buffer + 4)); - seg.ack = ntohl(*(uint32_t *)(buffer + 8)); + seg.conv = ntohl(*(guint32 *)buffer); + seg.seq = ntohl(*(guint32 *)(buffer + 4)); + seg.ack = ntohl(*(guint32 *)(buffer + 8)); seg.flags = buffer[13]; - seg.wnd = ntohs(*(uint16_t *)(buffer + 14)); + seg.wnd = ntohs(*(guint16 *)(buffer + 14)); - seg.tsval = ntohl(*(uint32_t *)(buffer + 16)); - seg.tsecr = ntohl(*(uint32_t *)(buffer + 20)); + seg.tsval = ntohl(*(guint32 *)(buffer + 16)); + seg.tsecr = ntohl(*(guint32 *)(buffer + 20)); seg.data = ((gchar *)buffer) + HEADER_SIZE; seg.len = size - HEADER_SIZE; diff --git a/configure.ac b/configure.ac index 2570a2d..694af48 100644 --- a/configure.ac +++ b/configure.ac @@ -6,9 +6,12 @@ dnl use a three digit version number for releases, and four for cvs/prerelease AC_INIT(libnice, 0.1.1.0) LIBNICE_RELEASE="no" +AC_CANONICAL_SYSTEM + AC_CONFIG_SRCDIR([agent/agent.c]) AC_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE([-Wall]) + AC_CONFIG_FILES([ Makefile agent/Makefile @@ -53,6 +56,20 @@ AC_PROG_CC AC_USE_SYSTEM_EXTENSIONS AC_PROG_LIBTOOL +# Check Operating System +AC_MSG_CHECKING([operating system]) +case "$host" in + *-*-*mingw*|*-*-*cygwin*) + platform=win32 + AC_MSG_RESULT($platform) + ;; + *) + platform=linux/other + AC_MSG_RESULT($platform) + ;; +esac + +AM_CONDITIONAL([WINDOWS], [test "$platform" = "win32"]) # Checks for compiler features diff --git a/socket/tcp-bsd.c b/socket/tcp-bsd.c index c8a5c48..255a234 100644 --- a/socket/tcp-bsd.c +++ b/socket/tcp-bsd.c @@ -91,7 +91,7 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr) int sockfd = -1; int ret; struct sockaddr_storage name; - guint name_len = sizeof (name); + socklen_t name_len = sizeof (name); NiceSocket *sock; TcpPriv *priv; diff --git a/socket/udp-bsd.c b/socket/udp-bsd.c index 095b2d8..029d385 100644 --- a/socket/udp-bsd.c +++ b/socket/udp-bsd.c @@ -51,9 +51,7 @@ #include "udp-bsd.h" -#ifdef G_OS_WIN32 -typedef unsigned long ssize_t; -#else +#ifndef G_OS_WIN32 #include <unistd.h> #endif diff --git a/stun/Makefile.am b/stun/Makefile.am index 0059187..7601964 100644 --- a/stun/Makefile.am +++ b/stun/Makefile.am @@ -13,6 +13,10 @@ include $(top_srcdir)/common.mk AM_CFLAGS = -std=gnu99 -DG_LOG_DOMAIN=\"libnice-stun\" $(ERROR_CFLAGS) AM_CPPFLAGS = -I$(top_srcdir) +if WINDOWS + AM_CFLAGS += -DWINVER=0x0501 # _WIN32_WINNT_WINXP +endif + noinst_LTLIBRARIES = libstun.la libstun_la_SOURCES = constants.h \ diff --git a/stun/rand.c b/stun/rand.c index a17e29d..964bb68 100644 --- a/stun/rand.c +++ b/stun/rand.c @@ -43,6 +43,7 @@ #ifdef _WIN32 #include <windows.h> +#include <Wincrypt.h> void RAND_bytes (uint8_t *dst, int len) { @@ -51,7 +52,9 @@ void RAND_bytes (uint8_t *dst, int len) if(!CryptAcquireContext(&hCryptProv, container, NULL, PROV_RSA_FULL, 0)) { /* non existing container. try to create a new one */ - if (GetLastError() == NTE_BAD_KEYSET) { + // I hope this cast here doesn't cause issues + // gcc was complaining about comparing signed and unsigned values + if (GetLastError() == (DWORD) NTE_BAD_KEYSET) { if(!CryptAcquireContext(&hCryptProv, container, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { return; } diff --git a/stun/tools/Makefile.am b/stun/tools/Makefile.am index 48fc0a5..42b3108 100644 --- a/stun/tools/Makefile.am +++ b/stun/tools/Makefile.am @@ -23,3 +23,7 @@ stunbdc_SOURCES = stunbdc.c stunbdc_LDADD = $(top_builddir)/stun/libstun.la +if WINDOWS + AM_CFLAGS += -DWINVER=0x0501 # _WIN32_WINNT_WINXP + stunbdc_LDADD += -lws2_32 +endif diff --git a/stun/tools/stunbdc.c b/stun/tools/stunbdc.c index c39f3f4..b539ab9 100644 --- a/stun/tools/stunbdc.c +++ b/stun/tools/stunbdc.c @@ -40,9 +40,12 @@ # include <config.h> #endif -#ifndef _WIN32 -#include <sys/socket.h> -#include <netdb.h> +#ifdef _WIN32 +# include <winsock2.h> +#else +# include <sys/socket.h> +# include <netdb.h> +#endif #include <sys/types.h> #include "stun/stunagent.h" @@ -184,8 +187,3 @@ int main (int argc, char *argv[]) return run (family, server, port) ? 1 : 0; } -#else -int main () { - return 0; -} -#endif diff --git a/stun/tools/stund.c b/stun/tools/stund.c index 86f72cc..8498318 100644 --- a/stun/tools/stund.c +++ b/stun/tools/stund.c @@ -346,7 +346,7 @@ int main (int argc, char *argv[]) } #else -int main () { +int main (int argc, char **argv) { return 0; } #endif diff --git a/stun/usages/bind.c b/stun/usages/bind.c index fc9ed51..34302e1 100644 --- a/stun/usages/bind.c +++ b/stun/usages/bind.c @@ -54,6 +54,7 @@ #include <unistd.h> #include <errno.h> #include <sys/time.h> +#include <fcntl.h> #endif @@ -70,7 +71,6 @@ #include <stdlib.h> #include <time.h> #include <errno.h> -#include <fcntl.h> #include "timer.h" @@ -394,11 +394,13 @@ stun_trans_recv (StunTransport *tr, uint8_t *buf, size_t maxlen) } +#ifdef HAVE_POLL static int stun_trans_fd (const StunTransport *tr) { assert (tr != NULL); return tr->fd; } +#endif /* diff --git a/stun/usages/bind.h b/stun/usages/bind.h index 30175ec..a8d72fa 100644 --- a/stun/usages/bind.h +++ b/stun/usages/bind.h @@ -52,7 +52,7 @@ #ifdef _WIN32 -#include "win32_common.h" +# include "../win32_common.h" #else # include <stdbool.h> # include <stdint.h> diff --git a/stun/usages/turn.h b/stun/usages/turn.h index def7501..68f0fab 100644 --- a/stun/usages/turn.h +++ b/stun/usages/turn.h @@ -53,7 +53,7 @@ #ifdef _WIN32 -#include "win32_common.h" +# include "../win32_common.h" #else # include <stdbool.h> # include <stdint.h> diff --git a/stun/win32_common.h b/stun/win32_common.h index 2797eba..cfb862d 100644 --- a/stun/win32_common.h +++ b/stun/win32_common.h @@ -57,6 +57,7 @@ #ifndef _WIN32_COMMON_H #define _WIN32_COMMON_H +#include <sys/types.h> /* 7.18.1.1 Exact-width integer types */ typedef signed char int8_t; @@ -67,8 +68,6 @@ typedef int int32_t; typedef unsigned uint32_t; typedef long long int64_t; typedef unsigned long long uint64_t; -typedef unsigned int size_t; -typedef unsigned long ssize_t; typedef uint8_t bool; #define true 1 diff --git a/tests/Makefile.am b/tests/Makefile.am index 63698a8..2cfc813 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -62,8 +62,6 @@ test_restart_LDADD = $(COMMON_LDADD) test_fallback_LDADD = $(COMMON_LDADD) -test_thread_LDADD = $(COMMON_LDADD) - test_dribble_LDADD = $(COMMON_LDADD) all-local: |