os/ossrv/genericopenlibs/openenvcore/include/arpa/inet.dosc
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /** @file ../include/arpa/inet.h
     2 @internalComponent
     3 */
     4 
     5 /** @fn  inet_addr(const char *cp)
     6 @param cp
     7 
     8 Note: This description also covers the following functions -
     9  inet_aton()  inet_ntoa()  inet_ntop()  inet_pton() 
    10 
    11 @code
    12   struct in_addr or some other internal binary representation, in network byte order).
    13  It returns 1 if the address was valid for the specified address family, or
    14  0 if the address was not parseable in the specified address family, or -1
    15  if some system error occurred.
    16  This function is presently valid for AF_INET and AF_INET6.
    17 @endcode
    18 @code
    19   struct in_addr or some other binary form, in network byte order) to presentation format
    20  (suitable for external display purposes).
    21  The size argument specifies the size, in bytes, of the buffer *dst It returns NULL if a system error occurs (in which case, errno will have been set), or it returns a pointer to the destination string.
    22  This function is presently valid for AF_INET and AF_INET6.
    23 @endcode
    24 @code
    25   The routines inet_addr and inet_aton interpret character strings representing
    26 numbers expressed in the Internet standard ‘.’ notation.
    27 @endcode
    28 
    29  The inet_pton function converts a presentation format address (that is, printable form
    30 as held in a character string) to network format (usually a  struct in_addr or some other internal binary representation, in network byte order).
    31 It returns 1 if the address was valid for the specified address family, or
    32 0 if the address was not parseable in the specified address family, or -1
    33 if some system error occurred.
    34 This function is presently valid for AF_INET and AF_INET6.
    35 
    36  The inet_aton routine interprets the specified character string as an Internet address,
    37 placing the address into the structure provided.
    38 It returns 1 if the string was successfully interpreted,
    39 or 0 if the string is invalid.
    40 The inet_addr functions return numbers suitable for use
    41 as Internet addresses.
    42 
    43  The function inet_ntop converts an address *src from network format
    44 (usually a  struct in_addr or some other binary form, in network byte order) to presentation format
    45 (suitable for external display purposes).
    46 The size argument specifies the size, in bytes, of the buffer *dst It returns NULL if a system error occurs (in which case, errno will have been set), or it returns a pointer to the destination string.
    47 This function is presently valid for AF_INET and AF_INET6.
    48 
    49  The routine inet_ntoa takes an Internet address and returns an ASCII string representing the address in ' . '
    50 notation.
    51 
    52  All Internet addresses are returned in network
    53 order (bytes ordered from left to right).
    54 All network numbers and local address parts are
    55 returned as machine byte order integer values.
    56 
    57 Diagnostics:
    58 
    59  The constant INADDR_NONE is returned by inet_addr for malformed requests.
    60 
    61 @see gethostbyname()
    62 
    63 
    64 Examples:
    65 @code
    66 #include <stdio.h>
    67 #include <arpa/inet.h>
    68 #include <netinet/in.h>
    69 #define IPV6ADDRSIZE 48
    70 int main()
    71     {
    72      unsigned int nbo_value;
    73      char *ipaddrstring="1.2.3.4";
    74      char *ipaddrholdr=NULL;
    75      char *ipv6addrstring="8000::123:4567:89AB:CDEF";
    76      struct in_addr ipstruct;
    77      struct in6_addr ipv6struct;
    78      char result[IPV6ADDRSIZE];
    79      int err;
    80      int size;
    81      const char* error;
    82      nbo_value=inet_addr(ipaddrstring);
    83      if(nbo_value == -1)
    84       {
    85        printf("inet_addr failed0);
    86       }
    87      else
    88       {
    89        printf("inet_addr passed0);
    90       }
    91      ipstruct.s_addr=nbo_value;
    92      ipaddrholdr=inet_ntoa(ipstruct);
    93      if(ipaddrholdr==NULL)
    94       {
    95        printf("inet_ntoa failed0);
    96       }
    97      else
    98       {
    99       printf("ipaddr is %s0,ipaddrholdr);
   100       }
   101      err=inet_pton(AF_INET6,ipv6addrstring ,&ipv6struct;);
   102      if(err ==0  || err==-1)
   103      printf("inet_pton Failed0);
   104      else
   105      printf("inet_pton passed0);
   106      size=sizeof(result);
   107      error=inet_ntop(AF_INET6,&ipv6struct.s6;_addr,result,size);     
   108      if(error==NULL)
   109       {
   110       printf("inet_ntop failed");
   111       }
   112      else
   113       {
   114       printf("inet_ntop passed");
   115       }
   116      err=inet_aton(ipaddrstring,&ipstruct;);
   117      if(err==0)
   118      {
   119       printf("invalid address ");
   120      }
   121      else
   122       {
   123       printf("inet_aton passed ");
   124       }
   125     
   126      return 0;
   127 }
   128 Output:
   129 inet_addr passed
   130 ipaddr is 1.2.3.4
   131 inet_pton passed
   132 inet_ntop passed
   133 inet_aton passed
   134 
   135 @endcode
   136  The inet_ntop and inet_pton functions conform to -xns5.2. Note that inet_pton does not accept 1-, 2-, or 3-part dotted addresses; all four parts
   137 must be specified and are interpreted only as decimal values.
   138 This is a narrower input set than that accepted by inet_aton. These
   139 functions appeared in BSD 4.2.
   140 
   141 Bugs:
   142 
   143  The value INADDR_NONE (0xffffffff) is a valid broadcast address, but inet_addr cannot return that value without indicating failure.
   144 The newer inet_aton function does not share this problem.
   145 The problem of host byte ordering versus network byte ordering is
   146 confusing.
   147 The string returned by inet_ntoa resides in a static memory area. Inet_addr should return a struct in_addr. 
   148 
   149    
   150 
   151 @publishedAll
   152 @externallyDefinedApi
   153 */
   154 
   155 /** @fn  inet_ntoa(struct in_addr in)
   156 @param in
   157 
   158 Refer to  inet_addr() for the documentation
   159 @see gethostbyname()
   160 
   161 
   162  
   163 
   164 @publishedAll
   165 @externallyDefinedApi
   166 */
   167 
   168 /** @fn  inet_ntop(  int af ,  const void *  src,   char *  dst,   socklen_t size)  
   169 @param af
   170 @param src
   171 @param dst
   172 @param size
   173 
   174 Refer to  inet_addr() for the documentation
   175 
   176 @see gethostbyname()
   177 
   178 
   179  
   180 
   181 @publishedAll
   182 @externallyDefinedApi
   183 */
   184 
   185 /** @fn  inet_pton(int af, const char *  src, void *  dst)
   186 @param af
   187 @param src
   188 @param dst
   189 
   190 Refer to  inet_addr() for the documentation
   191 
   192 @see gethostbyname()
   193 
   194 
   195  
   196 
   197 @publishedAll
   198 @externallyDefinedApi
   199 */
   200 
   201 /** @fn  inet_aton(const char *cp, struct in_addr *pin)
   202 @param cp
   203 @param pin
   204 
   205 Refer to  inet_addr() for the documentation
   206 
   207 @see gethostbyname()
   208 
   209 
   210  
   211 
   212 @publishedAll
   213 @externallyDefinedApi
   214 */
   215 
   216 /** @fn  htonl(uint32_t hl)
   217 @param hl
   218 
   219 Note: This description also covers the following functions -
   220  htons()  ntohl()  ntohs() 
   221 
   222   These routines convert 16 and 32 bit quantities between network
   223 byte order and host byte order.
   224 On machines which have a byte order which is the same as the network
   225 order, routines are defined as null macros.
   226 
   227  These routines are most often used in conjunction with Internet
   228 addresses and ports as returned by gethostbyname
   229 and getservent .
   230 
   231 @see gethostbyaddr()
   232 @see getservent()
   233 
   234 
   235 Bugs:
   236 
   237  On the VAX bytes are handled backwards from most everyone else in
   238 the world.
   239 
   240  
   241 
   242 @publishedAll
   243 @externallyDefinedApi
   244 */
   245 
   246 /** @fn  htons(uint16_t hs)
   247 @param hs
   248 
   249 Refer to  htonl() for the documentation
   250 @see gethostbyaddr()
   251 @see getservent()
   252 
   253 
   254  
   255 
   256 @publishedAll
   257 @externallyDefinedApi
   258 */
   259 
   260 /** @def  ntohl
   261 
   262 These are also declared as functions.
   263 
   264 @publishedAll
   265 @externallyDefinedApi
   266 */
   267 
   268 /** @def  ntohs
   269 
   270 These are also declared as functions.
   271 
   272 @publishedAll
   273 @externallyDefinedApi
   274 */
   275 
   276 /** @def  inet_addr
   277 
   278 These are also declared as functions.
   279 
   280 @publishedAll
   281 @externallyDefinedApi
   282 */
   283 
   284 
   285 /** @def  inet_ntoa
   286 
   287 These are also declared as functions.
   288 
   289 @publishedAll
   290 @externallyDefinedApi
   291 */
   292 
   293 
   294 /** @def  inet_pton
   295 
   296 These are also declared as functions.
   297 
   298 @publishedAll
   299 @externallyDefinedApi
   300 */
   301 
   302 
   303 /** @def  inet_ntop
   304 
   305 These are also declared as functions.
   306 
   307 @publishedAll
   308 @externallyDefinedApi
   309 */
   310 
   311