1.\" $NetBSD: inet_net.3,v 1.1 2004/05/20 23:13:02 christos Exp $ 2.\" 3.\" Copyright (c) 1997 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Luke Mewburn. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd December 8, 2001 38.Dt INET_NET 3 39.Os 40.Sh NAME 41.Nm inet_net_ntop , 42.Nm inet_net_pton 43.Nd Internet network number manipulation routines 44.Sh LIBRARY 45.Lb libc 46.Sh SYNOPSIS 47.In sys/socket.h 48.In netinet/in.h 49.In arpa/inet.h 50.Ft char * 51.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" 52.Ft int 53.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" 54.Sh DESCRIPTION 55The 56.Fn inet_net_ntop 57function converts an Internet network number from network format (usually a 58.Ft struct in_addr 59or some other binary form, in network byte order) to CIDR presentation format 60(suitable for external display purposes). 61.Fa bits 62is the number of bits in 63.Fa src 64that are the network number. 65It returns NULL if a system error occurs (in which case, 66.Va errno 67will have been set), or it returns a pointer to the destination string. 68.Pp 69The 70.Fn inet_net_pton 71function converts a presentation format Internet network number (that is, 72printable form as held in a character string) to network format (usually a 73.Ft struct in_addr 74or some other internal binary representation, in network byte order). 75It returns the number of bits (either computed based on the class, or 76specified with /CIDR), or -1 if a failure occurred 77(in which case 78.Va errno 79will have been set. 80It will be set to 81.Er ENOENT 82if the Internet network number was not valid). 83.Pp 84The currently supported values for 85.Fa af 86are 87.Dv AF_INET 88and 89.Dv AF_INET6 . 90.Fa size 91is the size of the result buffer 92.Fa dst . 93.Sh NETWORK NUMBERS (IP VERSION 4) 94Internet network numbers may be specified in one of the following forms: 95.Bd -literal -offset indent 96a.b.c.d/bits 97a.b.c.d 98a.b.c 99a.b 100a 101.Ed 102.Pp 103When four parts are specified, each is interpreted 104as a byte of data and assigned, from left to right, 105to the four bytes of an Internet network number. Note 106that when an Internet network number is viewed as a 32-bit 107integer quantity on a system that uses little-endian 108byte order (such as the 109.Tn Intel 386, 486 110and 111.Tn Pentium 112processors) the bytes referred to above appear as 113.Dq Li d.c.b.a . 114That is, little-endian bytes are ordered from right to left. 115.Pp 116When a three part number is specified, the last 117part is interpreted as a 16-bit quantity and placed 118in the right-most two bytes of the Internet network number. 119This makes the three part number format convenient 120for specifying Class B network numbers as 121.Dq Li 128.net.host . 122.Pp 123When a two part number is supplied, the last part 124is interpreted as a 24-bit quantity and placed in 125the right most three bytes of the Internet network number. 126This makes the two part number format convenient 127for specifying Class A network numbers as 128.Dq Li net.host . 129.Pp 130When only one part is given, the value is stored 131directly in the Internet network number without any byte 132rearrangement. 133.Pp 134All numbers supplied as 135.Dq parts 136in a 137.Ql \&. 138notation 139may be decimal, octal, or hexadecimal, as specified 140in the C language (i.e., a leading 0x or 0X implies 141hexadecimal; otherwise, a leading 0 implies octal; 142otherwise, the number is interpreted as decimal). 143.\" 144.\" .Sh NETWORK NUMBERS (IP VERSION 6) 145.\" XXX - document this! 146.\" 147.Sh SEE ALSO 148.Xr byteorder 3 , 149.Xr inet 3 , 150.Xr networks 5 151.Sh HISTORY 152The 153.Nm inet_net_ntop 154and 155.Nm inet_net_pton 156functions appeared in BIND 4.9.4 and thence 157.Nx 1.3 . 158Support for 159.Dv AF_INET6 160appeared in 161.Nx 1.6 . 162