Merge remote branch 'gvdb/master'
[platform/upstream/glib.git] / gio / gnetworkingprivate.h
1 /* GIO - GLib Input, Output and Streaming Library
2  *
3  * Copyright (C) 2008 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __G_NETWORKINGPRIVATE_H__
22 #define __G_NETWORKINGPRIVATE_H__
23
24 #ifdef G_OS_WIN32
25
26 #define _WIN32_WINNT 0x0501
27 #include <winsock2.h>
28 #undef interface
29 #include <ws2tcpip.h>
30 #include <windns.h>
31 #include <mswsock.h>
32
33 #ifdef HAVE_WSPIAPI_H
34 /* <wspiapi.h> in the Windows SDK and in mingw-w64 has wrappers for
35  * inline workarounds for getaddrinfo, getnameinfo and freeaddrinfo if
36  * they aren't present at run-time (on Windows 2000).
37  */
38 #include <wspiapi.h>
39 #endif
40
41 #else /* !G_OS_WIN32 */
42
43 /* need this for struct ucred on Linux */
44 #ifdef __linux__
45 #define __USE_GNU
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #undef __USE_GNU
49 #endif
50
51 #include <sys/types.h>
52 #include <arpa/inet.h>
53 #include <arpa/nameser.h>
54 #if defined(HAVE_ARPA_NAMESER_COMPAT_H) && !defined(GETSHORT)
55 #include <arpa/nameser_compat.h>
56 #endif
57
58 #ifndef T_SRV
59 #define T_SRV 33
60 #endif
61
62 /* We're supposed to define _GNU_SOURCE to get EAI_NODATA, but that
63  * won't actually work since <features.h> has already been included at
64  * this point. So we define __USE_GNU instead.
65  */
66 #define __USE_GNU
67 #include <netdb.h>
68 #undef __USE_GNU
69 #include <netinet/in.h>
70 #include <netinet/tcp.h>
71 #include <resolv.h>
72 #include <sys/socket.h>
73 #include <sys/un.h>
74
75 #ifndef _PATH_RESCONF
76 #define _PATH_RESCONF "/etc/resolv.conf"
77 #endif
78
79 #ifndef CMSG_LEN
80 /* CMSG_LEN and CMSG_SPACE are defined by RFC 2292, but missing on
81  * some older platforms.
82  */
83 #define CMSG_LEN(len) ((size_t)CMSG_DATA((struct cmsghdr *)NULL) + (len))
84
85 /* CMSG_SPACE must add at least as much padding as CMSG_NXTHDR()
86  * adds. We overestimate here.
87  */
88 #define ALIGN_TO_SIZEOF(len, obj) (((len) + sizeof (obj) - 1) & ~(sizeof (obj) - 1))
89 #define CMSG_SPACE(len) ALIGN_TO_SIZEOF (CMSG_LEN (len), struct cmsghdr)
90 #endif
91 #endif
92
93 G_BEGIN_DECLS
94
95 extern struct addrinfo _g_resolver_addrinfo_hints;
96
97 GList *_g_resolver_addresses_from_addrinfo (const char       *hostname,
98                                             struct addrinfo  *res,
99                                             gint              gai_retval,
100                                             GError          **error);
101
102 void   _g_resolver_address_to_sockaddr     (GInetAddress            *address,
103                                             struct sockaddr_storage *sa,
104                                             gsize                   *len);
105 char  *_g_resolver_name_from_nameinfo      (GInetAddress     *address,
106                                             const gchar      *name,
107                                             gint              gni_retval,
108                                             GError          **error);
109
110 #if defined(G_OS_UNIX)
111 GList *_g_resolver_targets_from_res_query  (const gchar      *rrname,
112                                             guchar           *answer,
113                                             gint              len,
114                                             gint              herr,
115                                             GError          **error);
116 #elif defined(G_OS_WIN32)
117 GList *_g_resolver_targets_from_DnsQuery   (const gchar      *rrname,
118                                             DNS_STATUS        status,
119                                             DNS_RECORD       *results,
120                                             GError          **error);
121 #endif
122
123 gboolean _g_uri_parse_authority            (const char       *uri,
124                                             char            **host,
125                                             guint16          *port,
126                                             char            **userinfo);
127 gchar *  _g_uri_from_authority             (const gchar      *protocol,
128                                             const gchar      *host,
129                                             guint             port,
130                                             const gchar      *userinfo);
131
132 G_END_DECLS
133
134 #endif /* __G_NETWORKINGPRIVATE_H__ */