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.\" $Id$ 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/socket.h> 49.Fd #include <netinet/in.h> 50.Fd #include <arpa/inet.h> 51.Ft int 52.Fn inet_aton "char *cp" "struct in_addr *pin" 53.Ft unsigned long 54.Fn inet_addr "char *cp" 55.Ft unsigned long 56.Fn inet_network "char *cp" 57.Ft char * 58.Fn inet_ntoa "struct in_addr in" 59.Ft struct in_addr 60.Fn inet_makeaddr "int net" "int lna" 61.Ft unsigned long 62.Fn inet_lnaof "struct in_addr in" 63.Ft unsigned long 64.Fn inet_netof "struct in_addr in" 65.Sh DESCRIPTION 66The routines 67.Fn inet_aton , 68.Fn inet_addr 69and 70.Fn inet_network 71interpret character strings representing 72numbers expressed in the Internet standard 73.Ql \&. 74notation. 75The 76.Fn inet_aton 77routine interprets the specified character string as an Internet address, 78placing the address into the structure provided. 79It returns 1 if the string was successfully interpreted, 80or 0 if the string is invalid. 81The 82.Fn inet_addr 83and 84.Fn inet_network 85functions return numbers suitable for use 86as Internet addresses and Internet network 87numbers, respectively. 88The routine 89.Fn inet_ntoa 90takes an Internet address and returns an 91.Tn ASCII 92string representing the address in 93.Ql \&. 94notation. The routine 95.Fn inet_makeaddr 96takes an Internet network number and a local 97network address and constructs an Internet address 98from it. The routines 99.Fn inet_netof 100and 101.Fn inet_lnaof 102break apart Internet host addresses, returning 103the network number and local network address part, 104respectively. 105.Pp 106All Internet addresses are returned in network 107order (bytes ordered from left to right). 108All network numbers and local address parts are 109returned as machine format integer values. 110.Sh INTERNET ADDRESSES 111Values specified using the 112.Ql \&. 113notation take one 114of the following forms: 115.Bd -literal -offset indent 116a.b.c.d 117a.b.c 118a.b 119a 120.Ed 121.Pp 122When four parts are specified, each is interpreted 123as a byte of data and assigned, from left to right, 124to the four bytes of an Internet address. Note 125that when an Internet address is viewed as a 32-bit 126integer quantity on the 127.Tn VAX 128the bytes referred to 129above appear as 130.Dq Li d.c.b.a . 131That is, 132.Tn VAX 133bytes are 134ordered from right to left. 135.Pp 136When a three part address is specified, the last 137part is interpreted as a 16-bit quantity and placed 138in the right-most two bytes of the network address. 139This makes the three part address format convenient 140for specifying Class B network addresses as 141.Dq Li 128.net.host . 142.Pp 143When a two part address is supplied, the last part 144is interpreted as a 24-bit quantity and placed in 145the right most three bytes of the network address. 146This makes the two part address format convenient 147for specifying Class A network addresses as 148.Dq Li net.host . 149.Pp 150When only one part is given, the value is stored 151directly in the network address without any byte 152rearrangement. 153.Pp 154All numbers supplied as 155.Dq parts 156in a 157.Ql \&. 158notation 159may be decimal, octal, or hexadecimal, as specified 160in the C language (i.e., a leading 0x or 0X implies 161hexadecimal; otherwise, a leading 0 implies octal; 162otherwise, the number is interpreted as decimal). 163.Pp 164The 165.Fn inet_aton 166and 167.Fn inet_ntoa 168functions are semi-deprecated in favor of the 169.Xr addr2ascii 3 170family. However, since those functions are not yet widely implemented, 171portable programs cannot rely on their presence and will continue 172to use the 173.Xr inet 3 174functions for some time. 175.Sh DIAGNOSTICS 176The constant 177.Dv INADDR_NONE 178is returned by 179.Fn inet_addr 180and 181.Fn inet_network 182for malformed requests. 183.Sh SEE ALSO 184.Xr addr2ascii 3 , 185.Xr gethostbyname 3 , 186.Xr getnetent 3 , 187.Xr hosts 5 , 188.Xr networks 5 , 189.Sh HISTORY 190These 191functions appeared in 192.Bx 4.2 . 193.Sh BUGS 194The value 195.Dv INADDR_NONE 196(0xffffffff) is a valid broadcast address, but 197.Fn inet_addr 198cannot return that value without indicating failure. 199The newer 200.Fn inet_aton 201function does not share this problem. 202The problem of host byte ordering versus network byte ordering is 203confusing. 204The string returned by 205.Fn inet_ntoa 206resides in a static memory area. 207.Pp 208Inet_addr should return a 209.Fa struct in_addr . 210