[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Communications Technical Reference, Volume 2

inet_network Subroutine


Converts an ASCII string containing an Internet network addressee in . (dot) notation to an Internet address number.


Standard C Library (libc.a)


#include <sys/socket.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
unsigned long inet_network (CharString)
char *CharString;


The inet_network subroutine converts an ASCII string containing a valid Internet address using . (dot) notation (such as, ) to an Internet address number formatted as an unsigned long value. The inet_network subroutine returns an error value if the application does not provide an ASCII string containing a valid Internet address using . notation.

The input ASCII string must represent a valid Internet address number, as described in "TCP/IP Addressing" in AIX Version 4.3 System Management Guide: Communications and Networks. The input string must be terminated with a null terminator (0x00) or a space (0x30). The inet_network subroutine ignores characters that follow the terminating character.

The input string can express an Internet address number in decimal, hexadecimal, or octal format. In hexadecimal format, the string must begin with 0x . The string must begin with 0 to indicate octal format. In decimal format, the string requires no prefix.

Each octet of the input string must be delimited from another by a period. The application can omit values between delimiters. The inet_network subroutine interprets missing values as 0.

The following examples show valid strings and their output values in both decimal and hexadecimal notation:

Examples of valid strings
Input String Output Value (in decimal) Output Value (in hex)
...1 1 0x00000001
.1.. 65536 0x00010000
1 256 0x00000100
0xFFFFFFFF 255 0x000000FF
1. 16777216 0x01000000 16909060 0x01020304
0x01.0X2.03.004 16909060 0x01020304
1.2. 3.4 16777218 0x01000002
9999.1.1.1 251724033 0x0F010101

The following examples show invalid input strings and the reasons they are not valid:

Examples of invalid strings
Input String Reason Excessive fields. Excessive delimiters (and therefore fields).
1,2 Bad delimiter.
1p String not terminated by null terminator nor space.
{empty string} No field or delimiter present.

Typically, the value of each octet of an Internet address cannot exceed 246. The inet_network subroutine can accept larger values, but it uses only the eight least significant bits for each field value. For example, if an application passes 0x1234567890.0xabcdef , the inet_network subroutine returns 37103 (0x000090EF ).

The application must verify that the network ID and host ID for the Internet address conform to class A, class B, or class C. The inet_makeaddr subroutine processes any nonconforming number as a class C address.

The inet_network subroutine does not check the pointer to the ASCII input string. The application must verify the validity of the address of the string.


CharString Represents a string of characters in the Internet address form.

Return Values

For valid input strings, the inet_network subroutine returns an unsigned long value that comprises the bit patterns of the input fields concatenated together. The inet_network subroutine places the first pattern in the leftmost (most significant) position and appends subsequent patterns if they exist.

For invalid input strings, the inet_network subroutine returns a value of -1.

Implementation Specifics

The inet_network subroutine is part of Base Operating System (BOS) Runtime.

All applications containing the inet_network subroutine must be compiled with _BSD set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.


                          Contains host names.
                          Contains network names.

Related Information

The endhostent subroutine, endnetent subroutine, gethostbyaddr subroutine, gethostbyname subroutine, getnetbyaddr subroutine, getnetbyname subroutine, getnetent subroutine, inet_addr subroutine, inet_lnaof subroutine, inet_makeaddr subroutine, inet_netof subroutine, inet_ntoa subroutine, sethostent subroutine, setnetent subroutine.

Sockets Overview and Understanding Network Address Translation in AIX Version 4.3 Communications Programming Concepts.

[ Previous | Next | Contents | Glossary | Home | Search ]