isinet_addr Subroutine

Purpose

Determines if the given ASCII string contains an Internet address using dot notation.

Library

Standard C Library (libc.a)

Syntax

#include <sys/types.h>
#include <netinet/in.h>

u_long isinet_addr (name)
char * name;

Description

The isinet_addr subroutine determines if the given ASCII string contains an Internet address using dot notation (for example, "120.121.122.123"). The isaddr_inet subroutine considers Internet address strings as a valid string, and considers any other string type as an invalid strings.

The isinet_addr subrountine expects the ASCII string to conform to the following format:

string ::= field | field delimited_field^1-3 
delimited_field ::= delimiter field
delimiter ::= .
field ::= 0 X | 0 x | 0 X hexadecimal* | 0 x hexadecimal* | decimal* | 0 octal*
hexadecimal ::= decimal | a | b | c | d | e | f | A | B | C | D | E | F
decimal ::= octal | 8 | 9
octal ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
Value Description
A^n Indicates n repetitions of pattern A.
A^n-m Indicates n to m repetitions of pattern A.
A* Indicates zero or more repetitions of pattern A, up to environmental limits.

The BNF description explicitly states the space character (' '), if used.

Value Description
{text} Indicates text, not a BNF symbol.

The isinet_addr subrountine allows the application to terminate the string with a null terminator (0x00) or a space (0x30). It ignores characters trailing the space character and considers the string invalid if the application does not terminate the string with a null terminator (0x00) or space (0x30).

The following describes the restrictions on the field values:

Address Format Field Restrictions (values in decimal base)
a a < 4294967296.
a.b a < 256; b < 16777216.
a.b.c a < 256; b < 256; c < 16777216.
a.b.c.d a < 256; b < 2^8; c < 256; d < 256.

The isinet_addr subrountine applications can enter field values exceeding the field value restrictions specified previously; isinet_addr accepts the least significant bits up to an integer in length. The isinet_addr subroutine still checks to see if the truncated value exceeds the maximum field value. For example, if an application gives the string 0.0;0;0xFF00000001 then isinet_addr interprets the string as 0.0.0.0x00000001 and considers the string as valid.

isinet_addr applications cannot omit field values between delimiters and considers a string with successive periods as invalid.

Examples of valid strings:

Input String Comment
1 isinet_addr uses a format.
1.2 isinet_addr uses a.b format.
1.2.3.4 isinet_addr uses a.b.c.d format.
0x01.0X2.03.004 isinet_addr uses a.b.c.d format.
1.2 3.4 isinet_addr uses a.b format; and ignores "3.4".

Examples of invalid strings:

Input String Reason
... No explicit field values specified.
1.2.3.4.5 Excessive fields.
1.2.3.4. Excessive delimiters and fields.
1,2 Bad delimiter.
1p String not terminated by null terminator nor space.
{empty string} No field or delimiter present.
9999.1.1.1 Value for field a exceeds limit.
Note:
  1. The isinet_addr subroutine does not check the pointer to the ASCII string; the user takes responsibility for ensuring validity of the address of the ASCII string.
  2. The application assumes responsibility for verifying that the network number and host number for the Internet address conforms to a class A or B or C Internet address; any other string is processed as a class C address.

All applications using isinet_addr must compile with the _BSD macro defined. Also, all socket applications must include the BSD library libbsd when applicable.

Parameters

Item Description
name Address of ASCII string buffer.

Return Values

The isinet_addr subroutine returns 1 for valid input strings and 0 for invalid input strings. isinet_addr returns the value as an unsigned long type.

Files

#include <ctype.h>

#include <sys/types.h>