Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

tpipv6.h

Go to the documentation of this file.
00001 /*++
00002 
00003 Copyright (c) 2000 Microsoft Corporation
00004 
00005 Module Name:
00006 
00007     tpipv6.h
00008 
00009 Abstract:
00010 
00011     This module contains IPv6-specific extensions, and address family
00012     independent extensions to Winsock for the IPv6 Technology Preview.
00013 
00014 --*/
00015 
00016 #ifndef _TPIPV6_
00017 #define _TPIPV6_
00018 
00019 #ifdef _MSC_VER
00020 #define TPIPV6_INLINE __inline
00021 #else
00022 #define TPIPV6_INLINE extern inline /* GNU style */
00023 #endif
00024 
00025 #ifdef __cplusplus
00026 #define TPIPV6_EXTERN extern "C"
00027 #else
00028 #define TPIPV6_EXTERN extern
00029 #endif
00030 
00031 #ifdef _WINSOCK2API_ 
00032 /* This section gets included if winsock2.h is included */
00033 
00034 #ifndef IPPROTO_IPV6
00035 
00036 #define IPPROTO_IPV6 41
00037 
00038 typedef unsigned __int64 u_int64;
00039 
00040 //
00041 // Portable socket structure.
00042 //
00043 
00044 //
00045 // Desired design of maximum size and alignment.
00046 // These are implementation specific.
00047 //
00048 #define _SS_MAXSIZE 128                  // Maximum size.
00049 #define _SS_ALIGNSIZE (sizeof(__int64))  // Desired alignment. 
00050 
00051 //
00052 // Definitions used for sockaddr_storage structure paddings design.
00053 //
00054 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (short))
00055 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (short) + _SS_PAD1SIZE \
00056                                                     + _SS_ALIGNSIZE))
00057 
00058 struct sockaddr_storage {
00059     short ss_family;               // Address family.
00060     char __ss_pad1[_SS_PAD1SIZE];  // 6 byte pad, this is to make
00061                                    // implementation specific pad up to
00062                                    // alignment field that follows explicit
00063                                    // in the data structure.
00064     __int64 __ss_align;            // Field to force desired structure.
00065     char __ss_pad2[_SS_PAD2SIZE];  // 112 byte pad to achieve desired size;
00066                                    // _SS_MAXSIZE value minus size of
00067                                    // ss_family, __ss_pad1, and
00068                                    // __ss_align fields is 112.
00069 };
00070 
00071 typedef struct sockaddr_storage SOCKADDR_STORAGE;
00072 typedef struct sockaddr_storage *PSOCKADDR_STORAGE;
00073 typedef struct sockaddr_storage FAR *LPSOCKADDR_STORAGE;
00074 
00075 #endif /* !IPPROTO_IPV6 */
00076 #endif /* _WINSOCK2API_ */
00077 
00078 #ifdef _WS2TCPIP_H_ 
00079 /* This section gets included if ws2tcpip.h is included */
00080 
00081 #ifndef IPV6_JOIN_GROUP
00082 
00083 #define in6_addr in_addr6
00084 
00085 // Macro that works for both IPv4 and IPv6
00086 #define SS_PORT(ssp) (((struct sockaddr_in*)(ssp))->sin_port)
00087 
00088 #define IN6ADDR_ANY_INIT        { 0 }
00089 #define IN6ADDR_LOOPBACK_INIT   { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
00090 
00091 TPIPV6_EXTERN const struct in6_addr in6addr_any;
00092 TPIPV6_EXTERN const struct in6_addr in6addr_loopback;
00093 
00094 TPIPV6_INLINE int
00095 IN6_ADDR_EQUAL(const struct in6_addr *a, const struct in6_addr *b)
00096 {
00097     return (memcmp(a, b, sizeof(struct in6_addr)) == 0);
00098 }
00099 
00100 TPIPV6_INLINE int
00101 IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *a)
00102 {
00103     return IN6_ADDR_EQUAL(a, &in6addr_any);
00104 }
00105 
00106 TPIPV6_INLINE int
00107 IN6_IS_ADDR_LOOPBACK(const struct in6_addr *a)
00108 {
00109     return IN6_ADDR_EQUAL(a, &in6addr_loopback);
00110 }
00111 
00112 TPIPV6_INLINE int
00113 IN6_IS_ADDR_MULTICAST(const struct in6_addr *a)
00114 {
00115     return (a->s6_addr[0] == 0xff);
00116 }
00117 
00118 TPIPV6_INLINE int
00119 IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a)
00120 {
00121     return ((a->s6_addr[0] == 0xfe) &&
00122             ((a->s6_addr[1] & 0xc0) == 0x80));
00123 }
00124 
00125 TPIPV6_INLINE int
00126 IN6_IS_ADDR_SITELOCAL(const struct in6_addr *a)
00127 {
00128     return ((a->s6_addr[0] == 0xfe) &&
00129             ((a->s6_addr[1] & 0xc0) == 0xc0));
00130 }
00131 
00132 TPIPV6_INLINE int
00133 IN6_IS_ADDR_V4MAPPED(const struct in6_addr *a)
00134 {
00135     return ((a->s6_addr[0] == 0) &&
00136             (a->s6_addr[1] == 0) &&
00137             (a->s6_addr[2] == 0) &&
00138             (a->s6_addr[3] == 0) &&
00139             (a->s6_addr[4] == 0) &&
00140             (a->s6_addr[5] == 0) &&
00141             (a->s6_addr[6] == 0) &&
00142             (a->s6_addr[7] == 0) &&
00143             (a->s6_addr[8] == 0) &&
00144             (a->s6_addr[9] == 0) &&
00145             (a->s6_addr[10] == 0xff) &&
00146             (a->s6_addr[11] == 0xff));
00147 }
00148 
00149 TPIPV6_INLINE int
00150 IN6_IS_ADDR_V4COMPAT(const struct in6_addr *a)
00151 {
00152     return ((a->s6_addr[0] == 0) &&
00153             (a->s6_addr[1] == 0) &&
00154             (a->s6_addr[2] == 0) &&
00155             (a->s6_addr[3] == 0) &&
00156             (a->s6_addr[4] == 0) &&
00157             (a->s6_addr[5] == 0) &&
00158             (a->s6_addr[6] == 0) &&
00159             (a->s6_addr[7] == 0) &&
00160             (a->s6_addr[8] == 0) &&
00161             (a->s6_addr[9] == 0) &&
00162             (a->s6_addr[10] == 0) &&
00163             (a->s6_addr[11] == 0) &&
00164             !((a->s6_addr[12] == 0) &&
00165               (a->s6_addr[13] == 0) &&
00166               (a->s6_addr[14] == 0) &&
00167               ((a->s6_addr[15] == 0) ||
00168                (a->s6_addr[15] == 1))));
00169 }
00170 
00171 TPIPV6_INLINE int
00172 IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *a)
00173 {
00174     return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 1);
00175 }
00176 
00177 TPIPV6_INLINE int
00178 IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *a)
00179 {
00180     return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 2);
00181 }
00182 
00183 TPIPV6_INLINE int
00184 IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *a)
00185 {
00186     return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 5);
00187 }
00188 
00189 TPIPV6_INLINE int
00190 IN6_IS_ADDR_MC_ORGLOCAL(const struct in6_addr *a)
00191 {
00192     return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 8);
00193 }
00194 
00195 TPIPV6_INLINE int
00196 IN6_IS_ADDR_MC_GLOBAL(const struct in6_addr *a)
00197 {
00198     return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 0xe);
00199 }
00200 
00201 /* Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP */
00202 
00203 typedef struct ipv6_mreq {
00204     struct in6_addr ipv6mr_multiaddr;  // IPv6 multicast address.
00205     unsigned int    ipv6mr_interface;  // Interface index.
00206 } IPV6_MREQ;
00207 
00208 //
00209 // Socket options at the IPPROTO_IPV6 level.
00210 //
00211 #define IPV6_UNICAST_HOPS       4  // Set/get IP unicast hop limit.
00212 #define IPV6_MULTICAST_IF       9  // Set/get IP multicast interface.
00213 #define IPV6_MULTICAST_HOPS     10 // Set/get IP multicast ttl.
00214 #define IPV6_MULTICAST_LOOP     11 // Set/get IP multicast loopback.
00215 #define IPV6_ADD_MEMBERSHIP     12 // Add an IP group membership.
00216 #define IPV6_DROP_MEMBERSHIP    13 // Drop an IP group membership.
00217 #define IPV6_JOIN_GROUP         IPV6_ADD_MEMBERSHIP
00218 #define IPV6_LEAVE_GROUP        IPV6_DROP_MEMBERSHIP
00219 
00220 //
00221 // Socket options at the IPPROTO_UDP level.
00222 //
00223 #define UDP_CHECKSUM_COVERAGE   20  // Set/get UDP-Lite checksum coverage.
00224 
00225 //
00226 // Error codes from getaddrinfo().
00227 //
00228 #define EAI_AGAIN       WSATRY_AGAIN
00229 #define EAI_BADFLAGS    WSAEINVAL
00230 #define EAI_FAIL        WSANO_RECOVERY
00231 #define EAI_FAMILY      WSAEAFNOSUPPORT
00232 #define EAI_MEMORY      WSA_NOT_ENOUGH_MEMORY
00233 #define EAI_NODATA      WSANO_DATA
00234 #define EAI_NONAME      WSAHOST_NOT_FOUND
00235 #define EAI_SERVICE     WSATYPE_NOT_FOUND
00236 #define EAI_SOCKTYPE    WSAESOCKTNOSUPPORT
00237 
00238 //
00239 // Structure used in getaddrinfo() call.
00240 //
00241 typedef struct addrinfo {
00242     int ai_flags;              // AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST.
00243     int ai_family;             // PF_xxx.
00244     int ai_socktype;           // SOCK_xxx.
00245     int ai_protocol;           // 0 or IPPROTO_xxx for IPv4 and IPv6.
00246     size_t ai_addrlen;         // Length of ai_addr.
00247     char *ai_canonname;        // Canonical name for nodename.
00248     struct sockaddr *ai_addr;  // Binary address.
00249     struct addrinfo *ai_next;  // Next structure in linked list.
00250 } ADDRINFO, FAR * LPADDRINFO;
00251 
00252 //
00253 // Flags used in "hints" argument to getaddrinfo().
00254 //
00255 #define AI_PASSIVE     0x1  // Socket address will be used in bind() call.
00256 #define AI_CANONNAME   0x2  // Return canonical name in first ai_canonname.
00257 #define AI_NUMERICHOST 0x4  // Nodename must be a numeric address string.
00258 
00259 #ifdef __cplusplus
00260 extern "C" {
00261 #endif
00262 
00263 WINSOCK_API_LINKAGE
00264 int
00265 WSAAPI
00266 getaddrinfo(
00267     IN const char FAR * nodename,
00268     IN const char FAR * servname,
00269     IN const struct addrinfo FAR * hints,
00270     OUT struct addrinfo FAR * FAR * res
00271     );
00272 
00273 #if INCL_WINSOCK_API_TYPEDEFS
00274 typedef
00275 int
00276 (WSAAPI * LPFN_GETADDRINFO)(
00277     IN const char FAR * nodename,
00278     IN const char FAR * servname,
00279     IN const struct addrinfo FAR * hints,
00280     OUT struct addrinfo FAR * FAR * res
00281     );
00282 #endif
00283 
00284 WINSOCK_API_LINKAGE
00285 void
00286 WSAAPI
00287 freeaddrinfo(
00288     IN struct addrinfo FAR * ai
00289     );
00290 
00291 #if INCL_WINSOCK_API_TYPEDEFS
00292 typedef
00293 void
00294 (WSAAPI * LPFN_FREEADDRINFO)(
00295     IN struct addrinfo FAR * ai
00296     );
00297 #endif
00298 
00299 #ifdef UNICODE
00300 #define gai_strerror   gai_strerrorW
00301 #else
00302 #define gai_strerror   gai_strerrorA
00303 #endif  /* UNICODE */
00304 
00305 // WARNING: The gai_strerror inline functions below use static buffers, 
00306 // and hence are not thread-safe.  We'll use buffers long enough to hold 
00307 // 1k characters.  Any system error messages longer than this will be 
00308 // returned as empty strings.  However 1k should work for the error codes 
00309 // used by getaddrinfo().
00310 #define GAI_STRERROR_BUFFER_SIZE 1024
00311 
00312 TPIPV6_INLINE 
00313 char *
00314 gai_strerrorA(
00315     IN int ecode)
00316 {
00317     DWORD dwMsgLen;
00318     static char buff[GAI_STRERROR_BUFFER_SIZE + 1];
00319 
00320     dwMsgLen = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
00321                              |FORMAT_MESSAGE_IGNORE_INSERTS,
00322                               NULL,
00323                               ecode,
00324                               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00325                               (LPSTR)buff,
00326                               GAI_STRERROR_BUFFER_SIZE,
00327                               NULL);
00328 
00329     return buff;
00330 }
00331 
00332 TPIPV6_INLINE 
00333 WCHAR *
00334 gai_strerrorW(
00335     IN int ecode
00336     )
00337 {
00338     DWORD dwMsgLen;
00339     static WCHAR buff[GAI_STRERROR_BUFFER_SIZE + 1];
00340 
00341     dwMsgLen = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
00342                              |FORMAT_MESSAGE_IGNORE_INSERTS,
00343                               NULL,
00344                               ecode,
00345                               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00346                               (LPWSTR)buff,
00347                               GAI_STRERROR_BUFFER_SIZE,
00348                               NULL);
00349 
00350     return buff;
00351 }
00352 
00353 typedef int socklen_t;
00354 
00355 WINSOCK_API_LINKAGE
00356 int
00357 WSAAPI
00358 getnameinfo(
00359     IN  const struct sockaddr FAR * sa,
00360     IN  socklen_t       salen,
00361     OUT char FAR *      host,
00362     IN  DWORD           hostlen,
00363     OUT char FAR *      serv,
00364     IN  DWORD           servlen,
00365     IN  int             flags
00366     );
00367 
00368 #if INCL_WINSOCK_API_TYPEDEFS
00369 typedef
00370 int
00371 (WSAAPI * LPFN_GETNAMEINFO)(
00372     IN  const struct sockaddr FAR * sa,
00373     IN  socklen_t       salen,
00374     OUT char FAR *      host,
00375     IN  DWORD           hostlen,
00376     OUT char FAR *      serv,
00377     IN  DWORD           servlen,
00378     IN  int             flags
00379     );
00380 #endif
00381 
00382 #define NI_MAXHOST  1025  // Max size of a fully-qualified domain name.
00383 #define NI_MAXSERV    32  // Max size of a service name.
00384 
00385 //
00386 // Flags for getnameinfo().
00387 //
00388 #define NI_NOFQDN       0x01  // Only return nodename portion for local hosts. 
00389 #define NI_NUMERICHOST  0x02  // Return numeric form of the host's address.
00390 #define NI_NAMEREQD     0x04  // Error if the host's name not in DNS.
00391 #define NI_NUMERICSERV  0x08  // Return numeric form of the service (port #).
00392 #define NI_DGRAM        0x10  // Service is a datagram service.
00393 
00394 #ifdef __cplusplus
00395 }
00396 #endif
00397 
00398 #endif /* !IPV6_JOIN_GROUP */
00399 #endif /* _WS2TCPIP_H_ */
00400 
00401 //
00402 // Unless the build environment is explicitly targeting
00403 // platforms that include built-in getaddrinfo() support,
00404 // include the backwards-compatibility version of the APIs.
00405 //
00406 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT <= 0x0500)
00407 #include <wspiapi.h>
00408 #endif
00409 
00410 #endif /* _TPIPV6_ */
00411 

Generated on Sun Aug 7 22:47:16 2005 for Dibbler - a portable DHCPv6 by  doxygen 1.3.9.1