1.\" $NetBSD: inet_net.3,v 1.2 2008/04/30 13:10:50 martin 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.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd December 8, 2001 31.Dt INET_NET 3 32.Os 33.Sh NAME 34.Nm inet_net_ntop , 35.Nm inet_net_pton 36.Nd Internet network number manipulation routines 37.Sh LIBRARY 38.Lb libc 39.Sh SYNOPSIS 40.In sys/socket.h 41.In netinet/in.h 42.In arpa/inet.h 43.Ft char * 44.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" 45.Ft int 46.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" 47.Sh DESCRIPTION 48The 49.Fn inet_net_ntop 50function converts an Internet network number from network format (usually a 51.Ft struct in_addr 52or some other binary form, in network byte order) to CIDR presentation format 53(suitable for external display purposes). 54.Fa bits 55is the number of bits in 56.Fa src 57that are the network number. 58It returns NULL if a system error occurs (in which case, 59.Va errno 60will have been set), or it returns a pointer to the destination string. 61.Pp 62The 63.Fn inet_net_pton 64function converts a presentation format Internet network number (that is, 65printable form as held in a character string) to network format (usually a 66.Ft struct in_addr 67or some other internal binary representation, in network byte order). 68It returns the number of bits (either computed based on the class, or 69specified with /CIDR), or -1 if a failure occurred 70(in which case 71.Va errno 72will have been set. 73It will be set to 74.Er ENOENT 75if the Internet network number was not valid). 76.Pp 77The currently supported values for 78.Fa af 79are 80.Dv AF_INET 81and 82.Dv AF_INET6 . 83.Fa size 84is the size of the result buffer 85.Fa dst . 86.Sh NETWORK NUMBERS (IP VERSION 4) 87Internet network numbers may be specified in one of the following forms: 88.Bd -literal -offset indent 89a.b.c.d/bits 90a.b.c.d 91a.b.c 92a.b 93a 94.Ed 95.Pp 96When four parts are specified, each is interpreted 97as a byte of data and assigned, from left to right, 98to the four bytes of an Internet network number. Note 99that when an Internet network number is viewed as a 32-bit 100integer quantity on a system that uses little-endian 101byte order (such as the 102.Tn Intel 386, 486 103and 104.Tn Pentium 105processors) the bytes referred to above appear as 106.Dq Li d.c.b.a . 107That is, little-endian bytes are ordered from right to left. 108.Pp 109When a three part number is specified, the last 110part is interpreted as a 16-bit quantity and placed 111in the right-most two bytes of the Internet network number. 112This makes the three part number format convenient 113for specifying Class B network numbers as 114.Dq Li 128.net.host . 115.Pp 116When a two part number is supplied, the last part 117is interpreted as a 24-bit quantity and placed in 118the right most three bytes of the Internet network number. 119This makes the two part number format convenient 120for specifying Class A network numbers as 121.Dq Li net.host . 122.Pp 123When only one part is given, the value is stored 124directly in the Internet network number 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.\" 137.\" .Sh NETWORK NUMBERS (IP VERSION 6) 138.\" XXX - document this! 139.\" 140.Sh SEE ALSO 141.Xr byteorder 3 , 142.Xr inet 3 , 143.Xr networks 5 144.Sh HISTORY 145The 146.Nm inet_net_ntop 147and 148.Nm inet_net_pton 149functions appeared in BIND 4.9.4 and thence 150.Nx 1.3 . 151Support for 152.Dv AF_INET6 153appeared in 154.Nx 1.6 . 155