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 i5/OS 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:
- -1 (unsuccessful)
- n (where n is the 32-bit IP address)
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
- Notation of the dotted decimal address string can be in one of seven
formats:
- Format 1 - a.b.c.d
- Format 2 - a.b.c.
- Format 3 - a.b.c
- Format 4 - a.b.
- Format 5 - a.b
- Format 6 - a.
- Format 7 - a
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:
- For format 1, each component is interpreted as one byte of the internet
address.
- For format 2, each component is interpreted as one byte of the internet
address, and the rightmost byte is set to zero.
- For format 3, each component is interpreted as one byte of the internet
address, except for component c, which is interpreted as the rightmost two
bytes of the internet address.
- For format 4, each component is interpreted as one byte of the internet
address, and the rightmost two bytes are set to zero.
- For format 5, each component is interpreted as one byte of the internet
address, except for component b, which is interpreted as the rightmost three
bytes of the internet address.
- For format 6, component a is interpreted as one byte of the internet
address, and the rightmost three bytes are set to zero.
- For format 7, component a is returned as the internet address.
- 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
- _XOPEN_SOURCE--Using _XOPEN_SOURCE for the UNIX 98
compatible interface
API introduced: V3R1