inet_addr()--Translate Full Address to 32-bit IP Address


  BSD 4.3 Syntax
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
  #include <arpa/inet.h>

  unsigned long inet_addr(char *address_string)

  Service Program Name: QSOSRV2

  Default Public Authority: *USE

  Threadsafe: Yes



  UNIX® 98 Compatible Syntax
  #define _XOPEN_SOURCE 520
  #include <arpa/inet.h>

  in_addr_t inet_addr(const char *address_string)

  Service Program Name: QSOSRV2

  Default Public Authority: *USE

  Threadsafe: Yes


The inet_addr() function is used to translate an Internet address from dotted decimal format to a 32-bit IP address.

There are two versions of the API, as shown above. The base IBM® i API uses BSD 4.3 structures and syntax. The other uses syntax and structures compatible with the UNIX 98 programming interface specifications. You can select the UNIX 98 compatible interface with the _XOPEN_SOURCE macro.


Parameters

address_string
(Input) The Internet address in dotted decimal format that is to be converted to a 32-bit IP address.

Authorities

No authorization is required.


Return Value

inet_addr() returns an integer. Possible values are:

The inet_addr() subroutine returns an error value of -1 for strings that are not valid.

Note: An Internet address with a dot notation value of 255.255.255.255 or its equivalent in a different base format causes the inet_addr() subroutine to return an unsigned long value of 4294967295. This value is identical to the unsigned representation of the error value. Otherwise, the inet_addr() subroutine considers 255.255.255.255 a valid Internet address.


Error Conditions

When inet_addr() fails, errno can be set to one of the following:

[EFAULT]

Bad address.

The system detected an address which was not valid while attempting to access the address_string parameter.

[EINVAL]

Parameter not valid.


Usage Notes

  1. Notation of the dotted decimal address string can be in one of seven formats:

    Where a component of the dotted decimal format can be decimal (for example, 7.3), octal (for example, 07.3) or hexadecimal (for example, 0xb.3).

    The rules for converting a dotted decimal string are as follows:



  2. When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the inet_addr() API is mapped to qso_inet_addr98().

Related Information



API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]