inet_addr

Converts an IP address in standard dotted decimal notation to an Internet address.

Library:LibC
Standard:BSD
Service:Networking

Syntax

  #include <arpa/inet.h> 
   
  in_addr_t inet_addr (
     const char   *string);
  

Parameters

string

(IN) Points to the character string (in Internet standard dotted notation) that represents the Internet address.

Return Values

If successful, returns the Internet address. Otherwise, returns (in_addr_t)(-1).

Remarks

The Internet addresses are returned in an in_addr_t structure. For details of this structure, which is also called in_addr, see in_addr.

Values specified using dotted notation take one of the following forms:

a

When only one part of the address is given, the value is stored directly in the network address without any byte rearrangement.

a.b

When a two-part address is supplied, the last part is interpreted as a 24-bit quantity and placed in the rightmost 3 bytes of the network address. This makes the two-part address format convenient for specifying Class A network addresses in net.host format (for example, 89.1 where the network address is 89 and the host address is 1).

a.b.c

When a three-part address is specified, the last part is interpreted as a 16-bit quantity and placed in the rightmost 2 bytes of the network address. This makes the three-part address format convenient for specifying Class B network addresses in net.host format (for example, 128.1.1 where the network address is 128.1 and the host address is 1).

a.b.c.d

When four parts are specified, each part is interpreted as a byte of data and assigned, from left to right, to the four bytes of an Internet address.

All numbers supplied as parts in dotted notation can be expressed in decimal, octal, or hexadecimal, as specified in the C language. (A leading 0x or 0X implies a hexadecimal number, and a leading 0 implies an octal number; otherwise, the number is interpreted as decimal.)