• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • network
netsupp.h
Go to the documentation of this file.
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2000-2003 Thiago Macieira <thiago.macieira@kdemail.net>>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library 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  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  **/
20 
21 #ifndef _NETSUPP_H_
22 #define _NETSUPP_H_
23 
24 #include <kdecore_export.h>
25 
26 #include <config.h>
27 #include <config-network.h>
28 
29 #include <sys/socket.h>
30 #include <netdb.h>
31 //#include "ksockaddr.h"
32 
33 
34 /*
35  * Seems some systems don't know about AF_LOCAL
36  */
37 #ifndef AF_LOCAL
38 #define AF_LOCAL AF_UNIX
39 #define PF_LOCAL PF_UNIX
40 #endif
41 
42 #ifdef CLOBBER_IN6
43 #define kde_in6_addr in6_addr
44 #define kde_sockaddr_in6 sockaddr_in6
45 #endif
46 
47 /*** IPv6 structures that might be missing from some implementations ***/
48 
53 struct kde_in6_addr
54 {
55  unsigned char __u6_addr[16];
56 };
57 
62 struct kde_sockaddr_in6
63 {
64 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
65  quint8 sin6_len;
66  quint8 sin6_family;
67 #else //HAVE_STRUCT_SOCKADDR_SA_LEN
68  quint16 sin6_family;
69 #endif
70  unsigned short sin6_port; /* RFC says in_port_t */
71  quint32 sin6_flowinfo;
72  struct kde_in6_addr sin6_addr;
73  quint32 sin6_scope_id;
74 };
75 
76 /* IPv6 test macros that could be missing from some implementations */
77 
78 #define KDE_IN6_IS_ADDR_UNSPECIFIED(a) \
79  (((quint32 *) (a))[0] == 0 && ((quint32 *) (a))[1] == 0 && \
80  ((quint32 *) (a))[2] == 0 && ((quint32 *) (a))[3] == 0)
81 
82 #define KDE_IN6_IS_ADDR_LOOPBACK(a) \
83  (((quint32 *) (a))[0] == 0 && ((quint32 *) (a))[1] == 0 && \
84  ((quint32 *) (a))[2] == 0 && ((quint32 *) (a))[3] == htonl (1))
85 
86 #define KDE_IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff)
87 
88 #define KDE_IN6_IS_ADDR_LINKLOCAL(a) \
89  ((((quint32 *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000))
90 
91 #define KDE_IN6_IS_ADDR_SITELOCAL(a) \
92  ((((quint32 *) (a))[0] & htonl (0xffc00000)) == htonl (0xfec00000))
93 
94 #define KDE_IN6_IS_ADDR_V4MAPPED(a) \
95  ((((quint32 *) (a))[0] == 0) && (((quint32 *) (a))[1] == 0) && \
96  (((quint32 *) (a))[2] == htonl (0xffff)))
97 
98 #define KDE_IN6_IS_ADDR_V4COMPAT(a) \
99  ((((quint32 *) (a))[0] == 0) && (((quint32 *) (a))[1] == 0) && \
100  (((quint32 *) (a))[2] == 0) && (ntohl (((quint32 *) (a))[3]) > 1))
101 
102 #define KDE_IN6_ARE_ADDR_EQUAL(a,b) \
103  ((((quint32 *) (a))[0] == ((quint32 *) (b))[0]) && \
104  (((quint32 *) (a))[1] == ((quint32 *) (b))[1]) && \
105  (((quint32 *) (a))[2] == ((quint32 *) (b))[2]) && \
106  (((quint32 *) (a))[3] == ((quint32 *) (b))[3]))
107 
108 #define KDE_IN6_IS_ADDR_MC_NODELOCAL(a) \
109  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0x1))
110 
111 #define KDE_IN6_IS_ADDR_MC_LINKLOCAL(a) \
112  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0x2))
113 
114 #define KDE_IN6_IS_ADDR_MC_SITELOCAL(a) \
115  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0x5))
116 
117 #define KDE_IN6_IS_ADDR_MC_ORGLOCAL(a) \
118  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0x8))
119 
120 #define KDE_IN6_IS_ADDR_MC_GLOBAL(a) \
121  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0xe))
122 
123 #ifdef NEED_IN6_TESTS
124 # define IN6_IS_ADDR_UNSPECIFIED KDE_IN6_IS_ADDR_UNSPECIFIED
125 # define IN6_IS_ADDR_LOOPBACK KDE_IN6_IS_ADDR_LOOPBACK
126 # define IN6_IS_ADDR_MULTICAST KDE_IN6_IS_ADDR_MULTICAST
127 # define IN6_IS_ADDR_LINKLOCAL KDE_IN6_IS_ADDR_LINKLOCAL
128 # define IN6_IS_ADDR_SITELOCAL KDE_IN6_IS_ADDR_SITELOCAL
129 # define IN6_IS_ADDR_V4MAPPED KDE_IN6_IS_ADDR_V4MAPPED
130 # define IN6_IS_ADDR_V4COMPAT KDE_IN6_IS_ADDR_V4COMPAT
131 # define IN6_ARE_ADDR_EQUAL KDE_IN6_ARE_ADDR_EQUAL
132 # define IN6_IS_ADDR_MC_NODELOCAL KDE_IN6_IS_ADDR_MC_NODELOCAL
133 # define IN6_IS_ADDR_MC_LINKLOCAL KDE_IN6_IS_ADDR_MC_LINKLOCAL
134 # define IN6_IS_ADDR_MC_SITELOCAL KDE_IN6_IS_ADDR_MC_SITELOCAL
135 # define IN6_IS_ADDR_MC_ORGLOCAL KDE_IN6_IS_ADDR_MC_ORGLOCAL
136 # define IN6_IS_ADDR_MC_GLOBAL KDE_IN6_IS_ADDR_MC_GLOBAL
137 #endif
138 
139 /* Special internal structure */
140 
141 #define KAI_SYSTEM 0 /* data is all-system */
142 #define KAI_LOCALUNIX 1 /* data contains a Unix addrinfo allocated by us */
143 #define KAI_QDNS 2 /* data contains data derived from QDns */
144 
145 struct addrinfo; /* forward declaration; this could be needed */
146 
155 struct kde_addrinfo
156 {
157  struct addrinfo *data;
158  int origin;
159 };
160 
161 extern KDECORE_EXPORT int kde_getaddrinfo(const char *name, const char *service,
162  const struct addrinfo* hint,
163  struct kde_addrinfo** result);
164 extern KDECORE_EXPORT void kde_freeaddrinfo(struct kde_addrinfo *p);
165 
166 #if !defined(HAVE_GETADDRINFO) || defined(HAVE_BROKEN_GETADDRINFO)
167 
168 # ifndef HAVE_STRUCT_ADDRINFO
169 
172 struct addrinfo
173 {
174  int ai_flags; /* Input flags. */
175  int ai_family; /* Protocol family for socket. */
176  int ai_socktype; /* Socket type. */
177  int ai_protocol; /* Protocol for socket. */
178  int ai_addrlen; /* Length of socket address. */
179  struct sockaddr *ai_addr; /* Socket address for socket. */
180  char *ai_canonname; /* Canonical name for service location. */
181  struct addrinfo *ai_next; /* Pointer to next in list. */
182 };
183 # endif
184 
185 # ifdef AI_PASSIVE
186 # undef AI_PASSIVE
187 # undef AI_CANONNAME
188 # undef AI_NUMERICHOST
189 # endif
190 
191 /* Possible values for `ai_flags' field in `addrinfo' structure. */
192 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
193 # define AI_CANONNAME 2 /* Request for canonical name. */
194 # define AI_NUMERICHOST 4 /* Don't use name resolution. */
195 
196 # ifdef EAI_ADDRFAMILY
197 # undef EAI_ADDRFAMILY
198 # undef EAI_AGAIN
199 # undef EAI_BADFLAGS
200 # undef EAI_FAIL
201 # undef EAI_FAMILY
202 # undef EAI_MEMORY
203 # undef EAI_NODATA
204 # undef EAI_NONAME
205 # undef EAI_SERVICE
206 # undef EAI_SOCKTYPE
207 # undef EAI_SYSTEM
208 # endif
209 
210 /* Error values for `getaddrinfo' function. */
211 # ifndef EAI_ADDRFAMILY
212 # define EAI_ADDRFAMILY 1 /* Address family for NAME not supported. */
213 # endif
214 # ifndef EAI_AGAIN
215 # define EAI_AGAIN 2 /* Temporary failure in name resolution. */
216 # endif
217 # ifndef EAI_BADFLAGS
218 # define EAI_BADFLAGS 3 /* Invalid value for `ai_flags' field. */
219 # endif
220 # ifndef EAI_FAIL
221 # define EAI_FAIL 4 /* Non-recoverable failure in name res. */
222 # endif
223 # ifndef EAI_FAMILY
224 # define EAI_FAMILY 5 /* `ai_family' not supported. */
225 # endif
226 # ifndef EAI_MEMORY
227 # define EAI_MEMORY 6 /* Memory allocation failure. */
228 # endif
229 # ifndef EAI_NODATA
230 # define EAI_NODATA 7 /* No address associated with NAME. */
231 # endif
232 # ifndef EAI_NONAME
233 # define EAI_NONAME 8 /* NAME or SERVICE is unknown. */
234 # endif
235 # ifndef EAI_SERVICE
236 # define EAI_SERVICE 9 /* SERVICE not supported for `ai_socktype'. */
237 # endif
238 # ifndef EAI_SOCKTYPE
239 # define EAI_SOCKTYPE 10 /* `ai_socktype' not supported. */
240 # endif
241 # ifndef EAI_SYSTEM
242 # define EAI_SYSTEM 11 /* System error returned in `errno'. */
243 # endif
244 
245 /*
246  * These are specified in the RFC
247  * We won't undefine them. If someone defined them to a different value
248  * the preprocessor will generate an error
249  */
250 # define NI_MAXHOST 1025
251 # define NI_MAXSERV 32
252 
253 # ifdef NI_NUMERICHOST
254 # undef NI_NUMERICHOST
255 # undef NI_NUMERICSERV
256 # undef NI_NOFQDN
257 # undef NI_NAMEREQD
258 # undef NI_DGRAM
259 # endif
260 
261 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
262 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
263 # define NI_NOFQDN 4 /* Only return nodename portion. */
264 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
265 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
266 
267 # ifdef gai_strerror
268 # undef gai_strerror
269 # endif
270 
271 # ifdef getaddrinfo
272 # undef getaddrinfo
273 # endif
274 
275 # ifdef freeaddrinfo
276 # undef freeaddrinfo
277 # endif
278 
279 # ifdef getnameinfo
280 # undef getnameinfo
281 # endif
282 
283 namespace KDE
284 {
286  extern KDECORE_EXPORT int getaddrinfo(const char *name, const char *service,
287  const struct addrinfo* hint,
288  struct addrinfo** result);
290  extern KDECORE_EXPORT void freeaddrinfo(struct addrinfo* ai);
292  extern KDECORE_EXPORT int getnameinfo(const struct sockaddr *sa,
293  kde_socklen_t salen,
294  char *host, size_t hostlen,
295  char *serv, size_t servlen,
296  int flags);
297 }
298 
299 # ifndef HAVE_GAI_STRERROR_PROTO
300 
301 extern KDECORE_EXPORT char *gai_strerror(int errorcode);
302 # endif
303 
304 # define getaddrinfo KDE::getaddrinfo
305 # define freeaddrinfo KDE::freeaddrinfo
306 # define getnameinfo KDE::getnameinfo
307 
308 
309 #endif
310 
311 #ifndef HAVE_INET_PTON
312 
313 namespace KDE
314 {
316  extern KDECORE_EXPORT int inet_pton(int af, const char *cp, void* buf);
317 }
318 
319 # define inet_pton KDE::inet_pton
320 #endif
321 
322 #ifndef HAVE_INET_NTOP
323 
324 namespace KDE
325 {
327  extern KDECORE_EXPORT const char* inet_ntop(int af, const void *cp, char *buf, size_t len);
328 }
329 
330 # define inet_ntop KDE::inet_ntop
331 #endif
332 
333 #endif
kde_sockaddr_in6::sin6_scope_id
quint32 sin6_scope_id
Definition: netsupp.h:73
kde_in6_addr::__u6_addr
unsigned char __u6_addr[16]
Definition: netsupp.h:55
kdecore_export.h
kde_sockaddr_in6::sin6_addr
struct kde_in6_addr sin6_addr
Definition: netsupp.h:72
KDE::inet_ntop
const char * inet_ntop(int af, const void *cp, char *buf, size_t len)
Definition: netsupp.cpp:1040
kde_freeaddrinfo
void kde_freeaddrinfo(struct kde_addrinfo *p)
Definition: netsupp.cpp:101
KDE::getaddrinfo
int getaddrinfo(const char *name, const char *service, const struct addrinfo *hint, struct addrinfo **result)
Definition: netsupp.cpp:784
quint32
KDE::inet_pton
int inet_pton(int af, const char *cp, void *buf)
Definition: netsupp.cpp:1142
addrinfo::ai_canonname
char * ai_canonname
Definition: netsupp.h:180
addrinfo::ai_addrlen
int ai_addrlen
Definition: netsupp.h:178
kde_addrinfo::data
struct addrinfo * data
Definition: netsupp.h:157
kde_sockaddr_in6::sin6_family
quint16 sin6_family
Definition: netsupp.h:68
kde_addrinfo::origin
int origin
Definition: netsupp.h:158
kde_sockaddr_in6::sin6_flowinfo
quint32 sin6_flowinfo
Definition: netsupp.h:71
addrinfo::ai_protocol
int ai_protocol
Definition: netsupp.h:177
KDE::freeaddrinfo
void freeaddrinfo(struct addrinfo *ai)
Definition: netsupp.cpp:884
addrinfo::ai_socktype
int ai_socktype
Definition: netsupp.h:176
kde_in6_addr
Definition: netsupp.h:53
gai_strerror
char * gai_strerror(int errorcode)
Definition: netsupp.cpp:890
addrinfo::ai_next
struct addrinfo * ai_next
Definition: netsupp.h:181
kde_sockaddr_in6::sin6_port
unsigned short sin6_port
Definition: netsupp.h:70
kde_sockaddr_in6
Definition: netsupp.h:62
kde_getaddrinfo
int kde_getaddrinfo(const char *name, const char *service, const struct addrinfo *hint, struct kde_addrinfo **result)
Definition: netsupp.cpp:230
KDE::getnameinfo
int getnameinfo(const struct sockaddr *sa, kde_socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
Definition: netsupp.cpp:944
addrinfo
Definition: netsupp.h:172
addrinfo::ai_flags
int ai_flags
Definition: netsupp.h:174
kde_addrinfo
Definition: netsupp.h:155
addrinfo::ai_addr
struct sockaddr * ai_addr
Definition: netsupp.h:179
addrinfo::ai_family
int ai_family
Definition: netsupp.h:175
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:12 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal