idnits 2.17.00 (12 Aug 2021) /tmp/idnits56469/draft-ietf-ipngwg-rfc2553bis-05.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Looks like you're using RFC 2026 boilerplate. This must be updated to follow RFC 3978/3979, as updated by RFC 4748. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing expiration date. The document expiration date should appear on the first and last page. ** The document seems to lack a 1id_guidelines paragraph about 6 months document validity -- however, there's a paragraph with a matching beginning. Boilerplate error? == No 'Intended status' indicated for this document; assuming Proposed Standard == The page length should not exceed 58 lines per page, but there was 32 longer pages, the longest (page 3) being 67 lines == It seems as if not all pages are separated by form feeds - found 0 form feeds but 32 pages Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. ** There are 37 instances of too long lines in the document, the longest one being 8 characters in excess of 72. ** The abstract seems to contain references ([4]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. == There are 1 instance of lines with non-RFC2606-compliant FQDNs in the document. ** The document seems to lack a both a reference to RFC 2119 and the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. RFC 2119 keyword, line 321: '...field SHOULD be set to zero by an impl...' Miscellaneous warnings: ---------------------------------------------------------------------------- == Line 694 has weird spacing: '...ned int if_na...' == Line 726 has weird spacing: '...ned int if_i...' == Line 752 has weird spacing: '... void if_fr...' == Line 782 has weird spacing: '... int hoplim...' == Line 803 has weird spacing: '... int hoplim...' == (1 more instance...) -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (February 2002) is 7400 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: '16' is mentioned on line 277, but not defined == Missing Reference: '512' is mentioned on line 1302, but not defined == Missing Reference: '514' is mentioned on line 1302, but not defined ** Obsolete normative reference: RFC 2460 (ref. '1') (Obsoleted by RFC 8200) ** Obsolete normative reference: RFC 2373 (ref. '2') (Obsoleted by RFC 3513) -- Possible downref: Non-RFC (?) normative reference: ref. '3' ** Obsolete normative reference: RFC 2292 (ref. '4') (Obsoleted by RFC 3542) -- Possible downref: Non-RFC (?) normative reference: ref. '5' -- Possible downref: Non-RFC (?) normative reference: ref. '6' -- Possible downref: Non-RFC (?) normative reference: ref. '7' ** Obsolete normative reference: RFC 2765 (ref. '8') (Obsoleted by RFC 6145) Summary: 12 errors (**), 0 flaws (~~), 13 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 IPNG Working Group R.E. Gilligan 3 INTERNET-DRAFT: draft-ietf-ipngwg-rfc2553bis-05.txt Cache Flow 4 Obsoletes RFC 2553 S. Thomson 5 Cisco 6 J. Bound 7 J. McCann 8 Compaq 9 W. R. Stevens 10 February 2002 12 Basic Socket Interface Extensions for IPv6 14 16 Status of this Memo 18 This document is an Internet-Draft and is in full conformance with 19 all provisions of Section 10 of RFC2026. 21 This document is a submission by the Internet Protocol IPv6 Working 22 Group of the Internet Engineering Task Force (IETF). Comments should 23 be submitted to the ipng@sunroof.eng.sun.com mailing list. 25 Internet-Drafts are working documents of the Internet Engineering 26 Task Force (IETF), its areas, and its working groups. Note that 27 other groups may also distribute working documents as Internet- 28 Drafts. 30 Internet-Drafts are draft documents valid for a maximum of six months 31 and may be updated, replaced, or obsoleted by other documents at any 32 time. It is inappropriate to use Internet- Drafts as reference 33 material or to cite them other than as "work in progress." 35 The list of current Internet-Drafts can be accessed at 36 http://www.ietf.org/ietf/1id-abstracts.txt 38 The list of Internet-Draft Shadow Directories can be accessed at 39 http://www.ietf.org/shadow.html. 41 Abstract 43 The de facto standard application program interface (API) for TCP/IP 44 applications is the "sockets" interface. Although this API was 45 developed for Unix in the early 1980s it has also been implemented on a 46 wide variety of non-Unix systems. TCP/IP applications written using the 47 sockets API have in the past enjoyed a high degree of portability and we 48 would like the same portability with IPv6 applications. But changes are 49 required to the sockets API to support IPv6 and this memo describes 50 these changes. These include a new socket address structure to carry 51 IPv6 addresses, new address conversion functions, and some new socket 52 options. These extensions are designed to provide access to the basic 53 IPv6 features required by TCP and UDP applications, including 54 multicasting, while introducing a minimum of change into the system and 55 providing complete compatibility for existing IPv4 applications. 56 Additional extensions for advanced IPv6 features (raw sockets and access 57 to the IPv6 extension headers) are defined in another document [4]. 59 Table of Contents: 61 1. Introduction.................................................4 62 2. Design Considerations........................................4 63 2.1 What Needs to be Changed....................................4 64 2.2 Data Types..................................................6 65 2.3 Headers.....................................................6 66 2.4 Structures...................................................6 67 3. Socket Interface.............................................6 68 3.1 IPv6 Address Family and Protocol Family.....................6 69 3.2 IPv6 Address Structure......................................6 70 3.3 Socket Address Structure for 4.3BSD-Based Systems...........7 71 3.4 Socket Address Structure for 4.4BSD-Based Systems...........8 72 3.5 The Socket Functions........................................9 73 3.6 Compatibility with IPv4 Applications.......................10 74 3.7 Compatibility with IPv4 Nodes..............................10 75 3.8 IPv6 Wildcard Address......................................10 76 3.9 IPv6 Loopback Address......................................11 77 3.10 Portability Additions.....................................12 78 4. Interface Identification....................................14 79 4.1 Name-to-Index..............................................14 80 4.2 Index-to-Name..............................................14 81 4.3 Return All Interface Names and Indexes......................15 82 4.4 Free Memory................................................15 83 5. Socket Options..............................................16 84 5.1 Unicast Hop Limit..........................................16 85 5.2 Sending and Receiving Multicast Packets....................17 86 5.3 IPV6_V6ONLY option for AF_INET6 Sockets....................18 87 6. Library Functions...........................................19 88 6.1 Protocol-Independent Nodename and Service Name Translation.19 89 6.2 Socket Address Structure to Nodename and Service Name......24 90 6.3 Address Conversion Functions...............................26 91 6.4 Address Testing Macros.....................................27 92 7. Summary of New Definitions..................................28 93 8. Security Considerations.....................................29 94 9. Year 2000 Considerations....................................29 95 Changes made to rfc2553bis-04 to rfc2553bis-05.................29 96 Changes made to rfc2553bis-03 to rfc2553bis-04.................30 97 Changes made to rfc2553bis-02 to rfc2553bis-03.................30 98 Changes made to rfc2553bis-01 to rfc2553bis-02.................30 99 Changes made to rfc2553bis-00 to rfc2553bis-01.................30 100 Changes made rfc2553 to rfc2553bis-00:.........................30 101 Acknowledgments................................................31 102 References.....................................................31 103 Authors' Addresses.............................................32 104 1. Introduction 106 While IPv4 addresses are 32 bits long, IPv6 interfaces are identified by 107 128-bit addresses. The socket interface makes the size of an IP address 108 quite visible to an application; virtually all TCP/IP applications for 109 BSD-based systems have knowledge of the size of an IP address. Those 110 parts of the API that expose the addresses must be changed to 111 accommodate the larger IPv6 address size. IPv6 also introduces new 112 features (e.g., traffic class and flowlabel), some of which must be made 113 visible to applications via the API. This memo defines a set of 114 extensions to the socket interface to support the larger address size 115 and new features of IPv6. 117 2. Design Considerations 119 There are a number of important considerations in designing changes to 120 this well-worn API: 122 - The API changes should provide both source and binary 123 compatibility for programs written to the original API. That 124 is, existing program binaries should continue to operate when 125 run on a system supporting the new API. In addition, existing 126 applications that are re-compiled and run on a system supporting 127 the new API should continue to operate. Simply put, the API 128 changes for IPv6 should not break existing programs. An additional 129 mechanism for implementations to verify this is to verify the new 130 symbols are protected by Feature Test Macros as described in IEEE Std 131 1003.1-200x. (Such Feature Test Macros are not defined by this RFC.) 133 - The changes to the API should be as small as possible in order 134 to simplify the task of converting existing IPv4 applications to 135 IPv6. 137 - Where possible, applications should be able to use this 138 API to interoperate with both IPv6 and IPv4 hosts. Applications 139 should not need to know which type of host they are 140 communicating with. 142 - IPv6 addresses carried in data structures should be 64-bit 143 aligned. This is necessary in order to obtain optimum 144 performance on 64-bit machine architectures. 146 Because of the importance of providing IPv4 compatibility in the API, 147 these extensions are explicitly designed to operate on machines that 148 provide complete support for both IPv4 and IPv6. A subset of this API 149 could probably be designed for operation on systems that support only 150 IPv6. However, this is not addressed in this memo. 152 2.1 What Needs to be Changed 154 The socket interface API consists of a few distinct components: 156 - Core socket functions. 158 - Address data structures. 160 - Name-to-address translation functions. 162 - Address conversion functions. 164 The core socket functions -- those functions that deal with such things 165 as setting up and tearing down TCP connections, and sending and 166 receiving UDP packets -- were designed to be transport independent. 167 Where protocol addresses are passed as function arguments, they are 168 carried via opaque pointers. A protocol-specific address data structure 169 is defined for each protocol that the socket functions support. 170 Applications must cast pointers to these protocol-specific address 171 structures into pointers to the generic "sockaddr" address structure 172 when using the socket functions. These functions need not change for 173 IPv6, but a new IPv6-specific address data structure is needed. 175 The "sockaddr_in" structure is the protocol-specific data structure for 176 IPv4. This data structure actually includes 8-octets of unused space, 177 and it is tempting to try to use this space to adapt the sockaddr_in 178 structure to IPv6. Unfortunately, the sockaddr_in structure is not 179 large enough to hold the 16-octet IPv6 address as well as the other 180 information (address family and port number) that is needed. So a new 181 address data structure must be defined for IPv6. 183 IPv6 addresses are scoped [2] so they could be link-local, site, 184 organization, global, or other scopes at this time undefined. To 185 support applications that want to be able to identify a set of 186 interfaces for a specific scope, the IPv6 sockaddr_in structure must 187 support a field that can be used by an implementation to identify a set 188 of interfaces identifying the scope for an IPv6 address. 190 The name-to-address translation functions in the socket interface are 191 gethostbyname() and gethostbyaddr(). These are left as is and new 192 functions are defined to support IPv4 and IPv6. The new API is based on 193 the IEEE Std 1003.1-200x draft [3] and specifies a new nodename-to- 194 address translation function which is protocol independent. This 195 function can also be used with IPv4 and IPv6. 197 The address conversion functions -- inet_ntoa() and inet_addr() -- 198 convert IPv4 addresses between binary and printable form. These 199 functions are quite specific to 32-bit IPv4 addresses. We have designed 200 two analogous functions that convert both IPv4 and IPv6 addresses, and 201 carry an address type parameter so that they can be extended to other 202 protocol families as well. 204 Finally, a few miscellaneous features are needed to support IPv6. New 205 interfaces are needed to support the IPv6 traffic class, flow label, and 206 hop limit header fields. New socket options are needed to control the 207 sending and receiving of IPv6 multicast packets. 209 The socket interface will be enhanced in the future to provide access to 210 other IPv6 features. These extensions are described in [4]. 212 2.2 Data Types 214 The data types of the structure elements given in this memo are intended 215 to track the relevant standards. uintN_t means an unsigned integer of 216 exactly N bits (e.g., uint16_t). 218 2.3 Headers 220 When function prototypes and structures are shown we show the headers 221 that must be #included to cause that item to be defined. 223 2.4 Structures 225 When structures are described the members shown are the ones that must 226 appear in an implementation. Additional, nonstandard members may also 227 be defined by an implementation. As an additional precaution 228 nonstandard members could be verified by Feature Test Macros as 229 described in IEEE Std 1003.1-200x. (Such Feature Test Macros are not 230 defined by this RFC.) 232 The ordering shown for the members of a structure is the recommended 233 ordering, given alignment considerations of multibyte members, but an 234 implementation may order the members differently. 236 3. Socket Interface 238 This section specifies the socket interface changes for IPv6. 240 3.1 IPv6 Address Family and Protocol Family 242 A new address family name, AF_INET6, is defined in . The 243 AF_INET6 definition distinguishes between the original sockaddr_in 244 address data structure, and the new sockaddr_in6 data structure. 246 A new protocol family name, PF_INET6, is defined in . 247 Like most of the other protocol family names, this will usually be 248 defined to have the same value as the corresponding address family name: 250 #define PF_INET6 AF_INET6 252 The PF_INET6 is used in the first argument to the socket() function to 253 indicate that an IPv6 socket is being created. 255 3.2 IPv6 Address Structure 257 A new in6_addr structure holds a single IPv6 address and is defined as a 258 result of including : 260 struct in6_addr { 261 uint8_t s6_addr[16]; /* IPv6 address */ 262 }; 264 This data structure contains an array of sixteen 8-bit elements, which 265 make up one 128-bit IPv6 address. The IPv6 address is stored in network 266 byte order. 268 The structure in6_addr above is usually implemented with an embedded 269 union with extra fields that force the desired alignment level in a 270 manner similar to BSD implementations of "struct in_addr". Those 271 additional implementation details are omitted here for simplicity. 273 An example is as follows: 275 struct in6_addr { 276 union { 277 uint8_t _S6_u8[16]; 278 uint32_t _S6_u32[4]; 279 uint64_t _S6_u64[2]; 280 } _S6_un; 281 }; 282 #define s6_addr _S6_un._S6_u8 284 3.3 Socket Address Structure for 4.3BSD-Based Systems 286 In the socket interface, a different protocol-specific data structure is 287 defined to carry the addresses for each protocol suite. Each protocol- 288 specific data structure is designed so it can be cast into a protocol- 289 independent data structure -- the "sockaddr" structure. Each has a 290 "family" field that overlays the "sa_family" of the sockaddr data 291 structure. This field identifies the type of the data structure. 293 The sockaddr_in structure is the protocol-specific address data 294 structure for IPv4. It is used to pass addresses between applications 295 and the system in the socket functions. The following sockaddr_in6 296 structure holds IPv6 addresses and is defined as a result of including 297 the header: 299 struct sockaddr_in6 { 300 sa_family_t sin6_family; /* AF_INET6 */ 301 in_port_t sin6_port; /* transport layer port # */ 302 uint32_t sin6_flowinfo; /* IPv6 traffic class & flow info */ 303 struct in6_addr sin6_addr; /* IPv6 address */ 304 uint32_t sin6_scope_id; /* set of interfaces for a scope */ 305 }; 307 This structure is designed to be compatible with the sockaddr data 308 structure used in the 4.3BSD release. 310 The sin6_family field identifies this as a sockaddr_in6 structure. This 311 field overlays the sa_family field when the buffer is cast to a sockaddr 312 data structure. The value of this field must be AF_INET6. 314 The sin6_port field contains the 16-bit UDP or TCP port number. This 315 field is used in the same way as the sin_port field of the sockaddr_in 316 structure. The port number is stored in network byte order. 318 The sin6_flowinfo field is a 32-bit field that contains two pieces of 319 information: the traffic class and the flow label. The contents and 320 interpretation of this member is specified in [1]. The sin6_flowinfo 321 field SHOULD be set to zero by an implementation prior to using the 322 sockaddr_in6 structure by an application on receive operations. 324 The sin6_addr field is a single in6_addr structure (defined in the 325 previous section). This field holds one 128-bit IPv6 address. The 326 address is stored in network byte order. 328 The ordering of elements in this structure is specifically designed so 329 that when sin6_addr field is aligned on a 64-bit boundary, the start of 330 the structure will also be aligned on a 64-bit boundary. This is done 331 for optimum performance on 64-bit architectures. 333 The sin6_scope_id field is a 32-bit integer that identifies a set of 334 interfaces as appropriate for the scope of the address carried in the 335 sin6_addr field [2][5][6][7]. For a link scope sin6_addr, sin6_scope_id 336 would be an interface index. For a site scope sin6_addr, sin6_scope_id 337 would be a site identifier. The mapping of sin6_scope_id to an 338 interface or set of interfaces is left to implementation and future 339 specifications on the subject of site identifiers. 341 Notice that the sockaddr_in6 structure will normally be larger than the 342 generic sockaddr structure. On many existing implementations the 343 sizeof(struct sockaddr_in) equals sizeof(struct sockaddr), with both 344 being 16 bytes. Any existing code that makes this assumption needs to 345 be examined carefully when converting to IPv6. 347 3.4 Socket Address Structure for 4.4BSD-Based Systems 349 The 4.4BSD release includes a small, but incompatible change to the 350 socket interface. The "sa_family" field of the sockaddr data structure 351 was changed from a 16-bit value to an 8-bit value, and the space saved 352 used to hold a length field, named "sa_len". The sockaddr_in6 data 353 structure given in the previous section cannot be correctly cast into 354 the newer sockaddr data structure. For this reason, the following 355 alternative IPv6 address data structure is provided to be used on 356 systems based on 4.4BSD. It is defined as a result of including the 357 header. 359 struct sockaddr_in6 { 360 uint8_t sin6_len; /* length of this struct */ 361 sa_family_t sin6_family; /* AF_INET6 */ 362 in_port_t sin6_port; /* transport layer port # */ 363 uint32_t sin6_flowinfo; /* IPv6 flow information */ 364 struct in6_addr sin6_addr; /* IPv6 address */ 365 uint32_t sin6_scope_id; /* set of interfaces for a scope */ 366 }; 368 The only differences between this data structure and the 4.3BSD variant 369 are the inclusion of the length field, and the change of the family 370 field to a 8-bit data type. The definitions of all the other fields are 371 identical to the structure defined in the previous section. 373 Systems that provide this version of the sockaddr_in6 data structure 374 must also declare SIN6_LEN as a result of including the 375 header. This macro allows applications to determine whether they are 376 being built on a system that supports the 4.3BSD or 4.4BSD variants of 377 the data structure. 379 3.5 The Socket Functions 381 Applications call the socket() function to create a socket descriptor 382 that represents a communication endpoint. The arguments to the socket() 383 function tell the system which protocol to use, and what format address 384 structure will be used in subsequent functions. For example, to create 385 an IPv4/TCP socket, applications make the call: 387 s = socket(PF_INET, SOCK_STREAM, 0); 389 To create an IPv4/UDP socket, applications make the call: 391 s = socket(PF_INET, SOCK_DGRAM, 0); 393 Applications may create IPv6/TCP and IPv6/UDP sockets (which may also 394 handle IPv4 communication as described in section 3.7) by simply using 395 the constant PF_INET6 instead of PF_INET in the first argument. For 396 example, to create an IPv6/TCP socket, applications make the call: 398 s = socket(PF_INET6, SOCK_STREAM, 0); 400 To create an IPv6/UDP socket, applications make the call: 402 s = socket(PF_INET6, SOCK_DGRAM, 0); 404 Once the application has created a PF_INET6 socket, it must use the 405 sockaddr_in6 address structure when passing addresses in to the system. 406 The functions that the application uses to pass addresses into the 407 system are: 409 bind() 410 connect() 411 sendmsg() 412 sendto() 414 The system will use the sockaddr_in6 address structure to return 415 addresses to applications that are using PF_INET6 sockets. The 416 functions that return an address from the system to an application are: 418 accept() 419 recvfrom() 420 recvmsg() 421 getpeername() 422 getsockname() 424 No changes to the syntax of the socket functions are needed to support 425 IPv6, since all of the "address carrying" functions use an opaque 426 address pointer, and carry an address length as a function argument. 428 3.6 Compatibility with IPv4 Applications 430 In order to support the large base of applications using the original 431 API, system implementations must provide complete source and binary 432 compatibility with the original API. This means that systems must 433 continue to support PF_INET sockets and the sockaddr_in address 434 structure. Applications must be able to create IPv4/TCP and IPv4/UDP 435 sockets using the PF_INET constant in the socket() function, as 436 described in the previous section. Applications should be able to hold 437 a combination of IPv4/TCP, IPv4/UDP, IPv6/TCP and IPv6/UDP sockets 438 simultaneously within the same process. 440 Applications using the original API should continue to operate as they 441 did on systems supporting only IPv4. That is, they should continue to 442 interoperate with IPv4 nodes. 444 3.7 Compatibility with IPv4 Nodes 446 The API also provides a different type of compatibility: the ability for 447 IPv6 applications to interoperate with IPv4 applications. This feature 448 uses the IPv4-mapped IPv6 address format defined in the IPv6 addressing 449 architecture specification [2]. This address format allows the IPv4 450 address of an IPv4 node to be represented as an IPv6 address. The IPv4 451 address is encoded into the low-order 32 bits of the IPv6 address, and 452 the high-order 96 bits hold the fixed prefix 0:0:0:0:0:FFFF. IPv4- 453 mapped addresses are written as follows: 455 ::FFFF: 457 These addresses can be generated automatically by the getaddrinfo() 458 function, when the specified host has only IPv4 addresses (as described 459 in Section 6.1 and 6.2). 461 Applications may use PF_INET6 sockets to open TCP connections to IPv4 462 nodes, or send UDP packets to IPv4 nodes, by simply encoding the 463 destination's IPv4 address as an IPv4-mapped IPv6 address, and passing 464 that address, within a sockaddr_in6 structure, in the connect() or 465 sendto() call. When applications use PF_INET6 sockets to accept TCP 466 connections from IPv4 nodes, or receive UDP packets from IPv4 nodes, the 467 system returns the peer's address to the application in the accept(), 468 recvfrom(), or getpeername() call using a sockaddr_in6 structure encoded 469 this way.. 471 Few applications will likely need to know which type of node they are 472 interoperating with. However, for those applications that do need to 473 know, the IN6_IS_ADDR_V4MAPPED() macro, defined in Section 6.7, is 474 provided. 476 3.8 IPv6 Wildcard Address 478 While the bind() function allows applications to select the source IP 479 address of UDP packets and TCP connections, applications often want the 480 system to select the source address for them. With IPv4, one specifies 481 the address as the symbolic constant INADDR_ANY (called the "wildcard" 482 address) in the bind() call, or simply omits the bind() entirely. 484 Since the IPv6 address type is a structure (struct in6_addr), a symbolic 485 constant can be used to initialize an IPv6 address variable, but cannot 486 be used in an assignment. Therefore systems provide the IPv6 wildcard 487 address in two forms. 489 The first version is a global variable named "in6addr_any" that is an 490 in6_addr structure. The extern declaration for this variable is defined 491 in : 493 extern const struct in6_addr in6addr_any; 495 Applications use in6addr_any similarly to the way they use INADDR_ANY in 496 IPv4. For example, to bind a socket to port number 23, but let the 497 system select the source address, an application could use the following 498 code: 500 struct sockaddr_in6 sin6; 501 . . . 502 sin6.sin6_family = AF_INET6; 503 sin6.sin6_flowinfo = 0; 504 sin6.sin6_port = htons(23); 505 sin6.sin6_addr = in6addr_any; /* structure assignment */ 506 . . . 507 if (bind(s, (struct sockaddr *) &sin6, sizeof(sin6)) == -1) 508 . . . 510 The other version is a symbolic constant named IN6ADDR_ANY_INIT and is 511 defined in . This constant can be used to initialize an 512 in6_addr structure: 514 struct in6_addr anyaddr = IN6ADDR_ANY_INIT; 516 Note that this constant can be used ONLY at declaration time. It can 517 not be used to assign a previously declared in6_addr structure. For 518 example, the following code will not work: 520 /* This is the WRONG way to assign an unspecified address */ 521 struct sockaddr_in6 sin6; 522 . . . 523 sin6.sin6_addr = IN6ADDR_ANY_INIT; /* will NOT compile */ 525 Be aware that the IPv4 INADDR_xxx constants are all defined in host byte 526 order but the IPv6 IN6ADDR_xxx constants and the IPv6 in6addr_xxx 527 externals are defined in network byte order. 529 3.9 IPv6 Loopback Address 531 Applications may need to send UDP packets to, or originate TCP 532 connections to, services residing on the local node. In IPv4, they can 533 do this by using the constant IPv4 address INADDR_LOOPBACK in their 534 connect(), sendto(), or sendmsg() call. 536 IPv6 also provides a loopback address to contact local TCP and UDP 537 services. Like the unspecified address, the IPv6 loopback address is 538 provided in two forms -- a global variable and a symbolic constant. 540 The global variable is an in6_addr structure named "in6addr_loopback." 541 The extern declaration for this variable is defined in : 543 extern const struct in6_addr in6addr_loopback; 545 Applications use in6addr_loopback as they would use INADDR_LOOPBACK in 546 IPv4 applications (but beware of the byte ordering difference mentioned 547 at the end of the previous section). For example, to open a TCP 548 connection to the local telnet server, an application could use the 549 following code: 551 struct sockaddr_in6 sin6; 552 . . . 553 sin6.sin6_family = AF_INET6; 554 sin6.sin6_flowinfo = 0; 555 sin6.sin6_port = htons(23); 556 sin6.sin6_addr = in6addr_loopback; /* structure assignment */ 557 . . . 558 if (connect(s, (struct sockaddr *) &sin6, sizeof(sin6)) == -1) 559 . . . 561 The symbolic constant is named IN6ADDR_LOOPBACK_INIT and is defined in 562 . It can be used at declaration time ONLY; for example: 564 struct in6_addr loopbackaddr = IN6ADDR_LOOPBACK_INIT; 566 Like IN6ADDR_ANY_INIT, this constant cannot be used in an assignment to 567 a previously declared IPv6 address variable. 569 3.10 Portability Additions 571 One simple addition to the sockets API that can help application writers 572 is the "struct sockaddr_storage". This data structure can simplify 573 writing portable code across multiple address families and platforms. 574 This data structure is designed with the following goals. 576 - Large enough to accommodate all supported protocol-specific address 577 structures. 578 - Aligned at an appropriate boundary so that pointers to it can be cast 579 as pointers to protocol specific address structures and used to 580 access the fields of those structures without alignment problems. 582 The sockaddr_storage structure contains field ss_family which is of type 583 sa_family_t. When a sockaddr_storage structure is cast to a sockaddr 584 structure, the ss_family field of the sockaddr_storage structure maps 585 onto the sa_family field of the sockaddr structure. When a 586 sockaddr_storage structure is cast as a protocol specific address 587 structure, the ss_family field maps onto a field of that structure that 588 is of type sa_family_t and that identifies the protocol's address 589 family. 591 An example implementation design of such a data structure would be as 592 follows. 594 /* 595 * Desired design of maximum size and alignment 596 */ 597 #define _SS_MAXSIZE 128 /* Implementation specific max size */ 598 #define _SS_ALIGNSIZE (sizeof (int64_t)) 599 /* Implementation specific desired alignment */ 600 /* 601 * Definitions used for sockaddr_storage structure paddings design. 602 */ 603 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (sa_family_t)) 604 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (sa_family_t)+ 605 _SS_PAD1SIZE + _SS_ALIGNSIZE)) 606 struct sockaddr_storage { 607 sa_family_t ss_family; /* address family */ 608 /* Following fields are implementation specific */ 609 char __ss_pad1[_SS_PAD1SIZE]; 610 /* 6 byte pad, this is to make implementation 611 /* specific pad up to alignment field that */ 612 /* follows explicit in the data structure */ 613 int64_t __ss_align; /* field to force desired structure */ 614 /* storage alignment */ 615 char __ss_pad2[_SS_PAD2SIZE]; 616 /* 112 byte pad to achieve desired size, */ 617 /* _SS_MAXSIZE value minus size of ss_family */ 618 /* __ss_pad1, __ss_align fields is 112 */ 619 }; 621 The above example implementation illustrates a data structure which 622 will align on a 64-bit boundary. An implementation-specific field 623 "_ss_align" along "_ss_pad1" is used to force a 64-bit alignment which 624 covers proper alignment good enough for needs of sockaddr_in6 (IPv6), 625 sockaddr_in (IPv4) address data structures. The size of padding fields 626 _ss_pad1 depends on the chosen alignment boundary. The size of padding 627 field _ss_pad2 depends on the value of overall size chosen for the total 628 size of the structure. This size and alignment are represented in the 629 above example by implementation specific (not required) constants 630 _SS_MAXSIZE (chosen value 128) and _SS_ALIGNMENT (with chosen value 8). 631 Constants _SS_PAD1SIZE (derived value 6) and _SS_PAD2SIZE (derived value 632 112) are also for illustration and not required. The implementation specific 633 definitions and structure field names above start with an underscore to 634 denote implementation private namespace. Portable code is not expected to 635 access or reference those fields or constants. 637 On implementations where sockaddr data structure includes a "sa_len", 638 field this data structure would look like this: 640 /* 641 * Definitions used for sockaddr_storage structure paddings design. 642 */ 643 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - 644 (sizeof (uint8_t) + sizeof (sa_family_t)) 645 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (sa_family_t)+ 646 _SS_PAD1SIZE + _SS_ALIGNSIZE)) 647 struct sockaddr_storage { 648 uint8_t ss_len; /* address length */ 649 sa_family_t ss_family; /* address family */ 650 /* Following fields are implementation specific */ 651 char __ss_pad1[_SS_PAD1SIZE]; 652 /* 6 byte pad, this is to make implementation 653 /* specific pad up to alignment field that */ 654 /* follows explicit in the data structure */ 655 int64_t __ss_align; /* field to force desired structure */ 656 /* storage alignment */ 657 char __ss_pad2[_SS_PAD2SIZE]; 658 /* 112 byte pad to achieve desired size, */ 659 /* _SS_MAXSIZE value minus size of ss_len, */ 660 /* __ss_family, __ss_pad1, __ss_align fields is 112 */ 661 }; 663 4. Interface Identification 665 This API uses an interface index (a small positive integer) to identify 666 the local interface on which a multicast group is joined (Section 5.3). 667 Additionally, the advanced API [4] uses these same interface indexes to 668 identify the interface on which a datagram is received, or to specify 669 the interface on which a datagram is to be sent. 671 Interfaces are normally known by names such as "le0", "sl1", "ppp2", and 672 the like. On Berkeley-derived implementations, when an interface is 673 made known to the system, the kernel assigns a unique positive integer 674 value (called the interface index) to that interface. These are small 675 positive integers that start at 1. (Note that 0 is never used for an 676 interface index.) There may be gaps so that there is no current 677 interface for a particular positive interface index. 679 This API defines two functions that map between an interface name and 680 index, a third function that returns all the interface names and 681 indexes, and a fourth function to return the dynamic memory allocated by 682 the previous function. How these functions are implemented is left up 683 to the implementation. 4.4BSD implementations can implement these 684 functions using the existing sysctl() function with the NET_RT_IFLIST 685 command. Other implementations may wish to use ioctl() for this 686 purpose. 688 4.1 Name-to-Index 690 The first function maps an interface name into its corresponding index. 692 #include 694 unsigned int if_nametoindex(const char *ifname); 696 If ifname is the name of an interface, the if_nametoindex() function 697 shall return the interface index corresponding to name ifname; 698 otherwise, it shall return zero. No errors are defined. 700 4.2 Index-to-Name 702 The second function maps an interface index into its corresponding name. 704 #include 706 char *if_indextoname(unsigned int ifindex, char *ifname); 708 When this function is called, the ifname argument shall point to a 709 buffer of at least IF_NAMESIZE bytes. The function shall place in this 710 buffer the name of the interface with index ifindex. (IF_NAMESIZE is 711 also defined in and its value includes a terminating null 712 byte at the end of the interface name.) If ifindex is an interface 713 index, then the function shall return the value supplied in ifname, 714 which points to a buffer now containing the interface name. Otherwise, 715 the function shall return a NULL pointer and set errno to indicate the 716 error. If there is no interface corresponding to the specified index, 717 errno is set to ENXIO. If there was a system error (such as running out 718 of memory), errno would be set to the proper value (e.g., ENOMEM). 720 4.3 Return All Interface Names and Indexes 722 The if_nameindex structure holds the information about a single 723 interface and is defined as a result of including the header. 725 struct if_nameindex { 726 unsigned int if_index; /* 1, 2, ... */ 727 char *if_name; /* null terminated name: "le0", ... */ 728 }; 730 The final function returns an array of if_nameindex structures, one 731 structure per interface. 733 #include 735 struct if_nameindex *if_nameindex(void); 737 The end of the array of structures is indicated by a structure with an 738 if_index of 0 and an if_name of NULL. The function returns a NULL 739 pointer upon an error, and would set errno to the appropriate value. 741 The memory used for this array of structures along with the interface 742 names pointed to by the if_name members is obtained dynamically. This 743 memory is freed by the next function. 745 4.4 Free Memory 747 The following function frees the dynamic memory that was allocated by 748 if_nameindex(). 750 #include 752 void if_freenameindex(struct if_nameindex *ptr); 754 The ptr argument shall be a pointer that was returned by if_nameindex(). 755 After if_freenameindex() has been called, the application shall not use 756 the array of which ptr is the address. 758 Currently net/if.h doesn't have prototype definitions for functions and 759 it is recommended that these definitions be defined in net/if.h as well 760 as the struct if_nameindex{}. 762 5. Socket Options 764 A number of new socket options are defined for IPv6. All of these new 765 options are at the IPPROTO_IPV6 level. That is, the "level" parameter 766 in the getsockopt() and setsockopt() calls is IPPROTO_IPV6 when using 767 these options. The constant name prefix IPV6_ is used in all of the new 768 socket options. This serves to clearly identify these options as 769 applying to IPv6. 771 The declaration for IPPROTO_IPV6, the new IPv6 socket options, and 772 related constants defined in this section are obtained by including the 773 header . 775 5.1 Unicast Hop Limit 777 A new setsockopt() option controls the hop limit used in outgoing 778 unicast IPv6 packets. The name of this option is IPV6_UNICAST_HOPS, and 779 it is used at the IPPROTO_IPV6 layer. The following example illustrates 780 how it is used: 782 int hoplimit = 10; 784 if (setsockopt(s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, 785 (char *) &hoplimit, sizeof(hoplimit)) == -1) 786 perror("setsockopt IPV6_UNICAST_HOPS"); 788 When the IPV6_UNICAST_HOPS option is set with setsockopt(), the option 789 value given is used as the hop limit for all subsequent unicast packets 790 sent via that socket. If the option is not set, the system selects a 791 default value. The integer hop limit value (called x) is interpreted as 792 follows: 794 x < -1: return an error of EINVAL 795 x == -1: use kernel default 796 0 <= x <= 255: use x 797 x >= 256: return an error of EINVAL 799 The IPV6_UNICAST_HOPS option may be used with getsockopt() to determine 800 the hop limit value that the system will use for subsequent unicast 801 packets sent via that socket. For example: 803 int hoplimit; 804 socklen_t len = sizeof(hoplimit); 806 if (getsockopt(s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, 807 (char *) &hoplimit, &len) == -1) 808 perror("getsockopt IPV6_UNICAST_HOPS"); 809 else 810 printf("Using %d for hop limit.\n", hoplimit); 812 5.2 Sending and Receiving Multicast Packets 814 IPv6 applications may send multicast packets by simply specifying an 815 IPv6 multicast address as the destination address, for example in the 816 destination address argument of the sendto() function. 818 Three socket options at the IPPROTO_IPV6 layer control some of the 819 parameters for sending multicast packets. Setting these options is not 820 required: applications may send multicast packets without using these 821 options. The setsockopt() options for controlling the sending of 822 multicast packets are summarized below. These three options can also be 823 used with getsockopt(). 825 IPV6_MULTICAST_IF 827 Set the interface to use for outgoing multicast packets. 828 The argument is the index of the interface to use. 829 If the interface index is specified as zero, the system 830 selects the interface (for example, by looking up the 831 address in a routing table and using the resulting interface). 833 Argument type: unsigned int 835 IPV6_MULTICAST_HOPS 837 Set the hop limit to use for outgoing multicast packets. 838 (Note a separate option - IPV6_UNICAST_HOPS - is 839 provided to set the hop limit to use for outgoing 840 unicast packets.) 842 The interpretation of the argument is the same 843 as for the IPV6_UNICAST_HOPS option: 845 x < -1: return an error of EINVAL 846 x == -1: use kernel default 847 0 <= x <= 255: use x 848 x >= 256: return an error of EINVAL 850 If IPV6_MULTICAST_HOPS is not set, the default is 1 851 (same as IPv4 today) 853 Argument type: int 855 IPV6_MULTICAST_LOOP 857 If a multicast datagram is sent to a group to which the sending host 858 itself belongs (on the outgoing interface), a copy of the datagram is 859 looped back by the IP layer for local delivery if this option is set to 860 1. If this option is set to 0 a copy is not looped back. Other option 861 values return an error of EINVAL. 863 If IPV6_MULTICAST_LOOP is not set, the default is 1 (loopback; same as 864 IPv4 today). 866 Argument type: unsigned int 868 The reception of multicast packets is controlled by the two setsockopt() 869 options summarized below. An error of EOPNOTSUPP is returned if these 870 two options are used with getsockopt(). 872 IPV6_JOIN_GROUP 874 Join a multicast group on a specified local interface. 875 If the interface index is specified as 0, 876 the kernel chooses the local interface. 877 For example, some kernels look up the multicast group 878 in the normal IPv6 routing table and use the resulting interface. 880 Argument type: struct ipv6_mreq 882 IPV6_LEAVE_GROUP 884 Leave a multicast group on a specified interface. 885 If the interface index is specified as 0, the system 886 may choose a multicast group membership to drop by 887 matching the multicast address only. 889 Argument type: struct ipv6_mreq 891 The argument type of both of these options is the ipv6_mreq structure, 892 defined as a result of including the header; 894 struct ipv6_mreq { 895 struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */ 896 unsigned int ipv6mr_interface; /* interface index */ 897 }; 899 Note that to receive multicast datagrams a process must join the 900 multicast group to which datagrams will be sent. UDP applications must 901 also bind the UDP port to which datagrams will be sent. Some processes 902 also bind the multicast group address to the socket, in addition to the 903 port, to prevent other datagrams destined to that same port from being 904 delivered to the socket. 906 5.3 IPV6_V6ONLY option for AF_INET6 Sockets 908 This socket option restricts AF_INET6 sockets to IPv6 communications 909 only. As stated in section <3.7 Compatibility with IPv4 Nodes>, 910 AF_INET6 sockets may be used for both IPv4 and IPv6 communications. Some 911 applications may want to restrict their use of an AF_INET6 socket to 912 IPv6 communications only. For these applications the IPV6_V6ONLY socket 913 option is defined. When this option is turned on, the socket can be 914 used to send and receive IPv6 packets only. This is an IPPROTO_IPV6 915 level option. This option takes an int value. This is a boolean 916 option. By default this option is turned off. 918 Here is an example of setting this option: 920 int on = 1; 922 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, 923 (char *)&on, sizeof(on)) == -1) 924 perror("setsockopt IPV6_V6ONLY"); 925 else 926 printf("IPV6_V6ONLY set0); 928 Note - This option has no effect on the use of IPv4 Mapped addresses 929 which enter a node as a valid IPv6 addresses for IPv6 communications as 930 defined by Stateless IP/ICMP Translation Algorithm (SIIT) [8]. 932 6. Library Functions 934 New library functions are needed to perform a variety of operations with 935 IPv6 addresses. Functions are needed to lookup IPv6 addresses in the 936 Domain Name System (DNS). Both forward lookup (nodename-to-address 937 translation) and reverse lookup (address-to-nodename translation) need 938 to be supported. Functions are also needed to convert IPv6 addresses 939 between their binary and textual form. 941 We note that the two existing functions, gethostbyname() and 942 gethostbyaddr(), are left as-is. New functions are defined to handle 943 both IPv4 and IPv6 addresses. 945 The commonly used function gethostbyname() is inadequate for many 946 applications, first because it provides no way for the caller to specify 947 anything about the types of addresses desired (IPv4 only, IPv6 only, 948 IPv4-mapped IPv6 are OK, etc.), and second because many implementations 949 of this function are not thread safe. RFC 2133 defined a function named 950 gethostbyname2() but this function was also inadequate, first because 951 its use required setting a global option (RES_USE_INET6) when IPv6 952 addresses were required, and second because a flag argument is needed to 953 provide the caller with additional control over the types of addresses 954 required. 956 6.1 Protocol-Independent Nodename and Service Name Translation 958 Nodename-to-address translation is done in a protocol-independent 959 fashion using the getaddrinfo() function that is taken from the 960 Institute of Electrical and Electronic Engineers IEEE 1003.1-200x 961 (POSIX) draft specification [3]. 963 The official specification for this function will be the final IEEE 964 standard. In addition this specification is not specifying all 965 parameter possibilities for this function, but only the parameters that 966 can be provided to support IPv4 and IPv6 communications to support this 967 specification. This is beyond the scope of this document and additional 968 work on this function will be done by the Austin (IEEE/ISO/TOG) Group. 969 #include 970 #include 972 int getaddrinfo(const char *nodename, const char *servname, 973 const struct addrinfo *hints, struct addrinfo **res); 975 void freeaddrinfo(struct addrinfo *ai); 977 struct addrinfo { 978 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST, .. */ 979 int ai_family; /* PF_xxx */ 980 int ai_socktype; /* SOCK_xxx */ 981 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 982 socklen_t ai_addrlen; /* length of ai_addr */ 983 char *ai_canonname; /* canonical name for nodename */ 984 struct sockaddr *ai_addr; /* binary address */ 985 struct addrinfo *ai_next; /* next structure in linked list */ 986 }; 988 The getaddrinfo() function translates the name of a service location 989 (for example, a host name) and/or a service name and returns a set of 990 socket addresses and associated information to be used in creating a 991 socket with which to address the specified service. 993 The nodename and servname arguments are either null pointers or 994 pointers to null-terminated strings. One or both of these two 995 arguments must be a non-null pointer. 997 The format of a valid name depends on the address family or families. 998 If a specific family is not given and the name could be interpreted 999 as valid within multiple supported families, the implementation will 1000 attempt to resolve the name in all supported families and, in absence 1001 of errors, one or more results shall be returned. 1003 If the nodename argument is not null, it can be a descriptive name or 1004 can be an address string. If the specified address family is AF_INET, 1005 AF_INET6, or AF_UNSPEC, valid descriptive names include host names. 1006 If the specified address family is AF_INET or AF_UNSPEC, address 1007 strings using Internet standard dot notation as specified in 1008 inet_addr() are valid. If the specified address family is AF_INET6 1009 or AF_UNSPEC, standard IPv6 text forms described in inet_ntop() and 1010 [5] are valid. 1012 If nodename is not null, the requested service location is named by 1013 nodename; otherwise, the requested service location is local to the 1014 caller. 1016 If servname is null, the call shall return network-level addresses 1017 for the specified nodename. If servname is not null, it is a null- 1018 terminated character string identifying the requested service. This 1019 can be either a descriptive name or a numeric representation suitable 1020 for use with the address family or families. If the specified address 1021 family is AF_INET, AF_INET6 or AF_UNSPEC, the service can be 1022 specified as a string specifying a decimal port number. 1024 If the argument hints is not null, it refers to a structure 1025 containing input values that may direct the operation by providing 1026 options and by limiting the returned information to a specific socket 1027 type, address family and/or protocol. In this hints structure every 1028 member other than ai_flags, ai_family, ai_socktype and ai_protocol 1029 shall be set to zero or a null pointer. A value of AF_UNSPEC for 1030 ai_family means that the caller shall accept any address family. A 1031 value of zero for ai_socktype means that the caller shall accept any 1032 socket type. A value of zero for ai_protocol means that the caller 1033 shall accept any protocol. If hints is a null pointer, the behavior 1034 shall be as if it referred to a structure containing the value zero 1035 for the ai_flags, ai_socktype and ai_protocol fields, and AF_UNSPEC 1036 for the ai_family field. 1038 Note: 1040 1. If the caller handles only TCP and not UDP, for example, then the 1041 ai_protocol member of the hints structure should be set to 1042 IPPROTO_TCP when getaddrinfo() is called. 1044 2. If the caller handles only IPv4 and not IPv6, then the ai_family 1045 member of the hints structure should be set to AF_INET when 1046 getaddrinfo() is called. 1048 The ai_flags field to which hints parameter points shall be set to 1049 zero or be the bitwise-inclusive OR of one or more of the values 1050 AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST, AI_NUMERICSERV, 1051 AI_V4MAPPED, AI_ALL, and AI_ADDRCONFIG. 1053 If the AI_PASSIVE flag is specified, the returned address information 1054 shall be suitable for use in binding a socket for accepting incoming 1055 connections for the specified service (i.e. a call to bind()). In 1056 this case, if the nodename argument is null, then the IP address 1057 portion of the socket address structure shall be set to INADDR_ANY 1058 for an IPv4 address or IN6ADDR_ANY_INIT for an IPv6 address. If the 1059 AI_PASSIVE flag is not specified, the returned address information 1060 shall be suitable for a call to connect() (for a connection-mode 1061 protocol) or for a call to connect(), sendto() or sendmsg() (for a 1062 connectionless protocol). In this case, if the nodename argument is 1063 null, then the IP address portion of the socket address structure 1064 shall be set to the loopback address. This flag is ignored if the 1065 nodename argument is not null. 1067 If the AI_CANONNAME flag is specified and the nodename argument is 1068 not null, the function shall attempt to determine the canonical name 1069 corresponding to nodename (for example, if nodename is an alias or 1070 shorthand notation for a complete name). 1072 If the AI_NUMERICHOST flag is specified, then a non-null nodename 1073 string supplied shall be a numeric host address string. Otherwise, an 1074 [EAI_NONAME] error is returned. This flag shall prevent any type of 1075 name resolution service (for example, the DNS) from being invoked. 1077 If the AI_NUMERICSERV flag is specified, then a non-null servname 1078 string supplied shall be a numeric port string. Otherwise, an 1079 [EAI_NONAME] error shall be returned. This flag shall prevent any 1080 type of name resolution service (for example, NIS+) from being 1081 invoked. 1083 If the AI_V4MAPPED flag is specified along with an ai_family of 1084 AF_INET6, then getaddrinfo() shall return IPv4-mapped IPv6 addresses 1085 on finding no matching IPv6 addresses (ai_addrlen shall be 16). 1087 For example, when using the DNS, if no AAAA or A6 records are found 1088 then a query is made for A records and any found are returned as 1089 IPv4-mapped IPv6 addresses. 1091 The AI_V4MAPPED flag shall be ignored unless ai_family equals 1092 AF_INET6. 1094 If the AI_ALL flag is used with the AI_V4MAPPED flag, then 1095 getaddrinfo() shall return all matching IPv6 and IPv4 addresses. 1097 For example, when using the DNS, a query is first made for AAAA/A6 1098 records and if successful, those IPv6 addresses are returned. 1099 Another query is then made for A records and any IPv4 addresses 1100 found are returned as IPv4-mapped IPv6 addresses. 1102 The AI_ALL flag without the AI_V4MAPPED flag is ignored. 1104 Note: 1106 When ai_family is not specified (AF_UNSPEC), AI_V4MAPPED and 1107 AI_ALL flags will only be used if AF_INET6 is supported. 1109 If the AI_ADDRCONFIG flag is specified then a query for AAAA or A6 1110 records should occur only if the node has at least one IPv6 source 1111 address configured and a query for A records should occur only if the 1112 node has at least one IPv4 source address configured. The loopback 1113 address is not considered for this case as valid as a configured 1114 sources address. 1116 The ai_socktype field to which argument hints points specifies the 1117 socket type for the service, as defined for socket(). If a specific 1118 socket type is not given (for example, a value of zero) and the 1119 service name could be interpreted as valid with multiple supported 1120 socket types, the implementation shall attempt to resolve the service 1121 name for all supported socket types and, in the absence of errors, 1122 all possible results shall be returned. A non-zero socket type value 1123 shall limit the returned information to values with the specified 1124 socket type. 1126 If the ai_family field to which hints points has the value AF_UNSPEC, 1127 addresses shall be returned for use with any address family that can 1128 be used with the specified nodename and/or servname. Otherwise, 1129 addresses shall be returned for use only with the specified address 1130 family. If ai_family is not AF_UNSPEC and ai_protocol is not zero, 1131 then addresses are returned for use only with the specified address 1132 family and protocol; the value of ai_protocol shall be interpreted as 1133 in a call to the socket() function with the corresponding values of 1134 ai_family and ai_protocol . 1136 The freeaddrinfo() function frees one or more addrinfo structures 1137 returned by getaddrinfo(), along with any additional storage 1138 associated with those structures. If the ai_next field of the 1139 structure is not null, the entire list of structures is freed. The 1140 freeaddrinfo() function must support the freeing of arbitrary 1141 sublists of an addrinfo list originally returned by getaddrinfo(). 1143 Functions getaddrinfo() and freeaddrinfo() must be thread-safe. 1145 A zero return value for getaddrinfo() indicates successful 1146 completion; a non-zero return value indicates failure. The possible 1147 values for the failures are listed below under Error Return Values. 1149 Upon successful return of getaddrinfo(), the location to which res 1150 points shall refer to a linked list of addrinfo structures, each of 1151 which shall specify a socket address and information for use in 1152 creating a socket with which to use that socket address. The list 1153 shall include at least one addrinfo structure. The ai_next field of 1154 each structure contains a pointer to the next structure on the list, 1155 or a null pointer if it is the last structure on the list. Each 1156 structure on the list shall include values for use with a call to the 1157 socket() function, and a socket address for use with the connect() 1158 function or, if the AI_PASSIVE flag was specified, for use with the 1159 bind() function. The fields ai_family, ai_socktype, and ai_protocol 1160 shall be usable as the arguments to the socket() function to create a 1161 socket suitable for use with the returned address. The fields ai_addr 1162 and ai_addrlen are usable as the arguments to the connect() or bind() 1163 functions with such a socket, according to the AI_PASSIVE flag. 1165 If nodename is not null, and if requested by the AI_CANONNAME flag, 1166 the ai_canonname field of the first returned addrinfo structure shall 1167 point to a null-terminated string containing the canonical name 1168 corresponding to the input nodename; if the canonical name is not 1169 available, then ai_canonname shall refer to the nodename argument or 1170 a string with the same contents. The contents of the ai_flags field 1171 of the returned structures are undefined. 1173 All fields in socket address structures returned by getaddrinfo() 1174 that are not filled in through an explicit argument (for example, 1175 sin6_flowinfo) shall be set to zero. 1177 Note: This makes it easier to compare socket address structures. 1179 Error Return Values: 1181 The getaddrinfo() function shall fail and return the corresponding 1182 value if: 1184 [EAI_AGAIN] The name could not be resolved at this time. Future 1185 attempts may succeed. 1187 [EAI_BADFLAGS] The flags parameter had an invalid value. 1189 [EAI_FAIL] A non-recoverable error occurred when attempting to 1190 resolve the name. 1192 [EAI_FAMILY] The address family was not recognized. 1194 [EAI_MEMORY] There was a memory allocation failure when trying to 1195 allocate storage for the return value. 1197 [EAI_NONAME] The name does not resolve for the supplied parameters. 1198 Neither nodename nor servname were supplied. At least one 1199 of these must be supplied. 1201 [EAI_SERVICE] The service passed was not recognized for the specified 1202 socket type. 1204 [EAI_SOCKTYPE] The intended socket type was not recognized. 1206 [EAI_SYSTEM] A system error occurred; the error code can be found in 1207 errno. 1209 #include 1211 const char *gai_strerror(int ecode); 1213 The argument is one of the EAI_xxx values defined for the getaddrinfo() 1214 and getnameinfo() functions. The return value points to a string 1215 describing the error. If the argument is not one of the EAI_xxx values, 1216 the function still returns a pointer to a string whose contents indicate 1217 an unknown error. 1219 6.2 Socket Address Structure to Nodename and Service Name 1221 The official specification for this function will be the final Austin 1222 Group standard update to getaddrinfo(), and will incorporate this 1223 function. In addition this specification is not specifying all 1224 parameter possibilities for this function, but only the parameters that 1225 can be provided to support IPv4 and IPv6 communications to support this 1226 specification. This is beyond the scope of this document and additional 1227 work on this function will be done by the Austin group. 1229 #include 1230 #include 1232 int getnameinfo(const struct sockaddr *sa, socklen_t salen, 1233 char *host, socklen_t hostlen, 1234 char *serv, socklen_t servlen, 1235 int flags); 1237 The getnameinfo() function shall translate a socket address to a node 1238 name and service location, all of which are defined as in getaddrinfo(). 1240 The sa argument points to a socket address structure to be translated. 1242 If the socket address structure contains an IPv4-mapped IPv6 address or 1243 an IPv4-compatible IPv6 address, the implementation shall extract the 1244 embedded IPv4 address and lookup the node name for that IPv4 address. 1246 Note: The IPv6 unspecified address ("::") and the IPv6 1247 loopback address ("::1") are not IPv4-compatible addresses. 1248 If the address is the IPv6 unspecified address ("::"), a 1249 lookup is not performed, and the [EAI_NONAME] error is returned. 1251 If the node argument is non-NULL and the nodelen argument is nonzero, 1252 then the node argument points to a buffer able to contain up to nodelen 1253 characters that receives the node name as a null-terminated string. If 1254 the node argument is NULL or the nodelen argument is zero, the node name 1255 shall not be returned. If the node's name cannot be located, the numeric 1256 form of the node's address is returned instead of its name. If the sa 1257 argument is an IPv6 address the returned nodename may be in the format 1258 as defined in [5]. 1260 If the service argument is non-NULL and the servicelen argument is non- 1261 zero, then the service argument points to a buffer able to contain up to 1262 servicelen bytes that receives the service name as a null-terminated 1263 string. If the service argument is NULL or the servicelen argument is 1264 zero, the service name shall not be returned. If the service's name 1265 cannot be located, the numeric form of the service address (for example, 1266 its port number) shall be returned instead of its name. 1268 The arguments node and service cannot both be NULL. 1270 The flags argument is a flag that changes the default actions of the 1271 function. By default the fully-qualified domain name (FQDN) for the host 1272 shall be returned, but: 1274 - If the flag bit NI_NOFQDN is set, only the node name portion of the 1275 FQDN shall be returned for local hosts. 1277 - If the flag bit NI_NUMERICHOST is set, the numeric form of the 1278 host's address shall be returned instead of its name, under all 1279 circumstances. 1281 - If the flag bit NI_NAMEREQD is set, an error shall be returned if the 1282 host's name cannot be located. 1284 - If the flag bit NI_NUMERICSERV is set, the numeric form of the 1285 service address shall be returned (for example, its port number) instead of 1286 its name, under all circumstances. 1288 - If the flag bit NI_NUMERICSCOPE is set, the numeric form of the 1289 scope identifier shall be returned (for example, interface index) 1290 instead of its name. This flag is ignored if the sa argument is 1291 not an IPv6 address. 1293 - If the flag bit NI_DGRAM is set, this indicates that the service is 1294 a datagram service (SOCK_DGRAM). The default behavior shall assume that 1295 the service is a stream service (SOCK_STREAM). 1297 Note: 1299 1. The three NI_NUMERICxxx flags are required to support the "-n" 1300 flags that many commands provide. 1301 2. The NI_DGRAM flag is required for the few AF_INET and AF_INET6 port 1302 numbers (for example, [512,514]) that represent different services 1303 for UDP and TCP. 1305 The getnameinfo() function shall be thread safe. 1307 A zero return value for getnameinfo() indicates successful completion; a 1308 non-zero return value indicates failure. 1310 Upon successful completion, getnameinfo() shall return the node and 1311 service names, if requested, in the buffers provided. The returned names 1312 are always null-terminated strings. 1314 Error Return Values: 1316 The getnameinfo() function shall fail and return the corresponding value 1317 if: 1319 [EAI_AGAIN] The name could not be resolved at this time. 1320 Future attempts may succeed. 1322 [EAI_BADFLAGS] The flags had an invalid value. 1324 [EAI_FAIL] A non-recoverable error occurred. 1326 [EAI_FAMILY] The address family was not recognized or the address 1327 length was invalid for the specified family. 1329 [EAI_MEMORY] There was a memory allocation failure. 1331 [EAI_NONAME] The name does not resolve for the supplied parameters. 1332 NI_NAMEREQD is set and the host's name cannot be located, or 1333 both nodename and servname were null. 1335 [EAI_OVERFLOW] An argument buffer overflowed. 1337 [EAI_SYSTEM] A system error occurred. The error code can be found in 1338 errno. 1340 6.3 Address Conversion Functions 1342 The two functions inet_addr() and inet_ntoa() convert an IPv4 address 1343 between binary and text form. IPv6 applications need similar functions. 1344 The following two functions convert both IPv6 and IPv4 addresses: 1346 #include 1348 int inet_pton(int af, const char *src, void *dst); 1350 const char *inet_ntop(int af, const void *src, 1351 char *dst, socklen_t size); 1353 The inet_pton() function shall convert an address in its standard text 1354 presentation form into its numeric binary form. The af argument shall 1355 specify the family of the address. The AF_INET and AF_INET6 address 1356 families shall be supported. The src argument points to the string 1357 being passed in. The dst argument points to a buffer into which the 1358 function stores the numeric address; this shall be large enough to hold 1359 the numeric address (32 bits for AF_INET, 128 bits for AF_INET6). The 1360 inet_pton() function shall return 1 if the conversion succeeds, with the 1361 address pointed to by dst in network byte order. It shall return 0 if 1362 the input is not a valid IPv4 dotted-decimal string or a valid IPv6 1363 address string, or -1 with errno set to EAFNOSUPPORT if the af argument 1364 is unknown. 1366 If the af argument of inet_pton() is AF_INET, the src string shall be in 1367 the standard IPv4 dotted-decimal form: 1369 ddd.ddd.ddd.ddd 1371 where "ddd" is a one to three digit decimal number between 0 and 255. 1372 The inet_pton() function does not accept other formats (such as the 1373 octal numbers, hexadecimal numbers, and fewer than four numbers that 1374 inet_addr() accepts). 1376 If the af argument of inet_pton() is AF_INET6, the src string shall be 1377 in one of the standard IPv6 text forms defined in Section 2.2 of the 1378 addressing architecture specification [2]. 1380 The inet_ntop() function shall convert a numeric address into a text 1381 string suitable for presentation. The af argument shall specify the 1382 family of the address. This can be AF_INET or AF_INET6. The src 1383 argument points to a buffer holding an IPv4 address if the af argument 1384 is AF_INET, or an IPv6 address if the af argument is AF_INET6; the 1385 address must be in network byte order. The dst argument points to a 1386 buffer where the function stores the resulting text string; it shall not 1387 be NULL. The size argument specifies the size of this buffer, which 1388 shall be large enough to hold the text string (INET_ADDRSTRLEN 1389 characters for IPv4, INET6_ADDRSTRLEN characters for IPv6). 1391 In order to allow applications to easily declare buffers of the proper 1392 size to store IPv4 and IPv6 addresses in string form, the following two 1393 constants are defined in : 1395 #define INET_ADDRSTRLEN 16 1396 #define INET6_ADDRSTRLEN 46 1398 The inet_ntop() function shall return a pointer to the buffer containing 1399 the text string if the conversion succeeds, and NULL otherwise. Upon 1400 failure, errno is set to EAFNOSUPPORT if the af argument is invalid or 1401 ENOSPC if the size of the result buffer is inadequate. 1403 6.4 Address Testing Macros 1405 The following macros can be used to test for special IPv6 addresses. 1407 #include 1409 int IN6_IS_ADDR_UNSPECIFIED (const struct in6_addr *); 1410 int IN6_IS_ADDR_LOOPBACK (const struct in6_addr *); 1411 int IN6_IS_ADDR_MULTICAST (const struct in6_addr *); 1412 int IN6_IS_ADDR_LINKLOCAL (const struct in6_addr *); 1413 int IN6_IS_ADDR_SITELOCAL (const struct in6_addr *); 1414 int IN6_IS_ADDR_V4MAPPED (const struct in6_addr *); 1415 int IN6_IS_ADDR_V4COMPAT (const struct in6_addr *); 1417 int IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *); 1418 int IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *); 1419 int IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *); 1420 int IN6_IS_ADDR_MC_ORGLOCAL (const struct in6_addr *); 1421 int IN6_IS_ADDR_MC_GLOBAL (const struct in6_addr *); 1423 The first seven macros return true if the address is of the specified 1424 type, or false otherwise. The last five test the scope of a multicast 1425 address and return true if the address is a multicast address of the 1426 specified scope or false if the address is either not a multicast 1427 address or not of the specified scope. Note that IN6_IS_ADDR_LINKLOCAL 1428 and IN6_IS_ADDR_SITELOCAL return true only for the two types of local- 1429 use IPv6 unicast addresses (Link-Local and Site-Local) defined in [2], 1430 and that by this definition, the IN6_IS_ADDR_LINKLOCAL macro returns 1431 false for the IPv6 loopback address (::1). These two macros do not 1432 return true for IPv6 multicast addresses of either link-local scope or 1433 site-local scope. 1435 7. Summary of New Definitions 1437 The following list summarizes the constants, structure, and extern 1438 definitions discussed in this memo, sorted by header. 1440 IF_NAMESIZE 1441 struct if_nameindex{}; 1443 AI_ADDRCONFIG 1444 AI_ALL 1445 AI_CANONNAME 1446 AI_NUMERICHOST 1447 AI_NUMERICSERV 1448 AI_PASSIVE 1449 AI_V4MAPPED 1450 EAI_AGAIN 1451 EAI_BADFLAGS 1452 EAI_FAIL 1453 EAI_FAMILY 1454 EAI_MEMORY 1455 EAI_NONAME 1456 EAI_OVERFLOW 1457 EAI_SERVICE 1458 EAI_SOCKTYPE 1459 EAI_SYSTEM 1460 NI_DGRAM 1461 NI_NAMEREQD 1462 NI_NOFQDN 1463 NI_NUMERICHOST 1464 NI_NUMERICSERV 1465 struct addrinfo{}; 1467 IN6ADDR_ANY_INIT 1468 IN6ADDR_LOOPBACK_INIT 1469 INET6_ADDRSTRLEN 1470 INET_ADDRSTRLEN 1471 IPPROTO_IPV6 1472 IPV6_JOIN_GROUP 1473 IPV6_LEAVE_GROUP 1474 IPV6_MULTICAST_HOPS 1475 IPV6_MULTICAST_IF 1476 IPV6_MULTICAST_LOOP 1477 IPV6_UNICAST_HOPS 1478 IPV6_V6ONLY 1479 SIN6_LEN 1480 extern const struct in6_addr in6addr_any; 1481 extern const struct in6_addr in6addr_loopback; 1482 struct in6_addr{}; 1483 struct ipv6_mreq{}; 1484 struct sockaddr_in6{}; 1486 AF_INET6 1487 PF_INET6 1488 struct sockaddr_storage; 1490 The following list summarizes the function and macro prototypes 1491 discussed in this memo, sorted by header. 1493 int inet_pton(int, const char *, void *); 1494 const char *inet_ntop(int, const void *, 1495 char *, socklen_t); 1497 char *if_indextoname(unsigned int, char *); 1498 unsigned int if_nametoindex(const char *); 1499 void if_freenameindex(struct if_nameindex *); 1500 struct if_nameindex *if_nameindex(void); 1502 int getaddrinfo(const char *, const char *, 1503 const struct addrinfo *, 1504 struct addrinfo **); 1505 int getnameinfo(const struct sockaddr *, socklen_t, 1506 char *, socklen_t, char *, socklen_t, int); 1507 void freeaddrinfo(struct addrinfo *); 1508 const char *gai_strerror(int); 1510 int IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *); 1511 int IN6_IS_ADDR_LOOPBACK(const struct in6_addr *); 1512 int IN6_IS_ADDR_MC_GLOBAL(const struct in6_addr *); 1513 int IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *); 1514 int IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *); 1515 int IN6_IS_ADDR_MC_ORGLOCAL(const struct in6_addr *); 1516 int IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *); 1517 int IN6_IS_ADDR_MULTICAST(const struct in6_addr *); 1518 int IN6_IS_ADDR_SITELOCAL(const struct in6_addr *); 1519 int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *); 1520 int IN6_IS_ADDR_V4COMPAT(const struct in6_addr *); 1521 int IN6_IS_ADDR_V4MAPPED(const struct in6_addr *); 1523 8. Security Considerations 1525 IPv6 provides a number of new security mechanisms, many of which need to 1526 be accessible to applications. Companion memos detailing the extensions 1527 to the socket interfaces to support IPv6 security are being written. 1529 9. Year 2000 Considerations 1531 There are no issues for this draft concerning the Year 2000 issue 1532 regarding the use of dates. 1534 Changes made to rfc2553bis-04 to rfc2553bis-05 1536 1. Added Jack McCann as coauthor for signicant work on draft 04. 1538 Changes made to rfc2553bis-03 to rfc2553bis-04 1540 1. Alignments with [3]. 1542 Changes made to rfc2553bis-02 to rfc2553bis-03 1544 1. Edits only. 1546 Changes made to rfc2553bis-01 to rfc2553bis-02 1548 1. Updated all references to comply with latest IEEEE work on 1549 socket APIs and changed all remaining size_t to socklen_t. 1551 2. Edits caught. 1553 Changes made to rfc2553bis-00 to rfc2553bis-01 1555 1. Removed all references to getipnodebyname() and 1556 getipnodebyaddr(). 1558 2. Added IPV6_V6ONLY Socket IP level option to permit nodes 1559 to not process IPv4 packets as IPv4 Mapped addresses 1560 in implementations. 1562 3. Added note to getaddrinfo() and getnameinfo() 1563 that final specification of parameter associations for 1564 these functions will be done by Austin. 1566 4. Added SIIT to references and added new contributors. 1568 Changes made rfc2553 to rfc2553bis-00: 1570 1. Updated Portability Section 3.10 to conform to XNS 5.2. 1572 2. Updated getaddrinfo(), getnameinfo(), to conform to XNS 5.2. 1574 3. Added references to Scope Architecture, Scope Routing, and 1575 Extension Format for Scoped Addresses work in progress. 1577 4. Added NI_NUMERICSCOPE flag to getnameinfo(). 1579 5. Added qualification to getipnodebyname/addr() functions that 1580 they will not work as is with scope identifiers with IPv6, and 1581 getaddrinfo/getnameinfo should be used. 1583 6. Added DNS A6 record notation to AAAA and added ip6.arpa as new 1584 PTR record domain. 1586 Acknowledgments 1588 This specification's evolution and completeness were significantly 1589 influenced by the efforts of Richard Stevens, who has passed on. Rich's 1590 wisdom and talent made the specification what it is today. The co- 1591 authors will long think of Richard with great respect. 1593 Thanks to the many people who made suggestions and provided feedback to 1594 this document, including: Werner Almesberger, Ran Atkinson, Fred Baker, 1595 Dave Borman, Andrew Cherenson, Alex Conta, Alan Cox, Steve Deering, 1596 Richard Draves, Francis Dupont, Robert Elz, Brian Haberman, Jun-ichiro 1597 itojun Hagino, Marc Hasson, Tom Herbert, Bob Hinden, Wan-Yen Hsu, 1598 Christian Huitema, Koji Imada, Markus Jork, Ron Lee, Alan Lloyd, Charles 1599 Lynn, Dan McDonald, Dave Mitton, Thomas Narten, Josh Osborne, Craig 1600 Partridge, Jean-Luc Richier, Bill Sommerfield, Erik Scoredos, Keith 1601 Sklower, JINMEI Tatuya, Dave Thaler, Matt Thomas, Harvey Thompson, Dean 1602 D. Throop, Karen Tracey, Glenn Trewitt, Paul Vixie, David Waitzman, Carl 1603 Williams, Kazu Yamamoto, Vlad Yasevich, Stig Venaas, and Brian Zill 1605 The getaddrinfo() and getnameinfo() functions are taken from an earlier 1606 Internet Draft by Keith Sklower. As noted in that draft, William Durst, 1607 Steven Wise, Michael Karels, and Eric Allman provided many useful 1608 discussions on the subject of protocol-independent name-to-address 1609 translation, and reviewed early versions of Keith Sklower's original 1610 proposal. Eric Allman implemented the first prototype of getaddrinfo(). 1611 The observation that specifying the pair of name and service would 1612 suffice for connecting to a service independent of protocol details was 1613 made by Marshall Rose in a proposal to X/Open for a "Uniform Network 1614 Interface". 1616 Craig Metz, Jack McCann, Erik Nordmark, Tim Hartrick, and Mukesh Kacker 1617 made many contributions to this document. Ramesh Govindan made a number 1618 of contributions and co-authored an earlier version of this memo. 1620 References 1622 [1] S. Deering, R. Hinden, "Internet Protocol, Version 6 (IPv6) 1623 Specification", RFC 2460 Draft Standard. 1625 [2] R. Hinden, S. Deering, "IP Version 6 Addressing Architecture", 1626 RFC 2373, July 1998 Draft Standard. 1628 [3] IEEE Std. 1003.1-200x Standard for Information Technology -- 1629 Portable Operating System Interface (POSIX) 1630 DRAFT 7, June 2001 1632 [4] W. Stevens, M. Thomas, "Advanced Sockets API for IPv6", 1633 RFC 2292, February 1998. 1635 [5] T. Jinmei, A. Onoe, "An Extension of Format for IPv6 Scoped 1636 Addresses", Work-in-Progress. 1638 [6] S. Deering, B. Haberman, B. Zill "IP Version 6 Scoped Address 1639 Architecture", Work-in-Progress. 1641 [7] B. Haberman " Routing of Scoped Addresses in the Internet Protocol 1642 Version 6 (IPv6)", Work-in-Progress. 1644 [8] E. Nordmark "Stateless IP/ICMP Translation Algorithm (SIIT)" 1645 RFC 2765, February 2000. 1647 Authors' Addresses 1649 Bob Gilligan 1650 Cacheflow, Inc. 1651 650 Almanor Ave. 1652 Sunnyvale, CA 94086 1653 Telephone: 408-220-2084 (voice) 1654 408-220-2250 (fax) 1655 Email: gilligan@cacheflow.com 1657 Susan Thomson 1658 Cisco Systems 1659 499 Thornall Street, 8th floor 1660 Edison, NJ 08837 1661 Telephone: 732-635-3086 1662 Email: sethomso@cisco.com 1664 Jim Bound 1665 Compaq Computer Corporation 1666 110 Spitbrook Road ZKO3-3/W20 1667 Nashua, NH 03062 1668 Telephone: 603-884-0062 1669 Email: Jim.Bound@compaq.com 1671 Jack McCann 1672 Compaq Computer Corporation 1673 110 Spitbrook Road ZKO3-3/W20 1674 Nashua, NH 03062 1675 Telephone: 603-884-2608 1676 Email: John.McCann@compaq.com