genericopenlibs/openenvcore/include/netdb.dosc
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /** @file  ../include/netdb.h
       
     2 @internalComponent
       
     3 */
       
     4 
       
     5 /** @fn  endservent(void)
       
     6 
       
     7 Refer to  getservent() for the documentation
       
     8 
       
     9 
       
    10  
       
    11 
       
    12 @publishedAll
       
    13 @externallyDefinedApi
       
    14 */
       
    15 
       
    16 /** @fn  gethostbyaddr(const char *addr, int length, int format)
       
    17 @param addr
       
    18 @param length
       
    19 @param format
       
    20 Refer to  gethostbyname() for the documentation
       
    21 @see getaddrinfo()
       
    22 @see getnameinfo()
       
    23 
       
    24 
       
    25  
       
    26 
       
    27 @publishedAll
       
    28 @externallyDefinedApi
       
    29 */
       
    30 
       
    31 /** @fn  gethostbyname(const char *name)
       
    32 @param name
       
    33 
       
    34 Note: This description also covers the following functions -
       
    35  gethostbyaddr() 
       
    36 
       
    37 @return   The gethostbyname and gethostbyaddr functions return NULL if an error occurs or a valid hostent 
       
    38 structure otherwise.
       
    39 
       
    40 The gethostbyname, and gethostbyaddr functions each return a pointer to an object with the following structure describing an internet host referenced by name or by address, respectively. 
       
    41 
       
    42 The name argument passed to gethostbyname should point to a NUL -terminated hostname. The addr argument passed to gethostbyaddr should point to an address which is len bytes long, in binary form (i.e., not an IP address in human readable ASCII form). The type argument specifies the address family (e.g. AF_INET, etc.) of this address. 
       
    43 
       
    44 The structure returned contains either the information obtained from the name server, 
       
    45 
       
    46 @code
       
    47 struct  hostent {
       
    48         char    *h_name;        // official name of host
       
    49         char    **h_aliases;    // alias list 
       
    50         int     h_addrtype;     // host address type 
       
    51         int     h_length;       // length of address 
       
    52         char    **h_addr_list;  // list of addresses from name server 
       
    53 };
       
    54 #define h_addr  h_addr_list[0]  //address, for backward compatibility
       
    55 @endcode
       
    56 
       
    57 
       
    58 
       
    59 The members of this structure are: 
       
    60 @code
       
    61 h_name  Official name of the host.  
       
    62 h_aliases  A NULL -terminated array of alternate names for the host.  
       
    63 h_addrtype  The type of address being returned; usually AF_INET.  
       
    64 h_length  The length, in bytes, of the address.  
       
    65 h_addr_list  A NULL -terminated array of network addresses for the host. Host addresses are returned in network byte order.  
       
    66 h_addr  The first address in h_addr_list; this is for backward compatibility.  
       
    67 @endcode
       
    68 
       
    69 
       
    70 When using the nameserver, gethostbyname will search for the named host in the current domain and its parents unless the name ends in a dot. 
       
    71 
       
    72 getaddrinfo and getnameinfo functions are preferred over the gethostbyname, and gethostbyaddr functions. 
       
    73 
       
    74 
       
    75 
       
    76 
       
    77 
       
    78 
       
    79 Examples:
       
    80 @code
       
    81 #include<stdio.h>
       
    82 #include<arpa/inet.h>
       
    83 #include <sys/socket.h>
       
    84 #include <netinet/in.h>
       
    85 #include <netdb.h>
       
    86 #include <string.h>
       
    87 Int main()
       
    88 {
       
    89 struct hostent *hp = 0;
       
    90 char *test_url=www.google.com:
       
    91 hp = gethostbyname(test_url);
       
    92 if(hp==NULL)
       
    93 printf("gethostbyname failed"):
       
    94 else
       
    95 printf("gethostbyname passed");
       
    96 return 0;
       
    97 }
       
    98 
       
    99 @endcode
       
   100  Output
       
   101 @code
       
   102 Gethostbyname passed
       
   103 
       
   104 @endcode
       
   105 @code
       
   106 #include<stdio.h>
       
   107 #include<arpa/inet.h>
       
   108 #include <sys/socket.h>
       
   109 #include <netinet/in.h>
       
   110 #include <netdb.h>
       
   111 #include <string.h>
       
   112 #define urlsize 50
       
   113 Int main()
       
   114 {
       
   115 struct hostent *hp = 0;
       
   116 char addr[256];
       
   117 unsigned long  test_addr;
       
   118 strcpy(addr," 147.243.3.83");
       
   119 test_addr=inet_addr(addr);
       
   120 struct hostent *hp;
       
   121 hp=gethostbyaddr((const char *)&test;_addr,sizeof(test_addr),AF_INET);
       
   122 if(hp)
       
   123 printf("DNS query resolved");
       
   124 else
       
   125 printf("gethostbyaddr failed");
       
   126 return 0;
       
   127 }
       
   128 
       
   129 @endcode
       
   130 
       
   131 Diagnostics:
       
   132 
       
   133  Error return status from gethostbyname and gethostbyaddr is indicated by return of a NULL pointer.
       
   134 The external integer h_errno may then be checked to see whether this is a temporary failure
       
   135 or an invalid or unknown host.
       
   136 The routine
       
   137 If its argument string is non- NULL, it is printed, followed by a colon and a space.
       
   138 The error message is printed with a trailing newline. The variable h_errno can have the following values: TRY_AGAIN This is usually a temporary error
       
   139 and means that the local server did not receive
       
   140 a response from an authoritative server.
       
   141 A retry at some later time may succeed. NO_RECOVERY Some unexpected server failure was encountered.
       
   142 This is a non-recoverable error.
       
   143 
       
   144 @see getaddrinfo()
       
   145 @see getnameinfo()
       
   146 
       
   147 
       
   148 Bugs:
       
   149 
       
   150  These functions use a thread-specific data storage; if the data is needed 
       
   151 for future use it should be copied before any subsequent calls overwrite it. Though these functions are thread-safe the getaddrinfo family of functions is recommended 
       
   152   instead. Only the Internet
       
   153 address format is currently understood. 
       
   154  
       
   155 
       
   156 @publishedAll
       
   157 @externallyDefinedApi
       
   158 */
       
   159 
       
   160 /** @fn  getprotobyname(const char *name)
       
   161 @param name
       
   162 
       
   163 Note: This description also covers the following functions -
       
   164  getprotobynumber() 
       
   165 
       
   166 @return   Null pointer
       
   167 (0) returned on
       
   168 error.
       
   169 
       
   170 The getprotobyname, and getprotobynumber functions each return a pointer to an object with the following structure from the network protocol data base 
       
   171 @code
       
   172 struct  protoent {
       
   173         char    *p_name;        /* official name of protocol */
       
   174         char    **p_aliases;    /* alias list */
       
   175         int     p_proto;        /* protocol number */
       
   176 };
       
   177 @endcode
       
   178 
       
   179 The members of this structure are: 
       
   180 @code
       
   181 p_name  The official name of the protocol.  
       
   182 p_aliases    A zero terminated list of alternate names for the protocol.  
       
   183 p_proto  The protocol number.  
       
   184 @endcode
       
   185 
       
   186 
       
   187 The getprotobyname function and getprotobynumber sequentially search from the beginning of the database until a matching protocol name or protocol number is found, 
       
   188 
       
   189 
       
   190 Examples:
       
   191 @code
       
   192 #include<netinet/in.h>
       
   193 #include<arpa/inet.h>
       
   194 #include<stdio.h>
       
   195 #include<string.h>
       
   196 #include<netdb.h>
       
   197 Int main()
       
   198 {
       
   199 struct protoent *p =0;
       
   200 char *protoname="tcp";
       
   201 p=getprotobyname(protoname);
       
   202 if(p!=NULL)
       
   203 printf("protocol not supported:");
       
   204 else
       
   205 printf("protocol supported");
       
   206 return 0;
       
   207 }
       
   208 
       
   209 @endcode
       
   210  Output
       
   211 @code
       
   212 Protocol supported/not supported based on the support for protocol
       
   213 
       
   214 @endcode
       
   215 @code
       
   216 #include<netinet/in.h>
       
   217 #include<arpa/inet.h>
       
   218 #include<stdio.h>
       
   219 #include<string.h>
       
   220 #include<netdb.h>
       
   221 int main()
       
   222 	{
       
   223 	struct protoent *p =0;
       
   224 	int protonum=6;
       
   225 	p=getprotobynumber(protonum);
       
   226 	if(p!=NULL)
       
   227 		printf("protocol not supported:");
       
   228 	else
       
   229 		printf("protocol supported");
       
   230 	return 0;
       
   231 	}
       
   232 
       
   233 @endcode
       
   234  Output
       
   235 @code
       
   236 Protocol supported/not supported based on the support for protocol
       
   237 
       
   238 @endcode
       
   239  The getprotobynumber, getprotobyname, functions appeared in BSD 4.2 .
       
   240 
       
   241 Bugs:
       
   242 
       
   243  These functions use a thread-specific data space; if the data is needed for 
       
   244 future use it must be copied before any subsequent calls overwrite it. Only the 
       
   245 Internet protocols are currently understood. 
       
   246 
       
   247  
       
   248 
       
   249 @publishedAll
       
   250 @externallyDefinedApi
       
   251 */
       
   252 
       
   253 /** @fn  getprotobynumber(int proto)
       
   254 @param proto
       
   255 
       
   256 Refer to  getprotobyname() for the documentation
       
   257 
       
   258 
       
   259  
       
   260 
       
   261 @publishedAll
       
   262 @externallyDefinedApi
       
   263 */
       
   264 
       
   265 /** @fn  getservbyname(const char *name, const char *proto)
       
   266 @param name
       
   267 @param proto
       
   268 Refer to  getservent() for the documentation
       
   269 
       
   270 
       
   271  
       
   272 
       
   273 @publishedAll
       
   274 @externallyDefinedApi
       
   275 */
       
   276 
       
   277 /** @fn  getservbyport(int port, const char *proto)
       
   278 @param port
       
   279 @param proto
       
   280 Refer to  getservent() for the documentation
       
   281 
       
   282 
       
   283  
       
   284 
       
   285 @publishedAll
       
   286 @externallyDefinedApi
       
   287 */
       
   288 
       
   289 /** @fn  getservent(void)
       
   290 
       
   291 Note: This description also covers the following functions -
       
   292  getservbyname()  getservbyport()  setservent()  endservent() 
       
   293 
       
   294 @return   getservent, getservbyname and getservbyport functions return the servent structure, or a NULL pointer if an error occurs or the end of the file is reached.
       
   295 
       
   296 @code
       
   297  s_name The official name of the service.
       
   298  s_aliases
       
   299   A zero terminated list of alternate names for the service.
       
   300  s_port The port number at which the service resides.
       
   301  Port numbers are returned in network byte order.
       
   302  s_proto The name of the protocol to use when contacting the
       
   303  service.
       
   304 
       
   305 @endcode
       
   306   
       
   307 @code
       
   308 The getservent, getservbyname, and getservbyport functions
       
   309 each return a pointer to an object with the
       
   310 following structure
       
   311 containing the broken-out
       
   312 fields of a line in the network services data base, c:/sys/data/services. 
       
   313 structservent {
       
   314 char*s_name;/* official name of service */
       
   315 char**s_aliases;/* alias list */
       
   316 ints_port;/* port service resides at */
       
   317 char*s_proto;/* protocol to use */
       
   318 };
       
   319 @endcode
       
   320 
       
   321  The members of this structure are: s_name The official name of the service. s_aliases  A zero terminated list of alternate names for the service. s_port The port number at which the service resides.
       
   322 Port numbers are returned in network byte order. s_proto The name of the protocol to use when contacting the
       
   323 service.
       
   324 
       
   325  The getservent function
       
   326 reads the next line of the file, opening the file if necessary.
       
   327 
       
   328  The setservent function
       
   329 opens and rewinds the file.
       
   330 
       
   331  The endservent function
       
   332 closes the file.
       
   333 
       
   334  The getservbyname and getservbyport functions
       
   335 sequentially search from the beginning
       
   336 of the file until a matching
       
   337 protocol name or
       
   338 port number (which must be specified in
       
   339 network byte order) is found,
       
   340 or until EOF is encountered.
       
   341 If a protocol name is also supplied (non- NULL ), searches must also match the protocol.
       
   342 
       
   343 Examples:
       
   344 @code
       
   345 #include<stdio.h>
       
   346 #include<netinet/in.h>
       
   347 #include<arpa/inet.h>
       
   348 #include<string.h>
       
   349 #include<netdb.h>
       
   350 int main()
       
   351 {
       
   352 Char *service="http";
       
   353 Char *protocol="tcp";
       
   354 Struct servent *p=0;
       
   355 P=getservbyname(service,protocol);
       
   356 if(p!=NULL)
       
   357 printf("service not supported:");
       
   358 else
       
   359 printf("Service  supported");
       
   360 return 0;
       
   361 }
       
   362 
       
   363 @endcode
       
   364 @code
       
   365 #include<stdio.h>
       
   366 #include<netinet/in.h>
       
   367 #include<arpa/inet.h>
       
   368 #include<string.h>
       
   369 #include<netdb.h>
       
   370 int main()
       
   371 {
       
   372 struct servent *p;
       
   373 char *protocol="tcp";
       
   374 int port;
       
   375 port=htons(80);
       
   376 p=(port,protocol);
       
   377 if(p)
       
   378 {
       
   379 Printf("port is  assigned");
       
   380 else
       
   381 printf("port is not assigned");
       
   382 }
       
   383 
       
   384 @endcode
       
   385  Output
       
   386 @code
       
   387 Port is assigned
       
   388 
       
   389 @endcode
       
   390 @code
       
   391 #include<stdio.h>
       
   392 #include<netinet/in.h>
       
   393 #include<arpa/inet.h>
       
   394 #include<string.h>
       
   395 #include<netdb.h>
       
   396 Int main()
       
   397 {
       
   398 struct servent *p;
       
   399 p=getservent();
       
   400 if(p)
       
   401 printf("getservent successful");
       
   402 else
       
   403 printf("getservent failed");
       
   404 return 0;
       
   405 }
       
   406 
       
   407 @endcode
       
   408  Output
       
   409 @code
       
   410 Getservent passed
       
   411 
       
   412 @endcode
       
   413 @code
       
   414 #include<stdio.h>
       
   415 #include<netinet/in.h>
       
   416 #include<arpa/inet.h>
       
   417 #include<string.h>
       
   418 #include<netdb.h>
       
   419 int main()
       
   420 {
       
   421 int stayopen=1;
       
   422 retservent(stayopen):
       
   423 return 0;
       
   424 }
       
   425 
       
   426 @endcode
       
   427 @code
       
   428 #include<stdio.h>
       
   429 #include<netinet/in.h>
       
   430 #include<arpa/inet.h>
       
   431 #include<string.h>
       
   432 #include<netdb.h>
       
   433 int main()
       
   434 {
       
   435 struct servent *p;
       
   436   p=getservent();
       
   437 if(p)
       
   438 endservent();
       
   439 return 0;
       
   440 }
       
   441 
       
   442 @endcode
       
   443 
       
   444 Diagnostics:
       
   445  Null pointer
       
   446 (0) returned on EOF or error. The getservent, getservbyport, getservbyname, setservent, and endservent functions appeared in BSD 4.2.
       
   447 
       
   448 Bugs:
       
   449 
       
   450  These functions use a thread-specific data storage. If the data is needed 
       
   451 for future use it should be copied before any subsequent calls overwrite it. Expecting 
       
   452 port numbers to fit in a 32 bit quantity is probably naive. 
       
   453  
       
   454 
       
   455 @publishedAll
       
   456 @externallyDefinedApi
       
   457 */
       
   458 
       
   459 /** @fn getaddrinfo(const char *hostname, const char *servname,const struct addrinfo *hints, struct addrinfo **res)
       
   460 @param hostname
       
   461 @param servname
       
   462 @param hints
       
   463 @param res
       
   464 @return A zero return value for getaddrinfo() indicates successful completion; a non-zero return value indicates failure. The possible values for the failures are listed in the ERRORS section.
       
   465 Upon successful return of getaddrinfo(), the location to which res points shall refer to a linked list of addrinfo structures, each of which shall specify a socket address and information for use in creating a socket with which to use that socket address. 
       
   466 The list shall include at least one addrinfo structure. 
       
   467 
       
   468 The freeaddrinfo() function shall free one or more addrinfo structures returned by getaddrinfo(), along with any additional storage associated with those structures. If the ai_next field of the structure is not null, the entire list of structures shall be freed. The freeaddrinfo() function shall support the freeing of arbitrary sublists of an addrinfo list originally returned by getaddrinfo().
       
   469 
       
   470 The getaddrinfo() function shall translate the name of a service location (for example, a host name) and//or a service name and shall return a set of socket addresses and associated information to be used in creating a socket with which to address the specified service.
       
   471 
       
   472 @publishedAll
       
   473 @externallyDefinedApi
       
   474 */
       
   475 
       
   476 /** @fn  getnameinfo( const struct sockaddr * sa , socklen_t salen, char * host,size_t 
       
   477       hostlen, char * serv, size_t servlen, int flags )
       
   478 @param sa
       
   479 @param salen
       
   480 @param host
       
   481 @param hostlen
       
   482 @param serv
       
   483 @param servlen
       
   484 @param flags
       
   485 @return   getnameinfo returns zero on success or one of the error codes listed in gai_strerror if an error occurs.
       
   486 
       
   487 The getnameinfo function is used to convert a sockaddr structure to a pair of host name and service strings. It is a replacement for and provides more flexibility than the gethostbyaddr and getservbyport functions and is the converse of the getaddrinfo function. 
       
   488 The sockaddr structure sa should point to sockaddr_in (for IPv4) that is salen bytes long. 
       
   489 
       
   490 The host and service names associated with sa are stored in host and serv which have length parameters hostlen and servlen. The maximum value for hostlen is NI_MAXHOST and the maximum value for servlen is NI_MAXSERV, as defined by \<netdb.h.\> If a length parameter is zero, no string will be stored. Otherwise, enough space must be provided to store the host name or service string plus a byte for the NUL terminator. 
       
   491 
       
   492 The flags argument is formed by OR ’ing the following values: NI_NOFQDN  A fully qualified domain name is not required for local hosts. The local part of the fully qualified domain name is returned instead.  
       
   493 @code
       
   494 NI_NUMERICHOST  Return the address in numeric form, as if calling inet_ntop, instead of a host name.  
       
   495 NI_NAMEREQD  A name is required. If the host name cannot be found in DNS and this flag is set, a non-zero error code is returned. If the host name is not found and the flag is not set, the address is returned in numeric form.  
       
   496 NI_NUMERICSERV  The service name is returned as a digit string representing the port number.  
       
   497 NI_DGRAM  Specifies that the service being looked up is a datagram service, and causes getservbyport to be called with a second argument of "udp" instead of its default of "tcp." This is required for the few ports (512-514) that have different services for UDP and TCP.  
       
   498 @endcode
       
   499 
       
   500 
       
   501 
       
   502 Examples:
       
   503 @code
       
   504 #include <stdio.h>
       
   505 #include <netdb.h>
       
   506 #include <netinet/in.h>
       
   507 int main()
       
   508 {
       
   509      struct addrinfo *result;
       
   510      char hostname[80];
       
   511      int error;
       
   512      if (error = getaddrinfo("www.yahoo.com",NULL, NULL, &result;))
       
   513      {
       
   514             fprintf(stderr, "error using getaddrinfo: %s
       
   515 ", gai_strerror(error));
       
   516      }
       
   517      if (result)
       
   518      {
       
   519             if (error = getnameinfo(result->ai_addr,result->ai_addrlen, hostname, sizeof(hostname), NULL,0,0))
       
   520             {
       
   521                    printf( "error using getnameinfo: %s
       
   522 ", gai_strerror(error));
       
   523             }
       
   524     }
       
   525 return 0;
       
   526 }
       
   527 
       
   528 @endcode
       
   529 @see gai_strerror()
       
   530 @see getaddrinfo()
       
   531 @see inet_ntop()
       
   532 
       
   533 
       
   534 Caveats:
       
   535 
       
   536  getnameinfo can return both numeric and FQDN forms of the address specified in sa. There is no return value that indicates whether the string returned in host is a result of binary to numeric-text translation (like inet_ntop or is the result of a DNS reverse lookup.
       
   537 Because of this, malicious parties could set up a PTR record as follows:
       
   538 @code
       
   539 1.0.0.127.in-addr.arpa. IN PTR  10.1.1.1
       
   540 
       
   541 @endcode
       
   542  and trick the caller of getnameinfo into believing that sa is 10.1.1.1
       
   543 when it is actually 127.0.0.1. To prevent such attacks, the use of NI_NAMEREQD is recommended when the result of getnameinfo is used
       
   544 for access control purposes:
       
   545 @code
       
   546 struct sockaddr *sa;
       
   547 socklen_t salen;
       
   548 char addr[NI_MAXHOST];
       
   549 struct addrinfo hints, *res;
       
   550 int error;
       
   551 error = getnameinfo(sa, salen, addr, sizeof(addr),
       
   552     NULL, 0, NI_NAMEREQD);
       
   553 if (error == 0) {
       
   554         memset(&hints;, 0, sizeof(hints));
       
   555         hints.ai_socktype = SOCK_DGRAM; /*dummy*/
       
   556         hints.ai_flags = AI_NUMERICHOST;
       
   557         if (getaddrinfo(addr, "0", &hints;, &res;) == 0) {
       
   558                 /* malicious PTR record */
       
   559                 freeaddrinfo(res);
       
   560                 printf("bogus PTR record
       
   561 ");
       
   562                 return -1;
       
   563         }
       
   564         /* addr is FQDN as a result of PTR lookup */
       
   565 } else {
       
   566         /* addr is numeric string */
       
   567         error = getnameinfo(sa, salen, addr, sizeof(addr),
       
   568             NULL, 0, NI_NUMERICHOST);
       
   569 }
       
   570 
       
   571 @endcode
       
   572  
       
   573 Caveats:
       
   574 
       
   575  getnameinfo can return both numeric and FQDN forms of the address specified in sa. There is no return value that indicates whether the string returned in host is a result of binary to numeric-text translation (like inet_ntop or is the result of a DNS reverse lookup.
       
   576 Because of this, malicious parties could set up a PTR record as follows:
       
   577 @code
       
   578 1.0.0.127.in-addr.arpa. IN PTR  10.1.1.1
       
   579 
       
   580 @endcode
       
   581  and trick the caller of getnameinfo into believing that sa is 10.1.1.1
       
   582 when it is actually 127.0.0.1. To prevent such attacks, the use of NI_NAMEREQD is recommended when the result of getnameinfo is used
       
   583 for access control purposes:
       
   584 @code
       
   585 struct sockaddr *sa;
       
   586 socklen_t salen;
       
   587 char addr[NI_MAXHOST];
       
   588 struct addrinfo hints, *res;
       
   589 int error;
       
   590 error = getnameinfo(sa, salen, addr, sizeof(addr),
       
   591     NULL, 0, NI_NAMEREQD);
       
   592 if (error == 0) {
       
   593         memset(&hints;, 0, sizeof(hints));
       
   594         hints.ai_socktype = SOCK_DGRAM; /*dummy*/
       
   595         hints.ai_flags = AI_NUMERICHOST;
       
   596         if (getaddrinfo(addr, "0", &hints;, &res;) == 0) {
       
   597                 /* malicious PTR record */
       
   598                 freeaddrinfo(res);
       
   599                 printf("bogus PTR record
       
   600 ");
       
   601                 return -1;
       
   602         }
       
   603         /* addr is FQDN as a result of PTR lookup */
       
   604 } else {
       
   605         /* addr is numeric string */
       
   606         error = getnameinfo(sa, salen, addr, sizeof(addr),
       
   607             NULL, 0, NI_NUMERICHOST);
       
   608 }
       
   609 
       
   610 @endcode
       
   611  
       
   612  
       
   613 
       
   614 @publishedAll
       
   615 @externallyDefinedApi
       
   616 */
       
   617 
       
   618 /** @fn  freeaddrinfo(struct addrinfo *ai)
       
   619 @param ai
       
   620 Refer to t() for the documentation
       
   621 @see bind()
       
   622 @see connect()
       
   623 @see send()
       
   624 @see socket()
       
   625 @see gai_strerror()
       
   626 @see gethostbyname()
       
   627 @see getnameinfo()
       
   628 @see getservent()
       
   629 
       
   630 
       
   631  
       
   632 
       
   633 @publishedAll
       
   634 @externallyDefinedApi
       
   635 */
       
   636 
       
   637 /** @fn  gai_strerror(int ecode)
       
   638 @param ecode
       
   639 @return   The gai_strerror function
       
   640 returns a pointer to the error message string corresponding to ecode. If ecode is out of range, an implementation-specific error message string is returned.
       
   641 
       
   642 @code
       
   643  EAI_AGAIN temporary failure in name resolution
       
   644  EAI_BADFLAGS
       
   645   invalid value for ai_flags
       
   646  EAI_BADHINTS
       
   647   invalid value for hints
       
   648  EAI_FAIL non-recoverable failure in name resolution
       
   649  EAI_FAMILY ai_family not supported
       
   650  EAI_MEMORY memory allocation failure
       
   651  EAI_NONAME hostname or servname not provided, or not known
       
   652  EAI_PROTOCOL
       
   653   resolved protocol is unknown
       
   654  EAI_SERVICE servname not supported for ai_socktype
       
   655  EAI_SOCKTYPE
       
   656   ai_socktype not supported
       
   657  EAI_SYSTEM system error returned in errno
       
   658 
       
   659 @endcode
       
   660   The gai_strerror function returns an error message string corresponding to the error code
       
   661 returned by getaddrinfo or getnameinfo .
       
   662 
       
   663  The following error codes and their meaning are defined in \#include \<netdb.h\>
       
   664 
       
   665  EAI_AGAIN temporary failure in name resolution EAI_BADFLAGS  invalid value for ai_flags EAI_BADHINTS  invalid value for hints EAI_FAIL non-recoverable failure in name resolution EAI_FAMILY ai_family not supported EAI_MEMORY memory allocation failure EAI_NONAME hostname or servname not provided, or not known EAI_PROTOCOL  resolved protocol is unknown EAI_SERVICE servname not supported for ai_socktype EAI_SOCKTYPE  ai_socktype not supported EAI_SYSTEM system error returned in errno
       
   666 
       
   667 Examples:
       
   668 @code
       
   669 #include <stdio.h>
       
   670 #include <netdb.h>
       
   671 #include <netinet/in.h>
       
   672 int main()
       
   673 {
       
   674       struct addrinfo *result;
       
   675       char hostname[80];
       
   676       int error;
       
   677       if (error = getaddrinfo("www.nokia.com",NULL, NULL, &result;))
       
   678       {
       
   679               fprintf(stderr, "error using getaddrinfo: %s
       
   680 ", gai_strerror(error));
       
   681       }
       
   682       if (result)
       
   683       {
       
   684               if (error = getnameinfo(result->ai_addr, sizeof(struct sockaddr), hostname, sizeof(hostname), NULL,0,0))
       
   685               {
       
   686                       printf( "error using getnameinfo: %s
       
   687 ", gai_strerror(error));
       
   688               }
       
   689       }
       
   690 return 0;
       
   691 }
       
   692 
       
   693 @endcode
       
   694 @see getaddrinfo()
       
   695 @see getnameinfo()
       
   696 
       
   697 
       
   698  
       
   699 
       
   700 @publishedAll
       
   701 @externallyDefinedApi
       
   702 */
       
   703 
       
   704 /** @fn  setservent(int f)
       
   705 @param f
       
   706 Refer to  getservent() for the documentation
       
   707 
       
   708 
       
   709  
       
   710 
       
   711 @publishedAll
       
   712 @externallyDefinedApi
       
   713 */
       
   714 
       
   715 /** @def h_errno
       
   716 
       
   717 defines errno
       
   718 
       
   719 @publishedAll
       
   720 @externallyDefinedApi
       
   721 */
       
   722 
       
   723 /** @def _PATH_SERVICES
       
   724 
       
   725 Defines the services path.
       
   726 
       
   727 @publishedAll
       
   728 @externallyDefinedApi
       
   729 */
       
   730 
       
   731 /** @def NETDB_INTERNAL
       
   732 
       
   733 Error return codes from gethostbyname() and gethostbyaddr(). see errno.
       
   734 
       
   735 @publishedAll
       
   736 @externallyDefinedApi
       
   737 */
       
   738 
       
   739 /** @def NETDB_SUCCESS
       
   740 
       
   741 Error return codes from gethostbyname() and gethostbyaddr(). No Problem.
       
   742 
       
   743 @publishedAll
       
   744 @externallyDefinedApi
       
   745 */
       
   746 
       
   747 /** @def HOST_NOT_FOUND
       
   748 
       
   749 Error return codes from gethostbyname() and gethostbyaddr(). Authoritative Answer Host not found.
       
   750 
       
   751 @publishedAll
       
   752 @externallyDefinedApi
       
   753 */
       
   754 
       
   755 /** @def TRY_AGAIN
       
   756 
       
   757 Error return codes from gethostbyname() and gethostbyaddr(). Non-Authoritative Host not found, or SERVERFAIL
       
   758 
       
   759 @publishedAll
       
   760 @externallyDefinedApi
       
   761 */
       
   762 
       
   763 /** @def NO_RECOVERY
       
   764 
       
   765 Error return codes from gethostbyname() and gethostbyaddr(). Non recoverable errors, FORMERR, REFUSED, NOTIMP
       
   766 
       
   767 @publishedAll
       
   768 @externallyDefinedApi
       
   769 */
       
   770 
       
   771 /** @def NO_DATA
       
   772 
       
   773 Error return codes from gethostbyname() and gethostbyaddr(). Valid name, no data record of requested type
       
   774 
       
   775 @publishedAll
       
   776 @externallyDefinedApi
       
   777 */
       
   778 
       
   779 /** @def NO_ADDRESS
       
   780 
       
   781 Error return codes from gethostbyname() and gethostbyaddr(). no address, look for MX record
       
   782 
       
   783 @publishedAll
       
   784 @externallyDefinedApi
       
   785 */
       
   786 
       
   787 /** @def EAI_AGAIN
       
   788 
       
   789 Error return codes from getaddrinfo(). emporary failure in name resolution 
       
   790 
       
   791 @publishedAll
       
   792 @externallyDefinedApi
       
   793 */
       
   794 
       
   795 /** @def EAI_BADFLAGS
       
   796 
       
   797 Error return codes from getaddrinfo(). invalid value for ai_flags
       
   798 
       
   799 @publishedAll
       
   800 @externallyDefinedApi
       
   801 */
       
   802 
       
   803 /** @def EAI_FAIL
       
   804 
       
   805 Error return codes from getaddrinfo(). non-recoverable failure in name resolution
       
   806 
       
   807 @publishedAll
       
   808 @externallyDefinedApi
       
   809 */
       
   810 
       
   811 /** @def EAI_FAMILY
       
   812 
       
   813 Error return codes from getaddrinfo(). ai_family not supported 
       
   814 
       
   815 @publishedAll
       
   816 @externallyDefinedApi
       
   817 */
       
   818 
       
   819 /** @def EAI_MEMORY
       
   820 
       
   821 Error return codes from getaddrinfo(). memory allocation failure .
       
   822 
       
   823 @publishedAll
       
   824 @externallyDefinedApi
       
   825 */
       
   826 
       
   827 /** @def EAI_NONAME
       
   828 
       
   829 Error return codes from getaddrinfo(). hostname nor servname provided, or not known.
       
   830 
       
   831 @publishedAll
       
   832 @externallyDefinedApi
       
   833 */
       
   834 
       
   835 /** @def EAI_SERVICE
       
   836 
       
   837 Error return codes from getaddrinfo(). servname not supported for ai_socktype.
       
   838 
       
   839 @publishedAll
       
   840 @externallyDefinedApi
       
   841 */
       
   842 
       
   843 /** @def EAI_SOCKTYPE
       
   844 
       
   845 Error return codes from getaddrinfo(). ai_socktype not supported 
       
   846 
       
   847 @publishedAll
       
   848 @externallyDefinedApi
       
   849 */
       
   850 
       
   851 /** @def EAI_SYSTEM
       
   852 
       
   853 Error return codes from getaddrinfo(). system error returned in errno.
       
   854 
       
   855 @publishedAll
       
   856 @externallyDefinedApi
       
   857 */
       
   858 
       
   859 /** @def EAI_SOCKTYPE
       
   860 
       
   861 Error return codes from getaddrinfo(). 
       
   862 
       
   863 @publishedAll
       
   864 @externallyDefinedApi
       
   865 */
       
   866  
       
   867 /** @def EAI_BADHINTS
       
   868 
       
   869 Error return codes from getaddrinfo(). 
       
   870 
       
   871 @publishedAll
       
   872 @externallyDefinedApi
       
   873 */
       
   874 
       
   875 /** @def EAI_PROTOCOL
       
   876 
       
   877 Error return codes from getaddrinfo(). 
       
   878 
       
   879 @publishedAll
       
   880 @externallyDefinedApi
       
   881 */
       
   882 
       
   883 /** @def EAI_MAX
       
   884 
       
   885 Error return codes from getaddrinfo(). 
       
   886 
       
   887 @publishedAll
       
   888 @externallyDefinedApi
       
   889 */
       
   890 
       
   891 /** @def AI_PASSIVE
       
   892 
       
   893 Flag values for getaddrinfo(). get address to use bind() 
       
   894 
       
   895 @publishedAll
       
   896 @externallyDefinedApi
       
   897 */
       
   898 
       
   899 /** @def AI_NUMERICHOST
       
   900 
       
   901 Flag values for getaddrinfo(). prevent host name resolution
       
   902 
       
   903 @publishedAll
       
   904 @externallyDefinedApi
       
   905 */
       
   906 
       
   907 /** @def AI_CANONNAME
       
   908 
       
   909 Flag values for getaddrinfo(). fill ai_canonname
       
   910 
       
   911 @publishedAll
       
   912 @externallyDefinedApi
       
   913 */
       
   914 
       
   915 /** @def AI_NUMERICSERV
       
   916 
       
   917 Flag values for getaddrinfo(). prevent service name resolution 
       
   918 
       
   919 @publishedAll
       
   920 @externallyDefinedApi
       
   921 */
       
   922 
       
   923 /** @def AI_MASK
       
   924 
       
   925 valid flags for addrinfo (not a standard def, apps should not use it) 
       
   926 
       
   927 @publishedAll
       
   928 @externallyDefinedApi
       
   929 */
       
   930 
       
   931 /** @def AI_ALL
       
   932 
       
   933 IPv6 and IPv4-mapped (with AI_V4MAPPED) 
       
   934 
       
   935 @publishedAll
       
   936 @externallyDefinedApi
       
   937 */
       
   938 
       
   939 /** @def AI_V4MAPPED_CFG
       
   940 
       
   941 accept IPv4-mapped if kernel supports
       
   942 
       
   943 @publishedAll
       
   944 @externallyDefinedApi
       
   945 */
       
   946 
       
   947 /** @def AI_ADDRCONFIG
       
   948 
       
   949 only if any address is assigned
       
   950 
       
   951 @publishedAll
       
   952 @externallyDefinedApi
       
   953 */
       
   954 
       
   955 /** @def AI_V4MAPPED
       
   956 
       
   957 accept IPv4-mapped IPv6 address
       
   958 
       
   959 @publishedAll
       
   960 @externallyDefinedApi
       
   961 */
       
   962 
       
   963 /** @def AI_DEFAULT
       
   964 
       
   965 special recommended flags for getipnodebyname
       
   966 
       
   967 @publishedAll
       
   968 @externallyDefinedApi
       
   969 */
       
   970 
       
   971 /** @def NI_MAXHOST
       
   972 
       
   973 Constants for getnameinfo()
       
   974 
       
   975 @publishedAll
       
   976 @externallyDefinedApi
       
   977 */
       
   978 
       
   979 /** @def NI_MAXSERV
       
   980 
       
   981 Constants for getnameinfo()
       
   982 
       
   983 @publishedAll
       
   984 @externallyDefinedApi
       
   985 */
       
   986 
       
   987 /** @def NI_NOFQDN
       
   988 
       
   989 Flag values for getnameinfo().
       
   990 Only the nodename portion of the FQDN is returned for local hosts.
       
   991 
       
   992 @publishedAll
       
   993 @externallyDefinedApi
       
   994 */
       
   995 
       
   996 /** @def NI_NUMERICHOST
       
   997 
       
   998 Flag values for getnameinfo().
       
   999 The numeric form of the node's address is returned instead of its name.
       
  1000 
       
  1001 @publishedAll
       
  1002 @externallyDefinedApi
       
  1003 */
       
  1004 
       
  1005 /** @def NI_NAMEREQD
       
  1006 
       
  1007 Flag values for getnameinfo().
       
  1008 Return an error if the node's name cannot be located in the database.
       
  1009 
       
  1010 @publishedAll
       
  1011 @externallyDefinedApi
       
  1012 */
       
  1013 
       
  1014 /** @def NI_NUMERICSERV
       
  1015 
       
  1016 Flag values for getnameinfo().
       
  1017 The numeric form of the service address is returned instead of its name.
       
  1018 
       
  1019 @publishedAll
       
  1020 @externallyDefinedApi
       
  1021 */
       
  1022 
       
  1023 /** @def NI_DGRAM
       
  1024 
       
  1025 Flag values for getnameinfo().
       
  1026 Indicates that the service is a datagram service (SOCK_DGRAM).
       
  1027 
       
  1028 @publishedAll
       
  1029 @externallyDefinedApi
       
  1030 */
       
  1031 
       
  1032 /** @def SCOPE_DELIMITER
       
  1033 
       
  1034 Scope delimit character
       
  1035 
       
  1036 @publishedAll
       
  1037 @externallyDefinedApi
       
  1038 */
       
  1039 
       
  1040 /** @struct hostent
       
  1041 
       
  1042 Structures returned by network data base library.  
       
  1043 All addresses are supplied in host order, and returned in network order (suitable for use in system calls).
       
  1044 
       
  1045 @publishedAll
       
  1046 @externallyDefinedApi
       
  1047 */
       
  1048 
       
  1049 /** @var hostent::h_name
       
  1050 official name of host
       
  1051 */
       
  1052 
       
  1053 /** @var hostent::h_aliases
       
  1054 alias list 
       
  1055 */
       
  1056 
       
  1057 /** @var hostent::h_addrtype
       
  1058 host address type
       
  1059 */
       
  1060 
       
  1061 /** @var hostent::h_length
       
  1062 length of address
       
  1063 */
       
  1064 
       
  1065 /** @var hostent::h_addr_list
       
  1066 list of addresses from name server
       
  1067 */
       
  1068 
       
  1069 /** @struct netent
       
  1070 
       
  1071 Contains following members,
       
  1072 
       
  1073 @publishedAll
       
  1074 @externallyDefinedApi
       
  1075 */
       
  1076 
       
  1077 /** @var netent::n_name
       
  1078 official name of net
       
  1079 */
       
  1080 
       
  1081 /** @var netent::n_aliases
       
  1082 alias list 
       
  1083 */
       
  1084 
       
  1085 /** @var netent::n_addrtype
       
  1086 net address type
       
  1087 */
       
  1088 
       
  1089 /** @var netent::n_net
       
  1090 network
       
  1091 */
       
  1092 
       
  1093 /** @struct servent
       
  1094 
       
  1095 Includes following members,
       
  1096 
       
  1097 @publishedAll
       
  1098 @externallyDefinedApi
       
  1099 */
       
  1100 
       
  1101 /** @var servent::s_name
       
  1102 official service name
       
  1103 */
       
  1104 
       
  1105 /** @var servent::s_aliases
       
  1106 alias list
       
  1107 */
       
  1108 
       
  1109 /** @var servent::s_port
       
  1110  port X
       
  1111 */
       
  1112 
       
  1113 /** @var servent::s_proto
       
  1114 protocol to use 
       
  1115 */
       
  1116 
       
  1117 /** @struct protoent
       
  1118 
       
  1119 Includes the following members,
       
  1120 
       
  1121 @publishedAll
       
  1122 @externallyDefinedApi
       
  1123 */
       
  1124 
       
  1125 /** @var protoent::p_name
       
  1126 official protocol name
       
  1127 */
       
  1128 
       
  1129 /** @var protoent::p_aliases
       
  1130 alias list
       
  1131 */
       
  1132 
       
  1133 /** @var protoent::p_proto
       
  1134 protocol X
       
  1135 */
       
  1136 
       
  1137 /** @struct addrinfo
       
  1138 
       
  1139 Includes the following members,
       
  1140 
       
  1141 @publishedAll
       
  1142 @externallyDefinedApi
       
  1143 */
       
  1144 
       
  1145 /** @var addrinfo::ai_flags
       
  1146 AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST 
       
  1147 */
       
  1148 
       
  1149 /** @var addrinfo::ai_family
       
  1150 PF_xxx
       
  1151 */
       
  1152 
       
  1153 /** @var addrinfo::ai_socktype
       
  1154 SOCK_xxx 
       
  1155 */
       
  1156 
       
  1157 /** @var addrinfo::ai_protocol
       
  1158 0 or IPPROTO_xxx for IPv4 and IPv6
       
  1159 */
       
  1160 
       
  1161 /** @var addrinfo::ai_addrlen
       
  1162 length of ai_addr
       
  1163 */
       
  1164 
       
  1165 /** @var addrinfo::ai_canonname
       
  1166  canonical name for hostname 
       
  1167 */
       
  1168 
       
  1169 /** @var addrinfo::ai_addr
       
  1170 binary address
       
  1171 */
       
  1172 
       
  1173 /** @var addrinfo::ai_next
       
  1174 next structure in linked list
       
  1175 */
       
  1176 
       
  1177 
       
  1178 /** @typedef  typedef __size_t	size_t
       
  1179 
       
  1180 Used for sizes of objects.
       
  1181 
       
  1182 @publishedAll
       
  1183 @externallyDefinedApi
       
  1184 */
       
  1185 
       
  1186 /** @typedef  typedef __socklen_t	socklen_t
       
  1187 
       
  1188 Socket address length type.
       
  1189 
       
  1190 @publishedAll
       
  1191 @externallyDefinedApi
       
  1192 */
       
  1193 
       
  1194 /** @typedef  typedef __uint32_t	uint32_t
       
  1195 
       
  1196 Unsigned long int
       
  1197 
       
  1198 @publishedAll
       
  1199 @externallyDefinedApi
       
  1200 */
       
  1201 
       
  1202 
       
  1203 
       
  1204 
       
  1205 
       
  1206 
       
  1207 
       
  1208 
       
  1209 
       
  1210 
       
  1211 
       
  1212 
       
  1213