• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
netsupp.h
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 "tdelibs_export.h"
25 
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29 
30 #include <sys/socket.h>
31 #include <netdb.h>
32 //#include "ksockaddr.h"
33 
34 #ifdef __CYGWIN__
35 typedef unsigned ksocklen_t;
36 #endif
37 
38 /*
39  * Seems some systems don't know about AF_LOCAL
40  */
41 #ifndef AF_LOCAL
42 #define AF_LOCAL AF_UNIX
43 #define PF_LOCAL PF_UNIX
44 #endif
45 
46 #ifdef CLOBBER_IN6
47 #define kde_in6_addr in6_addr
48 #define kde_sockaddr_in6 sockaddr_in6
49 #endif
50 
51 /*** IPv6 structures that might be missing from some implementations ***/
52 
57 struct kde_in6_addr
58 {
59  unsigned char __u6_addr[16];
60 };
61 
66 struct kde_sockaddr_in6
67 {
68 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
69  TQ_UINT8 sin6_len;
70  TQ_UINT8 sin6_family;
71 #else //HAVE_STRUCT_SOCKADDR_SA_LEN
72  TQ_UINT16 sin6_family;
73 #endif
74  unsigned short sin6_port; /* RFC says in_port_t */
75  TQ_UINT32 sin6_flowinfo;
76  struct kde_in6_addr sin6_addr;
77  TQ_UINT32 sin6_scope_id;
78 };
79 
80 /* IPv6 test macros that could be missing from some implementations */
81 
82 #define KDE_IN6_IS_ADDR_UNSPECIFIED(a) \
83  (((TQ_UINT32 *) (a))[0] == 0 && ((TQ_UINT32 *) (a))[1] == 0 && \
84  ((TQ_UINT32 *) (a))[2] == 0 && ((TQ_UINT32 *) (a))[3] == 0)
85 
86 #define KDE_IN6_IS_ADDR_LOOPBACK(a) \
87  (((TQ_UINT32 *) (a))[0] == 0 && ((TQ_UINT32 *) (a))[1] == 0 && \
88  ((TQ_UINT32 *) (a))[2] == 0 && ((TQ_UINT32 *) (a))[3] == htonl (1))
89 
90 #define KDE_IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff)
91 
92 #define KDE_IN6_IS_ADDR_LINKLOCAL(a) \
93  ((((TQ_UINT32 *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000))
94 
95 #define KDE_IN6_IS_ADDR_SITELOCAL(a) \
96  ((((TQ_UINT32 *) (a))[0] & htonl (0xffc00000)) == htonl (0xfec00000))
97 
98 #define KDE_IN6_IS_ADDR_V4MAPPED(a) \
99  ((((TQ_UINT32 *) (a))[0] == 0) && (((TQ_UINT32 *) (a))[1] == 0) && \
100  (((TQ_UINT32 *) (a))[2] == htonl (0xffff)))
101 
102 #define KDE_IN6_IS_ADDR_V4COMPAT(a) \
103  ((((TQ_UINT32 *) (a))[0] == 0) && (((TQ_UINT32 *) (a))[1] == 0) && \
104  (((TQ_UINT32 *) (a))[2] == 0) && (ntohl (((TQ_UINT32 *) (a))[3]) > 1))
105 
106 #define KDE_IN6_ARE_ADDR_EQUAL(a,b) \
107  ((((TQ_UINT32 *) (a))[0] == ((TQ_UINT32 *) (b))[0]) && \
108  (((TQ_UINT32 *) (a))[1] == ((TQ_UINT32 *) (b))[1]) && \
109  (((TQ_UINT32 *) (a))[2] == ((TQ_UINT32 *) (b))[2]) && \
110  (((TQ_UINT32 *) (a))[3] == ((TQ_UINT32 *) (b))[3]))
111 
112 #define KDE_IN6_IS_ADDR_MC_NODELOCAL(a) \
113  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((TQ_UINT8 *) (a))[1] & 0xf) == 0x1))
114 
115 #define KDE_IN6_IS_ADDR_MC_LINKLOCAL(a) \
116  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((TQ_UINT8 *) (a))[1] & 0xf) == 0x2))
117 
118 #define KDE_IN6_IS_ADDR_MC_SITELOCAL(a) \
119  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((TQ_UINT8 *) (a))[1] & 0xf) == 0x5))
120 
121 #define KDE_IN6_IS_ADDR_MC_ORGLOCAL(a) \
122  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((TQ_UINT8 *) (a))[1] & 0xf) == 0x8))
123 
124 #define KDE_IN6_IS_ADDR_MC_GLOBAL(a) \
125  (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((TQ_UINT8 *) (a))[1] & 0xf) == 0xe))
126 
127 #ifdef NEED_IN6_TESTS
128 # define IN6_IS_ADDR_UNSPECIFIED KDE_IN6_IS_ADDR_UNSPECIFIED
129 # define IN6_IS_ADDR_LOOPBACK KDE_IN6_IS_ADDR_LOOPBACK
130 # define IN6_IS_ADDR_MULTICAST KDE_IN6_IS_ADDR_MULTICAST
131 # define IN6_IS_ADDR_LINKLOCAL KDE_IN6_IS_ADDR_LINKLOCAL
132 # define IN6_IS_ADDR_SITELOCAL KDE_IN6_IS_ADDR_SITELOCAL
133 # define IN6_IS_ADDR_V4MAPPED KDE_IN6_IS_ADDR_V4MAPPED
134 # define IN6_IS_ADDR_V4COMPAT KDE_IN6_IS_ADDR_V4COMPAT
135 # define IN6_ARE_ADDR_EQUAL KDE_IN6_ARE_ADDR_EQUAL
136 # define IN6_IS_ADDR_MC_NODELOCAL KDE_IN6_IS_ADDR_MC_NODELOCAL
137 # define IN6_IS_ADDR_MC_LINKLOCAL KDE_IN6_IS_ADDR_MC_LINKLOCAL
138 # define IN6_IS_ADDR_MC_SITELOCAL KDE_IN6_IS_ADDR_MC_SITELOCAL
139 # define IN6_IS_ADDR_MC_ORGLOCAL KDE_IN6_IS_ADDR_MC_ORGLOCAL
140 # define IN6_IS_ADDR_MC_GLOBAL KDE_IN6_IS_ADDR_MC_GLOBAL
141 #endif
142 
143 /* Special internal structure */
144 
145 #define KAI_SYSTEM 0 /* data is all-system */
146 #define KAI_LOCALUNIX 1 /* data contains a Unix addrinfo allocated by us */
147 #define KAI_QDNS 2 /* data contains data derived from TQDns */
148 
149 struct addrinfo; /* forward declaration; this could be needed */
150 
159 struct kde_addrinfo
160 {
161  struct addrinfo *data;
162  int origin;
163 };
164 
165 extern TDECORE_EXPORT int kde_getaddrinfo(const char *name, const char *service,
166  const struct addrinfo* hint,
167  struct kde_addrinfo** result);
168 extern TDECORE_EXPORT void kde_freeaddrinfo(struct kde_addrinfo *p);
169 
170 #if !defined(HAVE_GETADDRINFO) || defined(HAVE_BROKEN_GETADDRINFO)
171 
172 # ifndef HAVE_STRUCT_ADDRINFO
176 struct addrinfo
177 {
178  int ai_flags;
179  int ai_family;
180  int ai_socktype;
181  int ai_protocol;
182  int ai_addrlen;
183  struct sockaddr *ai_addr;
184  char *ai_canonname;
185  struct addrinfo *ai_next;
186 };
187 # endif
188 
189 # ifdef AI_PASSIVE
190 # undef AI_PASSIVE
191 # undef AI_CANONNAME
192 # undef AI_NUMERICHOST
193 # endif
194 
195 /* Possible values for `ai_flags' field in `addrinfo' structure. */
196 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
197 # define AI_CANONNAME 2 /* Request for canonical name. */
198 # define AI_NUMERICHOST 4 /* Don't use name resolution. */
199 
200 # ifdef EAI_ADDRFAMILY
201 # undef EAI_ADDRFAMILY
202 # undef EAI_AGAIN
203 # undef EAI_BADFLAGS
204 # undef EAI_FAIL
205 # undef EAI_FAMILY
206 # undef EAI_MEMORY
207 # undef EAI_NODATA
208 # undef EAI_NONAME
209 # undef EAI_SERVICE
210 # undef EAI_SOCKTYPE
211 # undef EAI_SYSTEM
212 # endif
213 
214 /* Error values for `getaddrinfo' function. */
215 # define EAI_ADDRFAMILY 1 /* Address family for NAME not supported. */
216 # define EAI_AGAIN 2 /* Temporary failure in name resolution. */
217 # define EAI_BADFLAGS 3 /* Invalid value for `ai_flags' field. */
218 # define EAI_FAIL 4 /* Non-recoverable failure in name res. */
219 # define EAI_FAMILY 5 /* `ai_family' not supported. */
220 # define EAI_MEMORY 6 /* Memory allocation failure. */
221 # define EAI_NODATA 7 /* No address associated with NAME. */
222 # define EAI_NONAME 8 /* NAME or SERVICE is unknown. */
223 # define EAI_SERVICE 9 /* SERVICE not supported for `ai_socktype'. */
224 # define EAI_SOCKTYPE 10 /* `ai_socktype' not supported. */
225 # define EAI_SYSTEM 11 /* System error returned in `errno'. */
226 
227 /*
228  * These are specified in the RFC
229  * We won't undefine them. If someone defined them to a different value
230  * the preprocessor will generate an error
231  */
232 # define NI_MAXHOST 1025
233 # define NI_MAXSERV 32
234 
235 # ifdef NI_NUMERICHOST
236 # undef NI_NUMERICHOST
237 # undef NI_NUMERICSERV
238 # undef NI_NOFQDN
239 # undef NI_NAMEREQD
240 # undef NI_DGRAM
241 # endif
242 
243 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
244 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
245 # define NI_NOFQDN 4 /* Only return nodename portion. */
246 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
247 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
248 
249 # ifdef getaddrinfo
250 # undef getaddrinfo
251 # endif
252 
253 namespace KDE
254 {
256  extern TDECORE_EXPORT int getaddrinfo(const char *name, const char *service,
257  const struct addrinfo* hint,
258  struct addrinfo** result);
260  extern TDECORE_EXPORT void freeaddrinfo(struct addrinfo* ai);
262  extern TDECORE_EXPORT char *gai_strerror(int errorcode);
264  extern TDECORE_EXPORT int getnameinfo(const struct sockaddr *sa,
265  unsigned int salen,
266  char *host, size_t hostlen,
267  char *serv, size_t servlen,
268  int flags);
269 }
270 
271 # define getaddrinfo KDE::getaddrinfo
272 # define freeaddrinfo KDE::freeaddrinfo
273 # define gai_strerror KDE::gai_strerror
274 # define getnameinfo KDE::getnameinfo
275 
276 
277 #endif
278 
279 #ifndef HAVE_INET_PTON
280 
281 namespace KDE
282 {
284  extern TDECORE_EXPORT int inet_pton(int af, const char *cp, void* buf);
285 }
286 
287 # define inet_pton KDE::inet_pton
288 #endif
289 
290 #ifndef HAVE_INET_NTOP
291 
292 namespace KDE
293 {
295  extern TDECORE_EXPORT const char* inet_ntop(int af, const void *cp, char *buf, size_t len);
296 }
297 
298 # define inet_ntop KDE::inet_ntop
299 #endif
300 
301 #endif
KDE
Namespace for general KDE functions.
Definition: ktypelist.h:350

tdecore

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

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.1
This website is maintained by Timothy Pearson.