[Nice] libnice and mingw
Youness Alaoui
youness.alaoui at collabora.co.uk
Mon Nov 28 05:15:10 PST 2011
Hi Nader,
Sorry for the late response, I've been travelling so haven't had
time/opportunity to check my mails in a week!
Thank you for the diff, however for some reason, I don't see it correctly, did
you copy/paste it into the email? your mail client seems to reformat it which
breaks the patch format. Could you attach the diff directly to the mail ? or zip
it if necessary..
I guess it would be interesting to debug all those issues you've had and fix the
tools/unit tests properly. it would be great to have it fully working under mingw.
Don't worry about MSVC, it should work fine, but if it doesn't, it's ok as long
as we have mingw support :p
I will wait to receive a proper patch then I will review it and let you know if
I have any comments (I probably will.. I always do... :) )
Thank you,
Youness.
On 11/21/2011 04:22 PM, Nader Morshed wrote:
> Hey, I was poking at the trunk of libnice yesterday to see if I can get
> it to compile with mingw on windows.
>
> At this point, it compiles, -Werror and all, though one of the stun
> tools is still left with the windows version returning from main()
> immediately. I couldn't get the test suite running properly, either, so
> I'm not entirely sure how functional my changes are.
>
> A patch of my changes is listed below.
>
> I realize it probably won't fully fix the mingw support, but it's a
> start, and I didn't feel like letting my progress be in vain before I
> abandoned the effort.
>
> Some of the changes probably won't be fully compatible with MSVC, but I
> don't have a copy of it to check with. I'll watch this thread and
> respond to any questions regarding details in the patch, since I'm
> sure some of them may go against someone's code development
> philosophy. :)
>
> diff -r 0cfb9569bae9 agent/Makefile.am
> --- a/agent/Makefile.am Tue Sep 20 23:33:39 2011 -0400
> +++ b/agent/Makefile.am Mon Nov 21 13:16:06 2011 -0800
> @@ -18,7 +18,11 @@
> -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
> +
> +# COMMON_LDADD = libagent.la $(GLIB_LIBS) (GUPNP_LIBS)
>
> dist_noinst_DATA = agent-signals-marshal.list
> noinst_LTLIBRARIES = libagent.la
> @@ -71,3 +75,7 @@
> $(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 -r 0cfb9569bae9 agent/address.h
> --- a/agent/address.h Tue Sep 20 23:33:39 2011 -0400
> +++ b/agent/address.h Mon Nov 21 13:16:06 2011 -0800
> @@ -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 -r 0cfb9569bae9 agent/agent.c
> --- a/agent/agent.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/agent/agent.c Mon Nov 21 13:16:06 2011 -0800
> @@ -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>
> @@ -2881,13 +2882,13 @@
> _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 -r 0cfb9569bae9 agent/interfaces.c
> --- a/agent/interfaces.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/agent/interfaces.c Mon Nov 21 13:16:06 2011 -0800
> @@ -350,6 +350,20 @@
> #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 @@
>
> return sock;
> }
> +#endif
>
> GList * nice_interfaces_get_local_interfaces ()
> {
> @@ -450,7 +465,7 @@
> 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 @@
> /*
> * 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 @@
> 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 -r 0cfb9569bae9 agent/pseudotcp.c
> --- a/agent/pseudotcp.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/agent/pseudotcp.c Mon Nov 21 13:16:06 2011 -0800
> @@ -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 @@
> //////////////////////////////////////////////////////////////////////
> // 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 @@
>
> 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 @@
> 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 -r 0cfb9569bae9 configure.ac
> --- a/configure.ac Tue Sep 20 23:33:39 2011 -0400
> +++ b/configure.ac Mon Nov 21 13:16:06 2011 -0800
> @@ -6,9 +6,12 @@
> AC_INIT(libnice, 0.1.1.1)
> 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_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 -r 0cfb9569bae9 socket/tcp-bsd.c
> --- a/socket/tcp-bsd.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/socket/tcp-bsd.c Mon Nov 21 13:16:06 2011 -0800
> @@ -90,7 +90,7 @@
> int sockfd = -1;
> int ret;
> struct sockaddr_storage name;
> - guint name_len = sizeof (name);
> + gint name_len = sizeof (name);
> NiceSocket *sock;
> TcpPriv *priv;
>
> diff -r 0cfb9569bae9 socket/udp-bsd.c
> --- a/socket/udp-bsd.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/socket/udp-bsd.c Mon Nov 21 13:16:06 2011 -0800
> @@ -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 -r 0cfb9569bae9 stun/Makefile.am
> --- a/stun/Makefile.am Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/Makefile.am Mon Nov 21 13:16:06 2011 -0800
> @@ -13,6 +13,10 @@
> 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 -r 0cfb9569bae9 stun/rand.c
> --- a/stun/rand.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/rand.c Mon Nov 21 13:16:06 2011 -0800
> @@ -43,6 +43,7 @@
> #ifdef _WIN32
>
> #include <windows.h>
> +#include <Wincrypt.h>
>
> void RAND_bytes (uint8_t *dst, int len)
> {
> @@ -51,7 +52,9 @@
>
> 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 -r 0cfb9569bae9 stun/tools/Makefile.am
> --- a/stun/tools/Makefile.am Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/tools/Makefile.am Mon Nov 21 13:16:06 2011 -0800
> @@ -23,3 +23,7 @@
> stunbdc_LDADD = $(top_builddir)/stun/libstun.la
>
>
> +if WINDOWS
> + AM_CFLAGS += -DWINVER=0x0501 # _WIN32_WINNT_WINXP
> + stunbdc_LDADD += -lws2_32
> +endif
> diff -r 0cfb9569bae9 stun/tools/stunbdc.c
> --- a/stun/tools/stunbdc.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/tools/stunbdc.c Mon Nov 21 13:16:06 2011 -0800
> @@ -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 @@
>
> return run (family, server, port) ? 1 : 0;
> }
> -#else
> -int main () {
> - return 0;
> -}
> -#endif
> diff -r 0cfb9569bae9 stun/tools/stund.c
> --- a/stun/tools/stund.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/tools/stund.c Mon Nov 21 13:16:06 2011 -0800
> @@ -346,7 +346,7 @@
> }
>
> #else
> -int main () {
> +int main (int argc, char **argv) {
> return 0;
> }
> #endif
> diff -r 0cfb9569bae9 stun/usages/bind.c
> --- a/stun/usages/bind.c Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/usages/bind.c Mon Nov 21 13:16:06 2011 -0800
> @@ -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 @@
> }
>
>
> +#ifdef HAVE_POLL
> static int stun_trans_fd (const StunTransport *tr)
> {
> assert (tr != NULL);
> return tr->fd;
> }
> +#endif
>
>
> /*
> diff -r 0cfb9569bae9 stun/usages/bind.h
> --- a/stun/usages/bind.h Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/usages/bind.h Mon Nov 21 13:16:06 2011 -0800
> @@ -52,7 +52,7 @@
>
>
> #ifdef _WIN32
> -#include "win32_common.h"
> +# include "../win32_common.h"
> #else
> # include <stdbool.h>
> # include <stdint.h>
> diff -r 0cfb9569bae9 stun/usages/turn.h
> --- a/stun/usages/turn.h Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/usages/turn.h Mon Nov 21 13:16:06 2011 -0800
> @@ -53,7 +53,7 @@
>
>
> #ifdef _WIN32
> -#include "win32_common.h"
> +# include "../win32_common.h"
> #else
> # include <stdbool.h>
> # include <stdint.h>
> diff -r 0cfb9569bae9 stun/win32_common.h
> --- a/stun/win32_common.h Tue Sep 20 23:33:39 2011 -0400
> +++ b/stun/win32_common.h Mon Nov 21 13:16:06 2011 -0800
> @@ -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 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 -r 0cfb9569bae9 tests/Makefile.am
> --- a/tests/Makefile.am Tue Sep 20 23:33:39 2011 -0400
> +++ b/tests/Makefile.am Mon Nov 21 13:16:06 2011 -0800
> @@ -62,7 +62,7 @@
>
> test_fallback_LDADD = $(COMMON_LDADD)
>
> -test_thread_LDADD = $(COMMON_LDADD)
> +# test_thread_LDADD = $(COMMON_LDADD)
>
> test_dribble_LDADD = $(COMMON_LDADD)
>
>
>
> _______________________________________________
> Nice mailing list
> Nice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nice
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/nice/attachments/20111128/a09fc6f6/attachment-0001.pgp>
More information about the nice
mailing list