Chapter Contents

Previous

Next
inet_addr

inet_addr



Interprets an Internet Address

Portability: UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
PORTABILITY
IMPLEMENTATION
RELATED FUNCTIONS


SYNOPSIS

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

unsigned long inet_addr(const char *cp);


DESCRIPTION

inet_addr interprets a null-terminated character string, pointed to by cp , that represents numbers in the Internet standard dotted decimal notation and returns a corresponding Internet address. The dotted decimal string can contain up to four components. All but the last components are placed in succeeding bytes, beginning with the high-order byte. The last component fills all remaining bytes. This dotted decimal notation takes one of the following forms:
a.b.c.d Each section is assigned, from left to right, to the four bytes of an Internet address.
a.b.c The last section is interpreted as a 16-byte quantity and placed in the rightmost two bytes of the network address. In this way, you can specify Class B network addresses as "128.net.host".
a.b The last part is interpreted as a 24-bit quantity and placed in the rightmost three bytes of the network address. In this way, you can specify Class A network addresses as "net.host".
a. This value is stored directly in the network address without rearranging any bytes.

The numbers supplied in dotted decimal notation can be decimal, octal, or hexadecimal, as specified in the C language. In other words, a leading 0x or 0X implies hexadecimal notation; a leading 0 implies octal notation. Otherwise, the number is interpreted as decimal.

The Internet address is returned in network byte order.


RETURN VALUE

If inet_addr is successful, it returns the address in network byte order. Otherwise, it returns a -1UL ( 0xFFFFFFFF ), and sets errno to indicate the type of error. INADDR_NONE is the symbolic name for the -1UL value returned by inet_addr when the input is valid.


PORTABILITY

inet_addr is portable to other environments, including most UNIX systems, that implement BSD sockets. On some systems, this routine may return the type struct in_addr .


IMPLEMENTATION

The SAS/C version of inet_addr is a direct port from the BSD UNIX Socket Library.


RELATED FUNCTIONS

inet_lnaof , inet_makeaddr , inet_netof , inet_network , inet_ntoa


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.