fi
AC_CHECK_FUNCS(getprotobyname_r endservent if_nametoindex)
-AC_CHECK_HEADERS([netdb.h wspiapi.h arpa/nameser_compat.h])
+
+# <wspiapi.h> in the Windows SDK and in mingw-w64 has wrappers for
+# inline workarounds for getaddrinfo, getnameinfo and freeaddrinfo if
+# they aren't present at run-time (on Windows 2000).
+AC_CHECK_HEADER([wspiapi.h], [WSPIAPI_INCLUDE="\#include <wspiapi.h>"])
+AC_SUBST(WSPIAPI_INCLUDE)
+
+AC_MSG_CHECKING([if arpa/nameser_compat.h is needed])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <arpa/nameser.h>],
+ [int qclass = C_IN;])],
+ [AC_MSG_RESULT([no])],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <arpa/nameser.h>
+ #include <arpa/nameser_compat.h>],
+ [int qclass = C_IN;])],
+ [AC_MSG_RESULT([yes])
+ NAMESER_COMPAT_INCLUDE="\#include <arpa/nameser_compat.h>"],
+ [AC_MSG_ERROR([could not compile test program either way])])])
+AC_SUBST(NAMESER_COMPAT_INCLUDE)
AS_IF([test $glib_native_win32 = no], [
# We can't just use AC_CHECK_FUNC/AC_CHECK_LIB here. Bug 586150
gio/Makefile
gio/gdbus-2.0/codegen/Makefile
gio/gdbus-2.0/codegen/config.py
+gio/gnetworking.h
gio/xdgmime/Makefile
gio/inotify/Makefile
gio/kqueue/Makefile
<xi:include href="xml/gunixcredentialsmessage.xml"/>
<xi:include href="xml/gproxy.xml"/>
<xi:include href="xml/gproxyaddress.xml"/>
+ <xi:include href="xml/gnetworking.xml"/>
</chapter>
<chapter id="highlevel-socket">
<title>High-level network functionallity</title>
G_TASK_GET_CLASS
g_task_get_type
</SECTION>
+
+<SECTION>
+<FILE>gnetworking</FILE>
+<TITLE>gnetworking.h</TITLE>
+g_networking_init
+</SECTION>
gioenumtypes.[ch]
glib-compile-resources
glib-compile-schemas
+gnetworking.h
gresource
gschema-compile
gsettings
gnativevolumemonitor.c \
gnativevolumemonitor.h \
gnetworkaddress.c \
+ gnetworking.c \
gnetworkingprivate.h \
gnetworkmonitor.c \
gnetworkmonitorbase.c \
gmountoperation.h \
gnativevolumemonitor.h \
gnetworkaddress.h \
+ gnetworking.h \
gnetworkmonitor.h \
gnetworkservice.h \
goutputstream.h \
gioenumtypes.c \
gdbus-daemon-generated.c \
gdbus-daemon-generated.h \
+ gnetworking.h \
$(NULL)
EXTRA_DIST += \
#include "config.h"
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#endif
-#ifdef __OpenBSD__
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-#endif
#include <stdlib.h>
+#include <string.h>
#include <gobject/gvaluecollector.h>
#include "gcredentials.h"
-#include "gnetworkingprivate.h"
+#include "gnetworking.h"
#include "gioerror.h"
#include "glibintl.h"
#include "gdataoutputstream.h"
#ifdef G_OS_UNIX
-#include <sys/types.h>
-#include <sys/socket.h>
+#include "gnetworking.h"
#include "gunixconnection.h"
#include "gunixcredentialsmessage.h"
#endif
* An IPv4 or IPv6 internet address.
*/
-/* Networking initialization function, called from inside the g_once of
- * g_inet_address_get_type()
- */
-static void
-_g_networking_init (void)
-{
-#ifdef G_OS_WIN32
- WSADATA wsadata;
- if (WSAStartup (MAKEWORD (2, 0), &wsadata) != 0)
- g_error ("Windows Sockets could not be initialized");
-#endif
-}
-
G_DEFINE_TYPE_WITH_CODE (GInetAddress, g_inet_address, G_TYPE_OBJECT,
- _g_networking_init ();)
+ g_networking_init ();)
struct _GInetAddressPrivate
{
struct in6_addr in6_addr;
#endif
- /* Make sure _g_networking_init() has been called */
- g_type_ensure (G_TYPE_INET_ADDRESS);
+ /* If this GInetAddress is the first networking-related object to be
+ * created, then we won't have called g_networking_init() yet at
+ * this point.
+ */
+ g_networking_init ();
#ifdef G_OS_WIN32
memset (&sa, 0, sizeof (sa));
g_task_return_int
g_task_return_new_error
g_task_return_pointer
+g_networking_init
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "gnetworking.h"
+
+/**
+ * SECTION:gnetworking
+ * @title: gnetworking.h
+ * @short_description: System networking includes
+ * @include: gio/gnetworking.h
+ *
+ * The <literal>gnetworking.h</literal> header can be included to get
+ * various low-level networking-related system headers, automatically
+ * taking care of certain portability issues for you.
+ *
+ * This can be used, for example, if you want to call setsockopt()
+ * on a #GSocket.
+ *
+ * Note that while WinSock has many of the same APIs as the
+ * traditional UNIX socket API, most of them behave at least slightly
+ * differently (particularly with respect to error handling). If you
+ * want your code to work under both UNIX and Windows, you will need
+ * to take these differences into account.
+ *
+ * Also, under glibc, certain non-portable functions are only visible
+ * in the headers if you define <literal>_GNU_SOURCE</literal> before
+ * including them. Note that this symbol must be defined before
+ * including <emphasis>any</emphasis> headers, or it may not take
+ * effect.
+ */
+
+/**
+ * g_networking_init:
+ *
+ * Initializes the platform networking libraries (eg, on Windows, this
+ * calls WSAStartup()). GLib will call this itself if it is needed, so
+ * you only need to call it if you directly call system networking
+ * functions (without calling any GLib networking functions first).
+ *
+ * Since: 2.36
+ */
+void
+g_networking_init (void)
+{
+#ifdef G_OS_WIN32
+ static volatile gsize inited = 0;
+
+ if (g_once_init_enter (&inited))
+ {
+ WSADATA wsadata;
+
+ if (WSAStartup (MAKEWORD (2, 0), &wsadata) != 0)
+ g_error ("Windows Sockets could not be initialized");
+
+ g_once_init_leave (&inited, 1);
+ }
+#endif
+}
--- /dev/null
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __G_NETWORKING_H__
+#define __G_NETWORKING_H__
+
+#include <glib.h>
+
+#ifdef G_OS_WIN32
+
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
+#include <winsock2.h>
+#undef interface
+#include <ws2tcpip.h>
+#include <windns.h>
+#include <mswsock.h>
+@WSPIAPI_INCLUDE@
+
+#else /* !G_OS_WIN32 */
+
+#include <sys/types.h>
+
+#include <netdb.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <resolv.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <net/if.h>
+
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+@NAMESER_COMPAT_INCLUDE@
+
+#ifndef T_SRV
+#define T_SRV 33
+#endif
+
+#ifndef _PATH_RESCONF
+#define _PATH_RESCONF "/etc/resolv.conf"
+#endif
+
+#ifndef CMSG_LEN
+/* CMSG_LEN and CMSG_SPACE are defined by RFC 2292, but missing on
+ * some older platforms.
+ */
+#define CMSG_LEN(len) ((size_t)CMSG_DATA((struct cmsghdr *)NULL) + (len))
+
+/* CMSG_SPACE must add at least as much padding as CMSG_NXTHDR()
+ * adds. We overestimate here.
+ */
+#define GLIB_ALIGN_TO_SIZEOF(len, obj) (((len) + sizeof (obj) - 1) & ~(sizeof (obj) - 1))
+#define CMSG_SPACE(len) GLIB_ALIGN_TO_SIZEOF (CMSG_LEN (len), struct cmsghdr)
+#endif
+#endif
+
+G_BEGIN_DECLS
+
+GLIB_AVAILABLE_IN_2_36
+void g_networking_init (void);
+
+G_END_DECLS
+
+#endif /* __G_NETWORKING_H__ */
#ifndef __G_NETWORKINGPRIVATE_H__
#define __G_NETWORKINGPRIVATE_H__
-#ifdef G_OS_WIN32
-
-#include <winsock2.h>
-#undef interface
-#include <ws2tcpip.h>
-#include <windns.h>
-#include <mswsock.h>
-
-#ifdef HAVE_WSPIAPI_H
-/* <wspiapi.h> in the Windows SDK and in mingw-w64 has wrappers for
- * inline workarounds for getaddrinfo, getnameinfo and freeaddrinfo if
- * they aren't present at run-time (on Windows 2000).
- */
-#include <wspiapi.h>
-#endif
-
-#else /* !G_OS_WIN32 */
-
-#include <sys/types.h>
-
-#include <netdb.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <resolv.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#if defined(HAVE_ARPA_NAMESER_COMPAT_H) && !defined(GETSHORT)
-#include <arpa/nameser_compat.h>
-#endif
-#include <net/if.h>
-
-#ifndef T_SRV
-#define T_SRV 33
-#endif
-
-#ifndef _PATH_RESCONF
-#define _PATH_RESCONF "/etc/resolv.conf"
-#endif
-
-#ifndef CMSG_LEN
-/* CMSG_LEN and CMSG_SPACE are defined by RFC 2292, but missing on
- * some older platforms.
- */
-#define CMSG_LEN(len) ((size_t)CMSG_DATA((struct cmsghdr *)NULL) + (len))
-
-/* CMSG_SPACE must add at least as much padding as CMSG_NXTHDR()
- * adds. We overestimate here.
- */
-#define ALIGN_TO_SIZEOF(len, obj) (((len) + sizeof (obj) - 1) & ~(sizeof (obj) - 1))
-#define CMSG_SPACE(len) ALIGN_TO_SIZEOF (CMSG_LEN (len), struct cmsghdr)
-#endif
-#endif
+#include "gnetworking.h"
G_BEGIN_DECLS
* The object that handles DNS resolution. Use g_resolver_get_default()
* to get the default resolver.
*/
-G_DEFINE_TYPE (GResolver, g_resolver, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_CODE (GResolver, g_resolver, G_TYPE_OBJECT,
+ g_networking_init ();)
static GList *
srv_records_to_targets (GList *records)
g_type_class_add_private (resolver_class, sizeof (GResolverPrivate));
- /* Make sure _g_networking_init() has been called */
- g_type_ensure (G_TYPE_INET_ADDRESS);
-
/**
* GResolver::reload:
* @resolver: a #GResolver
#include "gioerror.h"
#include "gioenums.h"
#include "gioerror.h"
-#include "gnetworkingprivate.h"
+#include "gnetworking.h"
#include "gsocketaddress.h"
#include "gsocketcontrolmessage.h"
#include "gcredentials.h"
* SECTION:gsocket
* @short_description: Low-level socket object
* @include: gio/gio.h
- * @see_also: #GInitable
+ * @see_also: #GInitable, <link linkend="gio-gnetworking.h">gnetworking.h</link>
*
* A #GSocket is a low-level networking primitive. It is a more or less
* direct mapping of the BSD socket API in a portable GObject based API.
GError **error);
G_DEFINE_TYPE_WITH_CODE (GSocket, g_socket, G_TYPE_OBJECT,
+ g_networking_init ();
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
g_socket_initable_iface_init));
{
GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
- /* Make sure winsock has been initialized */
- g_type_ensure (G_TYPE_INET_ADDRESS);
-
#ifdef SIGPIPE
/* There is no portable, thread-safe way to avoid having the process
* be killed by SIGPIPE when calling send() or sendmsg(), so we are
#include <gio/gsocketcontrolmessage.h>
#include <gio/gunixfdmessage.h>
+#include <gio/gnetworking.h>
#include <gio/gsocket.h>
-#include <unistd.h>
-#ifdef __linux__
-/* for getsockopt() and setsockopt() */
-#include <sys/types.h> /* See NOTES */
-#include <sys/socket.h>
#include <errno.h>
#include <string.h>
-#endif
+#include <unistd.h>
G_DEFINE_TYPE_WITH_CODE (GUnixConnection, g_unix_connection,
/* ---------------------------------------------------------------------------------------------------- */
#ifdef __linux__
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <fcntl.h>
#define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
-
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <fcntl.h>
#define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
#else
/* TODO: please add support for your UNIX flavor */
/* ---------------------------------------------------------------------------------------------------- */
-#include <string.h>
+#include <fcntl.h>
#include <errno.h>
+#include <string.h>
+#include <unistd.h>
#include "gunixcredentialsmessage.h"
#include "gcredentials.h"
+#include "gnetworking.h"
#include "glibintl.h"
#include "config.h"
-#include <sys/types.h>
-#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include "gunixfdlist.h"
+#include "gnetworking.h"
#include "gioerror.h"
#include "config.h"
-#include <sys/types.h>
-#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include "gunixfdmessage.h"
#include "gunixfdlist.h"
+#include "gnetworking.h"
#include "gioerror.h"
#include "gunixsocketaddress.h"
#include "glibintl.h"
-#include "gnetworkingprivate.h"
+#include "gnetworking.h"
/**
/* for g_unlink() */
#include <glib/gstdio.h>
-#include <gio/gnetworkingprivate.h>
+#include <gio/gnetworking.h>
#include <gio/gunixsocketaddress.h>
#include <gio/gunixfdlist.h>
#ifdef G_OS_UNIX
#include <errno.h>
-#include <sys/types.h>
-#include <sys/socket.h>
#include <sys/wait.h>
#include <string.h>
#include <stdlib.h>
+#include <gio/gnetworking.h>
#include <gio/gunixconnection.h>
#endif
#include <gio/gio.h>
+#include <gio/gnetworking.h>
#include <gio/gunixfdmessage.h>
#include <gio/gunixsocketaddress.h>
-#include <sys/socket.h>
#include <string.h>
#include <unistd.h>