netsupp.h Source File (kdecore Library)

| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# netsupp.h

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

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:47:00 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001