COHERENT manpages
This page displays the COHERENT manpage for inet_addr() [Transform an IP address from text to binary].
List of available manpages
Index
inet_addr() -- Sockets Function (libsocket) Transform an IP address from text to binary #include <netinet/in.h> #include <arpa/inet.h> #include <sys/types.h> ulong inet_addr(ip_address) char *ip_address; The function inet_addr() translates an Internet-protocol (IP) address from text into binary format. ip_address gives the address where the string that holds the IP address resides in memory. If all goes well, inet_addr() returns the binary address that it built from ip_address. If, however, ip_address points to a malformed Internet address, inet_addr() returns -1. An IP address consists of four bytes. The four bytes normally are written as four numbers that are separated by periods; for example, ``199.3.32.100''. This way of rendering an IP address is called dot notation. Each byte can as a written as a decimal, octal, or hexadecimal number. By default, a numbers is written in decimal; a leading ``0x'' or ``0X'' indicates hexadecimal, and a leading `0' indicates octal. When inet_addr() translates an IP address from text into binary, it simply transforms the four numbers as written into four bytes, which it writes into the four bytes of an unsigned long (32-bit) integer, from left to right, without regard to the machine's byte ordering. This means, among other things, that you cannot perform arithmetic on the address that inet_addr() returns -- not even to increment or decrement it. The IP address to which ip_address points can have any of the following four forms: first.second.third.fourth first.second.third first.second first When the string to which ip_address points specifies all four parts of the Internet address, inet_addr() writes all four, from left to right, into the long integer that it returns. When ip_address points to a three-part address, inet_addr() interprets the last (third) part as a 16-bit value, which it writes into into the rightmost two bytes of the network address. When ip_address points to a two-part address, inet_addr() interprets the second part as a 24-bit, which it writes into the rightmost three bytes of the network address. When ip_address points to a one-part address, inet_addr() simply transforms it into an integer without shuffling any bytes. See Also inet_network(), libsocket Notes Because COHERENT does not yet support networking, inet_addr() is a dummy function that always returns zero.