1.\" Copyright (c) 1983, 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93 33.\" $FreeBSD$ 34.\" 35.Dd June 17, 1996 36.Dt INET 3 37.Os BSD 4.2 38.Sh NAME 39.Nm inet_aton , 40.Nm inet_addr , 41.Nm inet_network , 42.Nm inet_ntoa , 43.Nm inet_makeaddr , 44.Nm inet_lnaof , 45.Nm inet_netof 46.Nd Internet address manipulation routines 47.Sh SYNOPSIS 48.Fd #include <sys/types.h> 49.Fd #include <sys/socket.h> 50.Fd #include <netinet/in.h> 51.Fd #include <arpa/inet.h> 52.Ft int 53.Fn inet_aton "const char *cp" "struct in_addr *pin" 54.Ft unsigned long 55.Fn inet_addr "const char *cp" 56.Ft unsigned long 57.Fn inet_network "const char *cp" 58.Ft char * 59.Fn inet_ntoa "struct in_addr in" 60.Ft struct in_addr 61.Fn inet_makeaddr "unsigned long net" "unsigned long lna" 62.Ft unsigned long 63.Fn inet_lnaof "struct in_addr in" 64.Ft unsigned long 65.Fn inet_netof "struct in_addr in" 66.Sh DESCRIPTION 67The routines 68.Fn inet_aton , 69.Fn inet_addr 70and 71.Fn inet_network 72interpret character strings representing 73numbers expressed in the Internet standard 74.Ql \&. 75notation. 76The 77.Fn inet_aton 78routine interprets the specified character string as an Internet address, 79placing the address into the structure provided. 80It returns 1 if the string was successfully interpreted, 81or 0 if the string is invalid. 82The 83.Fn inet_addr 84and 85.Fn inet_network 86functions return numbers suitable for use 87as Internet addresses and Internet network 88numbers, respectively. 89The routine 90.Fn inet_ntoa 91takes an Internet address and returns an 92.Tn ASCII 93string representing the address in 94.Ql \&. 95notation. The routine 96.Fn inet_makeaddr 97takes an Internet network number and a local 98network address and constructs an Internet address 99from it. The routines 100.Fn inet_netof 101and 102.Fn inet_lnaof 103break apart Internet host addresses, returning 104the network number and local network address part, 105respectively. 106.Pp 107All Internet addresses are returned in network 108order (bytes ordered from left to right). 109All network numbers and local address parts are 110returned as machine format integer values. 111.Sh INTERNET ADDRESSES 112Values specified using the 113.Ql \&. 114notation take one 115of the following forms: 116.Bd -literal -offset indent 117a.b.c.d 118a.b.c 119a.b 120a 121.Ed 122.Pp 123When four parts are specified, each is interpreted 124as a byte of data and assigned, from left to right, 125to the four bytes of an Internet address. Note 126that when an Internet address is viewed as a 32-bit 127integer quantity on the 128.Tn VAX 129the bytes referred to 130above appear as 131.Dq Li d.c.b.a . 132That is, 133.Tn VAX 134bytes are 135ordered from right to left. 136.Pp 137When a three part address is specified, the last 138part is interpreted as a 16-bit quantity and placed 139in the right-most two bytes of the network address. 140This makes the three part address format convenient 141for specifying Class B network addresses as 142.Dq Li 128.net.host . 143.Pp 144When a two part address is supplied, the last part 145is interpreted as a 24-bit quantity and placed in 146the right most three bytes of the network address. 147This makes the two part address format convenient 148for specifying Class A network addresses as 149.Dq Li net.host . 150.Pp 151When only one part is given, the value is stored 152directly in the network address without any byte 153rearrangement. 154.Pp 155All numbers supplied as 156.Dq parts 157in a 158.Ql \&. 159notation 160may be decimal, octal, or hexadecimal, as specified 161in the C language (i.e., a leading 0x or 0X implies 162hexadecimal; otherwise, a leading 0 implies octal; 163otherwise, the number is interpreted as decimal). 164.Pp 165The 166.Fn inet_aton 167and 168.Fn inet_ntoa 169functions are semi-deprecated in favor of the 170.Xr addr2ascii 3 171family. However, since those functions are not yet widely implemented, 172portable programs cannot rely on their presence and will continue 173to use the 174.Xr inet 3 175functions for some time. 176.Sh DIAGNOSTICS 177The constant 178.Dv INADDR_NONE 179is returned by 180.Fn inet_addr 181and 182.Fn inet_network 183for malformed requests. 184.Sh SEE ALSO 185.Xr addr2ascii 3 , 186.Xr gethostbyname 3 , 187.Xr getnetent 3 , 188.Xr hosts 5 , 189.Xr networks 5 190.Sh HISTORY 191These 192functions appeared in 193.Bx 4.2 . 194.Sh BUGS 195The value 196.Dv INADDR_NONE 197(0xffffffff) is a valid broadcast address, but 198.Fn inet_addr 199cannot return that value without indicating failure. 200The newer 201.Fn inet_aton 202function does not share this problem. 203The problem of host byte ordering versus network byte ordering is 204confusing. 205The string returned by 206.Fn inet_ntoa 207resides in a static memory area. 208.Pp 209Inet_addr should return a 210.Fa struct in_addr . 211