1*48352Scael.\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California. 236744Sbostic.\" All rights reserved. 320540Smckusick.\" 443572Strent.\" %sccs.include.redist.man% 520540Smckusick.\" 6*48352Scael.\" @(#)inet.3 6.10 (Berkeley) 04/19/91 736744Sbostic.\" 8*48352Scael.Dd 9*48352Scael.Dt INET 3 10*48352Scael.Os BSD 4.2 11*48352Scael.Sh NAME 12*48352Scael.Nm inet_aton , 13*48352Scael.Nm inet_addr , 14*48352Scael.Nm inet_network , 15*48352Scael.Nm inet_ntoa , 16*48352Scael.Nm inet_makeaddr , 17*48352Scael.Nm inet_lnaof , 18*48352Scael.Nm inet_netof 19*48352Scael.Nd Internet address manipulation routines 20*48352Scael.Sh SYNOPSIS 21*48352Scael.Fd #include <sys/socket.h> 22*48352Scael.Fd #include <netinet/in.h> 23*48352Scael.Fd #include <arpa/inet.h> 24*48352Scael.Ft int 25*48352Scael.Fn inet_aton "char *cp" "struct in_addr *pin" 26*48352Scael.Ft unsigned long 27*48352Scael.Fn inet_addr "char *cp" 28*48352Scael.Ft unsigned long 29*48352Scael.Fn inet_network "char *cp" 30*48352Scael.Ft char * 31*48352Scael.Fn inet_ntoa "struct in_addr in" 32*48352Scael.Ft struct in_addr 33*48352Scael.Fn inet_makeaddr "int net" "int lna" 34*48352Scael.Ft unsigned long 35*48352Scael.Fn inet_lnaof "struct in_addr in" 36*48352Scael.Ft unsigned long 37*48352Scael.Fn inet_netof "struct in_addr in" 38*48352Scael.Sh DESCRIPTION 3920540SmckusickThe routines 40*48352Scael.Fn inet_aton , 41*48352Scael.Fn inet_addr 4220540Smckusickand 43*48352Scael.Fn inet_network 4443510Skarelsinterpret character strings representing 45*48352Scaelnumbers expressed in the Internet standard 46*48352Scael.Ql \&. 4743510Skarelsnotation. 4843510SkarelsThe 49*48352Scael.Fn inet_aton 5043510Skarelsroutine interprets the specified character string as an Internet address, 5143510Skarelsplacing the address into the structure provided. 5243510SkarelsIt returns 1 if the string was successfully interpreted, 5343510Skarelsor 0 if the string is invalid. 5443510SkarelsThe 55*48352Scael.Fn inet_addr 5643510Skarelsand 57*48352Scael.Fn inet_network 5843510Skarelsfunctions return numbers suitable for use 5920540Smckusickas Internet addresses and Internet network 6043510Skarelsnumbers, respectively. 6143510SkarelsThe routine 62*48352Scael.Fn inet_ntoa 63*48352Scaeltakes an Internet address and returns an 64*48352Scael.Tn ASCII 65*48352Scaelstring representing the address in 66*48352Scael.Ql \&. 6720540Smckusicknotation. The routine 68*48352Scael.Fn inet_makeaddr 6920540Smckusicktakes an Internet network number and a local 7020540Smckusicknetwork address and constructs an Internet address 7120540Smckusickfrom it. The routines 72*48352Scael.Fn inet_netof 7320540Smckusickand 74*48352Scael.Fn inet_lnaof 7520540Smckusickbreak apart Internet host addresses, returning 7620540Smckusickthe network number and local network address part, 7720540Smckusickrespectively. 78*48352Scael.Pp 7943510SkarelsAll Internet addresses are returned in network 8020540Smckusickorder (bytes ordered from left to right). 8120540SmckusickAll network numbers and local address parts are 8220540Smckusickreturned as machine format integer values. 83*48352Scael.Sh INTERNET ADDRESSES 84*48352ScaelValues specified using the 85*48352Scael.Ql \&. 86*48352Scaelnotation take one 8720540Smckusickof the following forms: 88*48352Scael.Bd -literal -offset indent 8920540Smckusicka.b.c.d 9020540Smckusicka.b.c 9120540Smckusicka.b 9220540Smckusicka 93*48352Scael.Ed 94*48352Scael.Pp 9520540SmckusickWhen four parts are specified, each is interpreted 9620540Smckusickas a byte of data and assigned, from left to right, 9720540Smckusickto the four bytes of an Internet address. Note 9820540Smckusickthat when an Internet address is viewed as a 32-bit 99*48352Scaelinteger quantity on the 100*48352Scael.Tn VAX 101*48352Scaelthe bytes referred to 102*48352Scaelabove appear as 103*48352Scael.Dq Li d.c.b.a . 104*48352ScaelThat is, 105*48352Scael.Tn VAX 106*48352Scaelbytes are 10720540Smckusickordered from right to left. 108*48352Scael.Pp 10920540SmckusickWhen a three part address is specified, the last 11020540Smckusickpart is interpreted as a 16-bit quantity and placed 11143510Skarelsin the right-most two bytes of the network address. 11220540SmckusickThis makes the three part address format convenient 11320540Smckusickfor specifying Class B network addresses as 114*48352Scael.Dq Li 128.net.host . 115*48352Scael.Pp 11620540SmckusickWhen a two part address is supplied, the last part 11720540Smckusickis interpreted as a 24-bit quantity and placed in 11820540Smckusickthe right most three bytes of the network address. 11920540SmckusickThis makes the two part address format convenient 12020540Smckusickfor specifying Class A network addresses as 121*48352Scael.Dq Li net.host . 122*48352Scael.Pp 12320540SmckusickWhen only one part is given, the value is stored 12420540Smckusickdirectly in the network address without any byte 12520540Smckusickrearrangement. 126*48352Scael.Pp 127*48352ScaelAll numbers supplied as 128*48352Scael.Dq parts 129*48352Scaelin a 130*48352Scael.Ql \&. 131*48352Scaelnotation 13220540Smckusickmay be decimal, octal, or hexadecimal, as specified 13328818Skjdin the C language (i.e., a leading 0x or 0X implies 13420540Smckusickhexadecimal; otherwise, a leading 0 implies octal; 13520540Smckusickotherwise, the number is interpreted as decimal). 136*48352Scael.Sh DIAGNOSTICS 137*48352ScaelThe constant 138*48352Scael.Dv INADDR_NONE 139*48352Scaelis returned by 140*48352Scael.Fn inet_addr 14120540Smckusickand 142*48352Scael.Fn inet_network 14320540Smckusickfor malformed requests. 144*48352Scael.Sh SEE ALSO 145*48352Scael.Xr gethostbyname 3 , 146*48352Scael.Xr getnetent 3 , 147*48352Scael.Xr hosts 5 , 148*48352Scael.Xr networks 5 , 149*48352Scael.Sh HISTORY 150*48352ScaelThese 151*48352Scaelfunctions appeared in 152*48352Scael.Bx 4.2 . 153*48352Scael.Sh BUGS 154*48352ScaelThe value 155*48352Scael.Dv INADDR_NONE 156*48352Scael(0xffffffff) is a valid broadcast address, but 157*48352Scael.Fn inet_addr 15843510Skarelscannot return that value without indicating failure. 15943510SkarelsThe newer 160*48352Scael.Fn inet_aton 16143510Skarelsfunction does not share this problem. 16220540SmckusickThe problem of host byte ordering versus network byte ordering is 16343510Skarelsconfusing. 16420540SmckusickThe string returned by 165*48352Scael.Fn inet_ntoa 16620540Smckusickresides in a static memory area. 167*48352Scael.Pp 168*48352ScaelInet_addr should return a 169*48352Scael.Fa struct in_addr . 170