VxWorks Reference Manual : Libraries

inetLib

NAME

inetLib - Internet address manipulation routines

ROUTINES

inet_addr( ) - convert a dot notation Internet address to a long integer
inet_lnaof( ) - get the local address (host number) from the Internet address
inet_makeaddr_b( ) - form an Internet address from network and host numbers
inet_makeaddr( ) - form an Internet address from network and host numbers
inet_netof( ) - return the network number from an Internet address
inet_netof_string( ) - extract the network address in dot notation
inet_network( ) - convert an Internet network number from string to address
inet_ntoa_b( ) - convert an network address to dot notation, store it in a buffer
inet_ntoa( ) - convert a network address to dotted decimal notation
inet_aton( ) - convert a network address from dot notation, store in a structure

DESCRIPTION

This library provides routines for manipulating Internet addresses, including the UNIX BSD 4.3 inet_ routines. It includes routines for converting between character addresses in Internet standard dotted decimal notation and integer addresses, routines for extracting the network and host portions out of an Internet address, and routines for constructing Internet addresses given the network and host address parts.

All Internet addresses are returned in network order (bytes ordered from left to right). All network numbers and local address parts are returned as machine format integer values.

INTERNET ADDRESSES

Internet addresses are typically specified in dotted decimal notation or as a 4-byte number. Values specified using the dotted decimal notation take one of the following forms:

        a.b.c.d
        a.b.c
        a.b
        a
If four parts are specified, each is interpreted as a byte of data and assigned, from left to right, to the four bytes of an Internet address. Note that when an Internet address is viewed as a 32-bit integer quantity on any MC68000 family machine, the bytes referred to above appear as "a.b.c.d" and are ordered from left to right.

If a three-part address is specified, the last part is interpreted as a 16-bit quantity and placed in the right-most two bytes of the network address. This makes the three-part address format convenient for specifying Class B network addresses as "128.net.host".

If a two-part address is supplied, the last part is interpreted as a 24-bit quantity and placed in the right-most three bytes of the network address. This makes the two-part address format convenient for specifying Class A network addresses as "net.host".

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

Although dotted decimal notation is the default, it is possible to use the dot notation with hexadecimal or octal numbers. The base is indicated using the same prefixes as are used in C. That is, a leading 0x or 0X indicates a hexadecimal number. A leading 0 indicates an octal number. If there is no prefix, the number is interpreted as decimal.

INCLUDE FILES

inetLib.h, inet.h

SEE ALSO

inetLib, UNIX BSD 4.3 manual entry for inet(3N), VxWorks Programmer's Guide: Network


Libraries : Routines

inet_addr( )

NAME

inet_addr( ) - convert a dot notation Internet address to a long integer

SYNOPSIS

u_long inet_addr
    (
    char * inetString /* string inet address */
    )

DESCRIPTION

This routine interprets an Internet address. All the network library routines call this routine to interpret entries in the data bases which are expected to be an address. The value returned is in network order.

EXAMPLE

The following example returns 0x5a000002:

    inet_addr ("90.0.0.2");

RETURNS

The Internet address, or ERROR.

SEE ALSO

inetLib


Libraries : Routines

inet_lnaof( )

NAME

inet_lnaof( ) - get the local address (host number) from the Internet address

SYNOPSIS

int inet_lnaof
    (
    int inetAddress /* inet addr from which to extract local portion */
    )

DESCRIPTION

This routine returns the local network address portion of an Internet address. The routine handles class A, B, and C network number formats.

EXAMPLE

The following example returns 2:

    inet_lnaof (0x5a000002);

RETURNS

The local address portion of inetAddress.

SEE ALSO

inetLib


Libraries : Routines

inet_makeaddr_b( )

NAME

inet_makeaddr_b( ) - form an Internet address from network and host numbers

SYNOPSIS

void inet_makeaddr_b
    (
    int              netAddr,  /* network part of the inet address */
    int              hostAddr, /* host part of the inet address */
    struct in_addr * pInetAddr /* where to return the inet address */
    )

DESCRIPTION

This routine constructs the Internet address from the network number and local host address. This routine is identical to the UNIX inet_makeaddr( ) routine except that you must provide a buffer for the resulting value.

EXAMPLE

The following copies the address 0x5a000002 to the location pointed to by pInetAddr:

    inet_makeaddr_b (0x5a, 2, pInetAddr);

RETURNS

N/A

SEE ALSO

inetLib


Libraries : Routines

inet_makeaddr( )

NAME

inet_makeaddr( ) - form an Internet address from network and host numbers

SYNOPSIS

struct in_addr inet_makeaddr
    (
    int netAddr, /* network part of the address */
    int hostAddr /* host part of the address */
    )

DESCRIPTION

This routine constructs the Internet address from the network number and local host address.

WARNING

This routine is supplied for UNIX compatibility only. Each time this routine is called, four bytes are allocated from memory. Use inet_makeaddr_b( ) instead.

EXAMPLE

The following example returns the address 0x5a000002 to the structure in_addr:

    inet_makeaddr (0x5a, 2);

RETURNS

The network address in an in_addr structure.

SEE ALSO

inetLib, inet_makeaddr_b( )


Libraries : Routines

inet_netof( )

NAME

inet_netof( ) - return the network number from an Internet address

SYNOPSIS

int inet_netof
    (
    struct in_addr inetAddress /* inet address */
    )

DESCRIPTION

This routine extracts the network portion of an Internet address.

EXAMPLE

The following example returns 0x5a:

    inet_netof (0x5a000002);

RETURNS

The network portion of inetAddress.

SEE ALSO

inetLib


Libraries : Routines

inet_netof_string( )

NAME

inet_netof_string( ) - extract the network address in dot notation

SYNOPSIS

void inet_netof_string
    (
    char * inetString, /* inet addr to extract local portion from */
    char * netString   /* net inet address to return */
    )

DESCRIPTION

This routine extracts the network Internet address from a host Internet address (specified in dotted decimal notation). The routine handles class A, B, and C network addresses. The buffer netString should be INET_ADDR_LEN bytes long.

NOTE

This is the only routine in inetLib that handles subnet masks correctly.

EXAMPLE

The following example copies "90.0.0.0" to netString:

    inet_netof_string ("90.0.0.2", netString);

RETURNS

N/A

SEE ALSO

inetLib


Libraries : Routines

inet_network( )

NAME

inet_network( ) - convert an Internet network number from string to address

SYNOPSIS

u_long inet_network
    (
    char * inetString /* string version of inet addr */
    )

DESCRIPTION

This routine forms a network address from an ASCII string containing an Internet network number.

EXAMPLE

The following example returns 0x5a:

    inet_network ("90");

RETURNS

The Internet address version of an ASCII string.

SEE ALSO

inetLib


Libraries : Routines

inet_ntoa_b( )

NAME

inet_ntoa_b( ) - convert an network address to dot notation, store it in a buffer

SYNOPSIS

void inet_ntoa_b
    (
    struct in_addr inetAddress, /* inet address */
    char *         pString      /* where to return ASCII string */
    )

DESCRIPTION

This routine converts an Internet address in network format to dotted decimal notation.

This routine is identical to the UNIX inet_ntoa( ) routine except that you must provide a buffer of size INET_ADDR_LEN.

EXAMPLE

The following example copies the string "90.0.0.2" to pString:

    struct in_addr iaddr;
     ...
    iaddr.s_addr = 0x5a000002;
     ...
    inet_ntoa_b (iaddr, pString);

RETURNS

N/A

SEE ALSO

inetLib


Libraries : Routines

inet_ntoa( )

NAME

inet_ntoa( ) - convert a network address to dotted decimal notation

SYNOPSIS

char *inet_ntoa
    (
    struct in_addr inetAddress /* inet address */
    )

DESCRIPTION

This routine converts an Internet address in network format to dotted decimal notation.

WARNING

This routine is supplied for UNIX compatibility only. Each time this routine is called, 18 bytes are allocated from memory. Use inet_ntoa_b( ) instead.

EXAMPLE

The following example returns a pointer to the string "90.0.0.2":

    struct in_addr iaddr;
     ...
    iaddr.s_addr = 0x5a000002;
     ...
    inet_ntoa (iaddr);

RETURNS

A pointer to the string version of an Internet address.

SEE ALSO

inetLib, inet_ntoa_b( )


Libraries : Routines

inet_aton( )

NAME

inet_aton( ) - convert a network address from dot notation, store in a structure

SYNOPSIS

STATUS inet_aton
    (
    char *           pString,    /* string containing address, dot notation */
    struct in_addr * inetAddress /* struct in which to store address */
    )

DESCRIPTION

This routine interprets an Internet address. All the network library routines call this routine to interpret entries in the data bases that are expected to be an address. The value returned is stored in network byte order in the structure provided.

EXAMPLE

The following example returns 0x5a000002 in the s_addr member of the structure pointed to by pinetAddr:

    inet_addr ("90.0.0.2", pinetAddr);

RETURNS

OK, or ERROR.

SEE ALSO

inetLib