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