From 492e526d4b1d933d1441dd759d8b1bdbe72c0cc3 Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Fri, 26 Jun 2009 17:04:28 +0200 Subject: [PATCH] Make it compile on mingw Add headers and casts necessary to silence mingw. Additionaly "interface" is a macro on Windows which leads to weird compiler errors; renaming the variables was unavoidable To make libtool generate DLLs on windows the linker flag -no-undefined needs to be passed; otherwise libtool will only create static libraries. --- configure.ac | 12 ++++++++ libgssdp/Makefile.am | 6 ++++ libgssdp/gssdp-client.c | 81 ++++++++++++++++++++++++++++++++++++++----------- libgssdp/gssdp-client.h | 2 +- 4 files changed, 82 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index 4691e76..cd23d0b 100644 --- a/configure.ac +++ b/configure.ac @@ -63,6 +63,18 @@ if test "x$enable_debug" = "xyes"; then fi GOBJECT_INTROSPECTION_CHECK([0.6.4]) +dnl Check for Win32 +AC_MSG_CHECKING([for Win32]) +case "$host" in + *-*-mingw*) + os_win32=yes + ;; + *) + os_win32=no + ;; +esac +AC_MSG_RESULT([$os_win32]) +AM_CONDITIONAL(OS_WIN32, [test $os_win32 = yes]) GTK_DOC_CHECK([1.0]) diff --git a/libgssdp/Makefile.am b/libgssdp/Makefile.am index aad8362..677aebf 100644 --- a/libgssdp/Makefile.am +++ b/libgssdp/Makefile.am @@ -48,6 +48,12 @@ libgssdp_1_0_la_SOURCES = gssdp-client.c \ libgssdp_1_0_la_LIBADD = $(LIBGSSDP_LIBS) +if OS_WIN32 + +libgssdp_1_0_la_LIBADD += -lws2_32 +libgssdp_1_0_la_LDFLAGS += -no-undefined +endif + EXTRA_DIST = gssdp-marshal.list diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c index 4819734..9393a56 100644 --- a/libgssdp/gssdp-client.c +++ b/libgssdp/gssdp-client.c @@ -31,18 +31,29 @@ */ #include -#include #include +#include +#ifndef G_OS_WIN32 +#include #include #include #include +#else +#include +#include +typedef int socklen_t; +/* from the return value of inet_addr */ +typedef unsigned long in_addr_t; +#endif #include #include #include #include +#ifndef G_OS_WIN32 #include #include #include +#endif #include #include "gssdp-client.h" @@ -63,7 +74,7 @@ struct _GSSDPClientPrivate { GMainContext *main_context; char *server_id; - char *interface; + char *iface; char *host_ip; GError **error; @@ -234,7 +245,7 @@ gssdp_client_set_property (GObject *object, client->priv->error = g_value_get_pointer (value); break; case PROP_IFACE: - client->priv->interface = g_value_dup_string (value); + client->priv->iface = g_value_dup_string (value); break; case PROP_ACTIVE: client->priv->active = g_value_get_boolean (value); @@ -280,7 +291,7 @@ gssdp_client_finalize (GObject *object) client = GSSDP_CLIENT (object); g_free (client->priv->server_id); - g_free (client->priv->interface); + g_free (client->priv->iface); g_free (client->priv->host_ip); G_OBJECT_CLASS (gssdp_client_parent_class)->finalize (object); @@ -444,12 +455,12 @@ gssdp_client_class_init (GSSDPClientClass *klass) **/ GSSDPClient * gssdp_client_new (GMainContext *main_context, - const char *interface, + const char *iface, GError **error) { return g_object_new (GSSDP_TYPE_CLIENT, "main-context", main_context, - "interface", interface, + "interface", iface, "error", error, NULL); } @@ -535,7 +546,7 @@ gssdp_client_get_interface (GSSDPClient *client) { g_return_val_if_fail (GSSDP_IS_CLIENT (client), NULL); - return client->priv->interface; + return client->priv->iface; } /** @@ -630,6 +641,19 @@ _gssdp_client_send_message (GSSDPClient *client, static char * make_server_id (void) { +#ifdef G_OS_WIN32 + OSVERSIONINFO versioninfo; + versioninfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + if (GetVersionEx (&versioninfo)) { + return g_strdup_printf ("Microsoft Windows/%ld.%ld GSSDP/%s", + versioninfo.dwMajorVersion, + versioninfo.dwMinorVersion, + VERSION); + } else { + return g_strdup_printf ("Microsoft Windows GSSDP/%s", + VERSION); + } +#else struct utsname sysinfo; uname (&sysinfo); @@ -638,6 +662,7 @@ make_server_id (void) sysinfo.sysname, sysinfo.version, VERSION); +#endif } static gboolean @@ -708,6 +733,20 @@ parse_http_response (char *buf, } } +#ifdef G_OS_WIN32 +static in_addr_t +inet_netof (struct in_addr in) { + in_addr_t i = ntohl(in.s_addr); + + if (IN_CLASSA (i)) + return (((i) & IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); + else if (IN_CLASSB (i)) + return (((i) & IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); + else + return (((i) & IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); +} +#endif + /** * Called when data can be read from the socket **/ @@ -866,11 +905,14 @@ multicast_socket_source_cb (GIOChannel *source, * appropriately. */ static char * -get_host_ip (char **interface) +get_host_ip (char **iface) { +#ifdef G_OS_WIN32 + return g_strdup ("127.0.0.1"); +#else struct ifaddrs *ifa_list, *ifa; char *ret; - GList *up_ifaces, *iface; + GList *up_ifaces, *ifaceptr; ret = NULL; up_ifaces = NULL; @@ -886,7 +928,7 @@ get_host_ip (char **interface) if (ifa->ifa_addr == NULL) continue; - if (*interface && strcmp (*interface, ifa->ifa_name) != 0) + if (*iface && strcmp (*iface, ifa->ifa_name) != 0) continue; else if (!(ifa->ifa_flags & IFF_UP)) continue; @@ -901,7 +943,9 @@ get_host_ip (char **interface) up_ifaces = g_list_prepend (up_ifaces, ifa); } - for (iface = up_ifaces; iface != NULL; iface = iface->next) { + for (ifaceptr = up_ifaces; + ifaceptr != NULL; + ifaceptr = ifaceptr->next) { char ip[INET6_ADDRSTRLEN]; const char *p; struct sockaddr_in *s4; @@ -909,7 +953,7 @@ get_host_ip (char **interface) p = NULL; - ifa = iface->data; + ifa = ifaceptr->data; switch (ifa->ifa_addr->sa_family) { case AF_INET: @@ -929,8 +973,8 @@ get_host_ip (char **interface) if (p != NULL) { ret = g_strdup (p); - if (*interface == NULL) - *interface = g_strdup (ifa->ifa_name); + if (*iface == NULL) + *iface = g_strdup (ifa->ifa_name); break; } } @@ -939,6 +983,7 @@ get_host_ip (char **interface) freeifaddrs (ifa_list); return ret; +#endif } static gboolean @@ -946,11 +991,11 @@ init_network_info (GSSDPClient *client) { gboolean ret = TRUE; - if (client->priv->interface == NULL || client->priv->host_ip == NULL) + if (client->priv->iface == NULL || client->priv->host_ip == NULL) client->priv->host_ip = - get_host_ip (&client->priv->interface); + get_host_ip (&client->priv->iface); - if (client->priv->interface == NULL) { + if (client->priv->iface == NULL) { if (client->priv->error) g_set_error (client->priv->error, GSSDP_ERROR, @@ -964,7 +1009,7 @@ init_network_info (GSSDPClient *client) GSSDP_ERROR, GSSDP_ERROR_NO_IP_ADDRESS, "Failed to find IP of interface %s", - client->priv->interface); + client->priv->iface); ret = FALSE; } diff --git a/libgssdp/gssdp-client.h b/libgssdp/gssdp-client.h index cae12f6..4dedf1d 100644 --- a/libgssdp/gssdp-client.h +++ b/libgssdp/gssdp-client.h @@ -70,7 +70,7 @@ typedef struct { GSSDPClient * gssdp_client_new (GMainContext *main_context, - const char *interface, + const char *iface, GError **error); GMainContext * -- 2.7.4