1.\" Copyright (c) 1983, 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)inet.3 8.1 (Berkeley) 06/04/93 7.\" 8.Dd 9.Dt INET 3 10.Os BSD 4.2 11.Sh NAME 12.Nm inet_aton , 13.Nm inet_addr , 14.Nm inet_network , 15.Nm inet_ntoa , 16.Nm inet_makeaddr , 17.Nm inet_lnaof , 18.Nm inet_netof 19.Nd Internet address manipulation routines 20.Sh SYNOPSIS 21.Fd #include <sys/socket.h> 22.Fd #include <netinet/in.h> 23.Fd #include <arpa/inet.h> 24.Ft int 25.Fn inet_aton "char *cp" "struct in_addr *pin" 26.Ft unsigned long 27.Fn inet_addr "char *cp" 28.Ft unsigned long 29.Fn inet_network "char *cp" 30.Ft char * 31.Fn inet_ntoa "struct in_addr in" 32.Ft struct in_addr 33.Fn inet_makeaddr "int net" "int lna" 34.Ft unsigned long 35.Fn inet_lnaof "struct in_addr in" 36.Ft unsigned long 37.Fn inet_netof "struct in_addr in" 38.Sh DESCRIPTION 39The routines 40.Fn inet_aton , 41.Fn inet_addr 42and 43.Fn inet_network 44interpret character strings representing 45numbers expressed in the Internet standard 46.Ql \&. 47notation. 48The 49.Fn inet_aton 50routine interprets the specified character string as an Internet address, 51placing the address into the structure provided. 52It returns 1 if the string was successfully interpreted, 53or 0 if the string is invalid. 54The 55.Fn inet_addr 56and 57.Fn inet_network 58functions return numbers suitable for use 59as Internet addresses and Internet network 60numbers, respectively. 61The routine 62.Fn inet_ntoa 63takes an Internet address and returns an 64.Tn ASCII 65string representing the address in 66.Ql \&. 67notation. The routine 68.Fn inet_makeaddr 69takes an Internet network number and a local 70network address and constructs an Internet address 71from it. The routines 72.Fn inet_netof 73and 74.Fn inet_lnaof 75break apart Internet host addresses, returning 76the network number and local network address part, 77respectively. 78.Pp 79All Internet addresses are returned in network 80order (bytes ordered from left to right). 81All network numbers and local address parts are 82returned as machine format integer values. 83.Sh INTERNET ADDRESSES 84Values specified using the 85.Ql \&. 86notation take one 87of the following forms: 88.Bd -literal -offset indent 89a.b.c.d 90a.b.c 91a.b 92a 93.Ed 94.Pp 95When four parts are specified, each is interpreted 96as a byte of data and assigned, from left to right, 97to the four bytes of an Internet address. Note 98that when an Internet address is viewed as a 32-bit 99integer quantity on the 100.Tn VAX 101the bytes referred to 102above appear as 103.Dq Li d.c.b.a . 104That is, 105.Tn VAX 106bytes are 107ordered from right to left. 108.Pp 109When a three part address is specified, the last 110part is interpreted as a 16-bit quantity and placed 111in the right-most two bytes of the network address. 112This makes the three part address format convenient 113for specifying Class B network addresses as 114.Dq Li 128.net.host . 115.Pp 116When a two part address is supplied, the last part 117is interpreted as a 24-bit quantity and placed in 118the right most three bytes of the network address. 119This makes the two part address format convenient 120for specifying Class A network addresses as 121.Dq Li net.host . 122.Pp 123When only one part is given, the value is stored 124directly in the network address without any byte 125rearrangement. 126.Pp 127All numbers supplied as 128.Dq parts 129in a 130.Ql \&. 131notation 132may be decimal, octal, or hexadecimal, as specified 133in the C language (i.e., a leading 0x or 0X implies 134hexadecimal; otherwise, a leading 0 implies octal; 135otherwise, the number is interpreted as decimal). 136.Sh DIAGNOSTICS 137The constant 138.Dv INADDR_NONE 139is returned by 140.Fn inet_addr 141and 142.Fn inet_network 143for malformed requests. 144.Sh SEE ALSO 145.Xr gethostbyname 3 , 146.Xr getnetent 3 , 147.Xr hosts 5 , 148.Xr networks 5 , 149.Sh HISTORY 150These 151functions appeared in 152.Bx 4.2 . 153.Sh BUGS 154The value 155.Dv INADDR_NONE 156(0xffffffff) is a valid broadcast address, but 157.Fn inet_addr 158cannot return that value without indicating failure. 159The newer 160.Fn inet_aton 161function does not share this problem. 162The problem of host byte ordering versus network byte ordering is 163confusing. 164The string returned by 165.Fn inet_ntoa 166resides in a static memory area. 167.Pp 168Inet_addr should return a 169.Fa struct in_addr . 170