Commit 1fe527be authored by Nader Morshed's avatar Nader Morshed Committed by Youness Alaoui

Add support for windows's compilation through MinGW

parent 1b44dca9
......@@ -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
......@@ -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>
......
......@@ -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));
}
......
......@@ -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,
......
......@@ -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;
......
......@@ -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
......
......@@ -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;
......
......@@ -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
......
......@@ -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 \
......
......@@ -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;
}
......
......@@ -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
......@@ -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
......@@ -346,7 +346,7 @@ int main (int argc, char *argv[])
}
#else
int main () {
int main (int argc, char **argv) {
return 0;
}
#endif
......@@ -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
/*
......
......@@ -52,7 +52,7 @@
#ifdef _WIN32
#include "win32_common.h"
# include "../win32_common.h"
#else
# include <stdbool.h>
# include <stdint.h>
......
......@@ -53,7 +53,7 @@
#ifdef _WIN32
#include "win32_common.h"
# include "../win32_common.h"
#else
# include <stdbool.h>
# include <stdint.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
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment