Wherein ai_flags, ai_family, ai_socktype follows: Parameter Value Value Description ai_family AF_INET 2 IPv4 AF_INET6 23 IPv6 AF_UNSPEC 0 ai_protocol IPPROTO_IP 0 IP protocol independent protocol IPPROTO_IPV4 4 IPv4 IPPROTO_IPV6 41 IPv6 IPPROTO_UDP 17 UDP IPPROTO_TCP 6 TCPai_socktype SOCK_STREAM 1 ai_flags datagram stream SOCK_DGRAM 2 Ai_Passive 1 Passive, for BIND, usually used for server socket ai_canname 2 ai_numerichost 4 address as a numeric string for ai_flags value: AI_NUMERICHOST AI_CANONNAME AI_PASSIVE0 / 1 0 / 1 0/1 As shown in the table, AI_FLAGSDE value The range is from 0 to 7, depending on how the program sets 3 sign bits, such as setting AI_FLAGS "AI_Passive | Ai_canname", the AI_FLAGS value is 3. The meaning of the three parameters is: (1) AI_Passive When this flag is set, the caller will use the returned address structure in the BIND () function call. When this flag is not set, it means that it will be used in the Connect () function call. When the node is named NULL, and this flag is set, the returned address will be a wild address. If the node name NULL, and this flag is not set, the return address will be a loop address. (2) AI_CANNONAME When this flag is set, in the AI_CANNONAME member in the first addrinfo structure returned, it should contain a string ending with an empty character, and the content of the string is the regular name of the node name. (3) AI_NUMERICHOST When this flag is set, this flag indicates that the node name in the call must be a digital address string. Several common settings in actually use Under Client / Server programming, Server end calls bind (if listen is needed for connection), the client does not need to drop the bind function, parse the address, directly connect or send it directly Data (no connection). Therefore, more common situations (1) Typically, the server side is used before calling getaddrinfo, and Ai_Flags sets AI_Passive for bind; hostname NodeName is usually set to NULL, return to wild address [::]. (2) When the client calls GetDrinfo, AI_FLAGS generally does not set AI_Passive, but hostname NodeName and service name servname should not be empty. (3) Of course, even if it does not set AI_Passive, the removed address is not could not be bind, and many programs are set directly to 0, that is, the three flag bits are not set, this case as long as HostName and Servname settings No problem can be correct.
The above situation is just a simple client / server used, but when using getaddrinfo and refer to the foreign open source code, it encounters some cases of setting servname (ie port) to null (of course, Nodename will not be null Otherwise calling getadDrInfo will report an error). The following sub-cases were tested: (1) If NodeName is a string type IPv6 address, the temporary port will be assigned when Bind; (2) If Nodename is this name, servname is NULL, then according to The other is slightly different from the WinXP and Win2003 this article. a) WinXP system (SP2) Returns the loopback address [:: 1] b) WIN2003 returns all IPv6 addresses of this unit. Because typically an IPv6 host is likely to be more than one IPv6 address, such as Fe80 :: 1 (this machine loopback address), FE80 :: *** Link-local address, 3FFE: *** global address, etc. In this case, calling GetDrinfo will return all of these addresses, and the caller should pay attention to how to use these addresses. Also note that the address of the interface must be indicated when the FE80 :: 20D: 60FF: FE78: 51C2% 4 or Fe80: 1% 1 is used in the address format of Fe80 :: 20D: 60F: FE80: 51C2% 4 or Fe80: 1% 1. Take out the FE80 address directly like it cannot be directly bind. Program personal feeling in Windows environmental debug IPv6 still uses WinXP (SP2) and Win2003 basically not very different, using Win2003 more standardized. Writing and debugging the IPv6 with VC must install Windows newer SDK, I installed MS_PLATFORM_SDK_FEB_2003, otherwise the library function and header file may have problems.