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

KDECore

netsupp.h

Go to the documentation of this file.
00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (C) 2000-2003 Thiago Macieira <thiago.macieira@kdemail.net>>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Library General Public License
00016  *  along with this library; see the file COPYING.LIB.  If not, write to
00017  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  *  Boston, MA 02110-1301, USA.
00019  **/
00020 
00021 #ifndef _NETSUPP_H_
00022 #define _NETSUPP_H_
00023 
00024 #include <kdecore_export.h>
00025 
00026 #include <config.h>
00027 #include <config-network.h>
00028 
00029 #include <sys/socket.h>
00030 #include <netdb.h>
00031 //#include "ksockaddr.h"
00032 
00033 #ifdef __CYGWIN__
00034 typedef unsigned ksocklen_t;
00035 #endif
00036 
00037 /*
00038  * Seems some systems don't know about AF_LOCAL
00039  */
00040 #ifndef AF_LOCAL
00041 #define AF_LOCAL    AF_UNIX
00042 #define PF_LOCAL    PF_UNIX
00043 #endif
00044 
00045 #ifdef CLOBBER_IN6
00046 #define kde_in6_addr        in6_addr
00047 #define kde_sockaddr_in6    sockaddr_in6
00048 #endif
00049 
00050 /*** IPv6 structures that might be missing from some implementations ***/
00051 
00056 struct kde_in6_addr
00057 {
00058   unsigned char __u6_addr[16];
00059 };
00060 
00065 struct kde_sockaddr_in6
00066 {
00067 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
00068   quint8        sin6_len;
00069   quint8        sin6_family;
00070 #else  //HAVE_STRUCT_SOCKADDR_SA_LEN
00071   quint16       sin6_family;
00072 #endif
00073   unsigned short        sin6_port;  /* RFC says in_port_t */
00074   quint32       sin6_flowinfo;
00075   struct kde_in6_addr   sin6_addr;
00076   quint32       sin6_scope_id;
00077 };
00078 
00079 /* IPv6 test macros that could be missing from some implementations */
00080 
00081 #define KDE_IN6_IS_ADDR_UNSPECIFIED(a) \
00082     (((quint32 *) (a))[0] == 0 && ((quint32 *) (a))[1] == 0 && \
00083      ((quint32 *) (a))[2] == 0 && ((quint32 *) (a))[3] == 0)
00084 
00085 #define KDE_IN6_IS_ADDR_LOOPBACK(a) \
00086     (((quint32 *) (a))[0] == 0 && ((quint32 *) (a))[1] == 0 && \
00087      ((quint32 *) (a))[2] == 0 && ((quint32 *) (a))[3] == htonl (1))
00088 
00089 #define KDE_IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff)
00090 
00091 #define KDE_IN6_IS_ADDR_LINKLOCAL(a) \
00092     ((((quint32 *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000))
00093 
00094 #define KDE_IN6_IS_ADDR_SITELOCAL(a) \
00095     ((((quint32 *) (a))[0] & htonl (0xffc00000)) == htonl (0xfec00000))
00096 
00097 #define KDE_IN6_IS_ADDR_V4MAPPED(a) \
00098     ((((quint32 *) (a))[0] == 0) && (((quint32 *) (a))[1] == 0) && \
00099      (((quint32 *) (a))[2] == htonl (0xffff)))
00100 
00101 #define KDE_IN6_IS_ADDR_V4COMPAT(a) \
00102     ((((quint32 *) (a))[0] == 0) && (((quint32 *) (a))[1] == 0) && \
00103      (((quint32 *) (a))[2] == 0) && (ntohl (((quint32 *) (a))[3]) > 1))
00104 
00105 #define KDE_IN6_ARE_ADDR_EQUAL(a,b) \
00106     ((((quint32 *) (a))[0] == ((quint32 *) (b))[0]) && \
00107      (((quint32 *) (a))[1] == ((quint32 *) (b))[1]) && \
00108      (((quint32 *) (a))[2] == ((quint32 *) (b))[2]) && \
00109      (((quint32 *) (a))[3] == ((quint32 *) (b))[3]))
00110 
00111 #define KDE_IN6_IS_ADDR_MC_NODELOCAL(a) \
00112     (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0x1))
00113 
00114 #define KDE_IN6_IS_ADDR_MC_LINKLOCAL(a) \
00115     (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0x2))
00116 
00117 #define KDE_IN6_IS_ADDR_MC_SITELOCAL(a) \
00118     (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0x5))
00119 
00120 #define KDE_IN6_IS_ADDR_MC_ORGLOCAL(a) \
00121     (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0x8))
00122 
00123 #define KDE_IN6_IS_ADDR_MC_GLOBAL(a) \
00124     (KDE_IN6_IS_ADDR_MULTICAST(a) && ((((quint8 *) (a))[1] & 0xf) == 0xe))
00125 
00126 #ifdef NEED_IN6_TESTS
00127 # define IN6_IS_ADDR_UNSPECIFIED    KDE_IN6_IS_ADDR_UNSPECIFIED
00128 # define IN6_IS_ADDR_LOOPBACK       KDE_IN6_IS_ADDR_LOOPBACK
00129 # define IN6_IS_ADDR_MULTICAST      KDE_IN6_IS_ADDR_MULTICAST
00130 # define IN6_IS_ADDR_LINKLOCAL      KDE_IN6_IS_ADDR_LINKLOCAL
00131 # define IN6_IS_ADDR_SITELOCAL      KDE_IN6_IS_ADDR_SITELOCAL
00132 # define IN6_IS_ADDR_V4MAPPED       KDE_IN6_IS_ADDR_V4MAPPED
00133 # define IN6_IS_ADDR_V4COMPAT       KDE_IN6_IS_ADDR_V4COMPAT
00134 # define IN6_ARE_ADDR_EQUAL     KDE_IN6_ARE_ADDR_EQUAL
00135 # define IN6_IS_ADDR_MC_NODELOCAL   KDE_IN6_IS_ADDR_MC_NODELOCAL
00136 # define IN6_IS_ADDR_MC_LINKLOCAL   KDE_IN6_IS_ADDR_MC_LINKLOCAL
00137 # define IN6_IS_ADDR_MC_SITELOCAL   KDE_IN6_IS_ADDR_MC_SITELOCAL
00138 # define IN6_IS_ADDR_MC_ORGLOCAL    KDE_IN6_IS_ADDR_MC_ORGLOCAL
00139 # define IN6_IS_ADDR_MC_GLOBAL      KDE_IN6_IS_ADDR_MC_GLOBAL
00140 #endif
00141 
00142 /* Special internal structure */
00143 
00144 #define KAI_SYSTEM      0   /* data is all-system */
00145 #define KAI_LOCALUNIX       1   /* data contains a Unix addrinfo allocated by us */
00146 #define KAI_QDNS        2   /* data contains data derived from QDns */
00147 
00148 struct addrinfo;        /* forward declaration; this could be needed */
00149 
00158 struct kde_addrinfo
00159 {
00160   struct addrinfo *data;
00161   int origin;
00162 };
00163 
00164 extern KDECORE_EXPORT int kde_getaddrinfo(const char *name, const char *service,
00165                const struct addrinfo* hint,
00166                struct kde_addrinfo** result);
00167 extern KDECORE_EXPORT void kde_freeaddrinfo(struct kde_addrinfo *p);
00168 
00169 #if !defined(HAVE_GETADDRINFO) || defined(HAVE_BROKEN_GETADDRINFO)
00170 
00171 # ifndef HAVE_STRUCT_ADDRINFO
00172 
00175 struct addrinfo
00176 {
00177   int ai_flags;         /* Input flags.  */
00178   int ai_family;        /* Protocol family for socket.  */
00179   int ai_socktype;      /* Socket type.  */
00180   int ai_protocol;      /* Protocol for socket.  */
00181   int ai_addrlen;       /* Length of socket address.  */
00182   struct sockaddr *ai_addr; /* Socket address for socket.  */
00183   char *ai_canonname;       /* Canonical name for service location.  */
00184   struct addrinfo *ai_next; /* Pointer to next in list.  */
00185 };
00186 # endif
00187 
00188 # ifdef AI_PASSIVE
00189 #  undef AI_PASSIVE
00190 #  undef AI_CANONNAME
00191 #  undef AI_NUMERICHOST
00192 # endif
00193 
00194 /* Possible values for `ai_flags' field in `addrinfo' structure.  */
00195 # define AI_PASSIVE 1   /* Socket address is intended for `bind'.  */
00196 # define AI_CANONNAME   2   /* Request for canonical name.  */
00197 # define AI_NUMERICHOST 4   /* Don't use name resolution.  */
00198 
00199 # ifdef EAI_ADDRFAMILY
00200 #  undef EAI_ADDRFAMILY
00201 #  undef EAI_AGAIN
00202 #  undef EAI_BADFLAGS
00203 #  undef EAI_FAIL
00204 #  undef EAI_FAMILY
00205 #  undef EAI_MEMORY
00206 #  undef EAI_NODATA
00207 #  undef EAI_NONAME
00208 #  undef EAI_SERVICE
00209 #  undef EAI_SOCKTYPE
00210 #  undef EAI_SYSTEM
00211 # endif
00212 
00213 /* Error values for `getaddrinfo' function.  */
00214 # ifndef EAI_ADDRFAMILY
00215 #  define EAI_ADDRFAMILY    1   /* Address family for NAME not supported.  */
00216 # endif
00217 # ifndef EAI_AGAIN
00218 #  define EAI_AGAIN 2   /* Temporary failure in name resolution.  */
00219 # endif
00220 # ifndef EAI_BADFLAGS
00221 #  define EAI_BADFLAGS  3   /* Invalid value for `ai_flags' field.  */
00222 # endif
00223 # ifndef EAI_FAIL
00224 #  define EAI_FAIL  4   /* Non-recoverable failure in name res.  */
00225 # endif
00226 # ifndef EAI_FAMILY
00227 #  define EAI_FAMILY    5   /* `ai_family' not supported.  */
00228 # endif
00229 # ifndef EAI_MEMORY
00230 #  define EAI_MEMORY    6   /* Memory allocation failure.  */
00231 # endif
00232 # ifndef EAI_NODATA
00233 #  define EAI_NODATA    7   /* No address associated with NAME.  */
00234 # endif
00235 # ifndef EAI_NONAME
00236 #  define EAI_NONAME    8   /* NAME or SERVICE is unknown.  */
00237 # endif
00238 # ifndef EAI_SERVICE
00239 #  define EAI_SERVICE   9   /* SERVICE not supported for `ai_socktype'.  */
00240 # endif
00241 # ifndef EAI_SOCKTYPE
00242 #  define EAI_SOCKTYPE  10  /* `ai_socktype' not supported.  */
00243 # endif
00244 # ifndef EAI_SYSTEM
00245 #  define EAI_SYSTEM    11  /* System error returned in `errno'.  */
00246 # endif
00247 
00248 /*
00249  * These are specified in the RFC
00250  * We won't undefine them. If someone defined them to a different value
00251  * the preprocessor will generate an error
00252  */
00253 # define NI_MAXHOST 1025
00254 # define NI_MAXSERV 32
00255 
00256 # ifdef NI_NUMERICHOST
00257 #  undef NI_NUMERICHOST
00258 #  undef NI_NUMERICSERV
00259 #  undef NI_NOFQDN
00260 #  undef NI_NAMEREQD
00261 #  undef NI_DGRAM
00262 # endif
00263 
00264 # define NI_NUMERICHOST 1   /* Don't try to look up hostname.  */
00265 # define NI_NUMERICSERV 2   /* Don't convert port number to name.  */
00266 # define NI_NOFQDN  4   /* Only return nodename portion.  */
00267 # define NI_NAMEREQD    8   /* Don't return numeric addresses.  */
00268 # define NI_DGRAM   16  /* Look up UDP service rather than TCP.  */
00269 
00270 # ifdef gai_strerror
00271 #  undef gai_strerror
00272 # endif
00273 
00274 # ifdef getaddrinfo
00275 #  undef getaddrinfo
00276 # endif
00277 
00278 # ifdef freeaddrinfo
00279 #  undef freeaddrinfo
00280 # endif
00281 
00282 # ifdef getnameinfo
00283 #  undef getnameinfo
00284 # endif
00285 
00286 namespace KDE
00287 {
00289   extern KDECORE_EXPORT int getaddrinfo(const char *name, const char *service,
00290              const struct addrinfo* hint,
00291              struct addrinfo** result);
00293   extern KDECORE_EXPORT void freeaddrinfo(struct addrinfo* ai);
00295   extern KDECORE_EXPORT int getnameinfo(const struct sockaddr *sa,
00296              kde_socklen_t salen,
00297              char *host, size_t hostlen,
00298              char *serv, size_t servlen,
00299              int flags);
00300 }
00301 
00302 # ifndef HAVE_GAI_STRERROR_PROTO
00303 
00304 extern KDECORE_EXPORT char *gai_strerror(int errorcode);
00305 # endif
00306   
00307 # define getaddrinfo    KDE::getaddrinfo
00308 # define freeaddrinfo   KDE::freeaddrinfo
00309 # define getnameinfo    KDE::getnameinfo
00310 
00311 
00312 #endif
00313 
00314 #ifndef HAVE_INET_PTON
00315 
00316 namespace KDE
00317 {
00319   extern KDECORE_EXPORT int inet_pton(int af, const char *cp, void* buf);
00320 }
00321 
00322 # define inet_pton  KDE::inet_pton
00323 #endif
00324 
00325 #ifndef HAVE_INET_NTOP
00326 
00327 namespace KDE
00328 {
00330   extern KDECORE_EXPORT const char* inet_ntop(int af, const void *cp, char *buf, size_t len);
00331 }
00332 
00333 # define inet_ntop  KDE::inet_ntop
00334 #endif
00335 
00336 #endif

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal