1*61150Sbostic.\" Copyright (c) 1983, 1990, 1991, 1993 2*61150Sbostic.\" The Regents of the University of California. All rights reserved. 320540Smckusick.\" 443572Strent.\" %sccs.include.redist.man% 520540Smckusick.\" 6*61150Sbostic.\" @(#)inet.3 8.1 (Berkeley) 06/04/93 736744Sbostic.\" 848352Scael.Dd 948352Scael.Dt INET 3 1048352Scael.Os BSD 4.2 1148352Scael.Sh NAME 1248352Scael.Nm inet_aton , 1348352Scael.Nm inet_addr , 1448352Scael.Nm inet_network , 1548352Scael.Nm inet_ntoa , 1648352Scael.Nm inet_makeaddr , 1748352Scael.Nm inet_lnaof , 1848352Scael.Nm inet_netof 1948352Scael.Nd Internet address manipulation routines 2048352Scael.Sh SYNOPSIS 2148352Scael.Fd #include <sys/socket.h> 2248352Scael.Fd #include <netinet/in.h> 2348352Scael.Fd #include <arpa/inet.h> 2448352Scael.Ft int 2548352Scael.Fn inet_aton "char *cp" "struct in_addr *pin" 2648352Scael.Ft unsigned long 2748352Scael.Fn inet_addr "char *cp" 2848352Scael.Ft unsigned long 2948352Scael.Fn inet_network "char *cp" 3048352Scael.Ft char * 3148352Scael.Fn inet_ntoa "struct in_addr in" 3248352Scael.Ft struct in_addr 3348352Scael.Fn inet_makeaddr "int net" "int lna" 3448352Scael.Ft unsigned long 3548352Scael.Fn inet_lnaof "struct in_addr in" 3648352Scael.Ft unsigned long 3748352Scael.Fn inet_netof "struct in_addr in" 3848352Scael.Sh DESCRIPTION 3920540SmckusickThe routines 4048352Scael.Fn inet_aton , 4148352Scael.Fn inet_addr 4220540Smckusickand 4348352Scael.Fn inet_network 4443510Skarelsinterpret character strings representing 4548352Scaelnumbers expressed in the Internet standard 4648352Scael.Ql \&. 4743510Skarelsnotation. 4843510SkarelsThe 4948352Scael.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 5548352Scael.Fn inet_addr 5643510Skarelsand 5748352Scael.Fn inet_network 5843510Skarelsfunctions return numbers suitable for use 5920540Smckusickas Internet addresses and Internet network 6043510Skarelsnumbers, respectively. 6143510SkarelsThe routine 6248352Scael.Fn inet_ntoa 6348352Scaeltakes an Internet address and returns an 6448352Scael.Tn ASCII 6548352Scaelstring representing the address in 6648352Scael.Ql \&. 6720540Smckusicknotation. The routine 6848352Scael.Fn inet_makeaddr 6920540Smckusicktakes an Internet network number and a local 7020540Smckusicknetwork address and constructs an Internet address 7120540Smckusickfrom it. The routines 7248352Scael.Fn inet_netof 7320540Smckusickand 7448352Scael.Fn inet_lnaof 7520540Smckusickbreak apart Internet host addresses, returning 7620540Smckusickthe network number and local network address part, 7720540Smckusickrespectively. 7848352Scael.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. 8348352Scael.Sh INTERNET ADDRESSES 8448352ScaelValues specified using the 8548352Scael.Ql \&. 8648352Scaelnotation take one 8720540Smckusickof the following forms: 8848352Scael.Bd -literal -offset indent 8920540Smckusicka.b.c.d 9020540Smckusicka.b.c 9120540Smckusicka.b 9220540Smckusicka 9348352Scael.Ed 9448352Scael.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 9948352Scaelinteger quantity on the 10048352Scael.Tn VAX 10148352Scaelthe bytes referred to 10248352Scaelabove appear as 10348352Scael.Dq Li d.c.b.a . 10448352ScaelThat is, 10548352Scael.Tn VAX 10648352Scaelbytes are 10720540Smckusickordered from right to left. 10848352Scael.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 11448352Scael.Dq Li 128.net.host . 11548352Scael.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 12148352Scael.Dq Li net.host . 12248352Scael.Pp 12320540SmckusickWhen only one part is given, the value is stored 12420540Smckusickdirectly in the network address without any byte 12520540Smckusickrearrangement. 12648352Scael.Pp 12748352ScaelAll numbers supplied as 12848352Scael.Dq parts 12948352Scaelin a 13048352Scael.Ql \&. 13148352Scaelnotation 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). 13648352Scael.Sh DIAGNOSTICS 13748352ScaelThe constant 13848352Scael.Dv INADDR_NONE 13948352Scaelis returned by 14048352Scael.Fn inet_addr 14120540Smckusickand 14248352Scael.Fn inet_network 14320540Smckusickfor malformed requests. 14448352Scael.Sh SEE ALSO 14548352Scael.Xr gethostbyname 3 , 14648352Scael.Xr getnetent 3 , 14748352Scael.Xr hosts 5 , 14848352Scael.Xr networks 5 , 14948352Scael.Sh HISTORY 15048352ScaelThese 15148352Scaelfunctions appeared in 15248352Scael.Bx 4.2 . 15348352Scael.Sh BUGS 15448352ScaelThe value 15548352Scael.Dv INADDR_NONE 15648352Scael(0xffffffff) is a valid broadcast address, but 15748352Scael.Fn inet_addr 15843510Skarelscannot return that value without indicating failure. 15943510SkarelsThe newer 16048352Scael.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 16548352Scael.Fn inet_ntoa 16620540Smckusickresides in a static memory area. 16748352Scael.Pp 16848352ScaelInet_addr should return a 16948352Scael.Fa struct in_addr . 170