181a3cb97SRuslan Ermilov.\" $NetBSD: inet_net.3,v 1.4 1999/03/22 19:44:52 garbled Exp $ 281a3cb97SRuslan Ermilov.\" 381a3cb97SRuslan Ermilov.\" Copyright (c) 1997 The NetBSD Foundation, Inc. 481a3cb97SRuslan Ermilov.\" All rights reserved. 581a3cb97SRuslan Ermilov.\" 681a3cb97SRuslan Ermilov.\" This code is derived from software contributed to The NetBSD Foundation 781a3cb97SRuslan Ermilov.\" by Luke Mewburn. 881a3cb97SRuslan Ermilov.\" 981a3cb97SRuslan Ermilov.\" Redistribution and use in source and binary forms, with or without 1081a3cb97SRuslan Ermilov.\" modification, are permitted provided that the following conditions 1181a3cb97SRuslan Ermilov.\" are met: 1281a3cb97SRuslan Ermilov.\" 1. Redistributions of source code must retain the above copyright 1381a3cb97SRuslan Ermilov.\" notice, this list of conditions and the following disclaimer. 1481a3cb97SRuslan Ermilov.\" 2. Redistributions in binary form must reproduce the above copyright 1581a3cb97SRuslan Ermilov.\" notice, this list of conditions and the following disclaimer in the 1681a3cb97SRuslan Ermilov.\" documentation and/or other materials provided with the distribution. 1781a3cb97SRuslan Ermilov.\" 3. All advertising materials mentioning features or use of this software 1881a3cb97SRuslan Ermilov.\" must display the following acknowledgement: 1981a3cb97SRuslan Ermilov.\" This product includes software developed by the NetBSD 2081a3cb97SRuslan Ermilov.\" Foundation, Inc. and its contributors. 2181a3cb97SRuslan Ermilov.\" 4. Neither the name of The NetBSD Foundation nor the names of its 2281a3cb97SRuslan Ermilov.\" contributors may be used to endorse or promote products derived 2381a3cb97SRuslan Ermilov.\" from this software without specific prior written permission. 2481a3cb97SRuslan Ermilov.\" 2581a3cb97SRuslan Ermilov.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2681a3cb97SRuslan Ermilov.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2781a3cb97SRuslan Ermilov.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2881a3cb97SRuslan Ermilov.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2981a3cb97SRuslan Ermilov.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3081a3cb97SRuslan Ermilov.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3181a3cb97SRuslan Ermilov.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3281a3cb97SRuslan Ermilov.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3381a3cb97SRuslan Ermilov.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3481a3cb97SRuslan Ermilov.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3581a3cb97SRuslan Ermilov.\" POSSIBILITY OF SUCH DAMAGE. 3681a3cb97SRuslan Ermilov.\" 3781a3cb97SRuslan Ermilov.\" $FreeBSD$ 3881a3cb97SRuslan Ermilov.\" 3912d96fe6SHajimu UMEMOTO.Dd February 26, 2006 4081a3cb97SRuslan Ermilov.Dt INET_NET 3 4181a3cb97SRuslan Ermilov.Os 4281a3cb97SRuslan Ermilov.Sh NAME 4381a3cb97SRuslan Ermilov.Nm inet_net_ntop , 4481a3cb97SRuslan Ermilov.Nm inet_net_pton 4581a3cb97SRuslan Ermilov.Nd Internet network number manipulation routines 4681a3cb97SRuslan Ermilov.Sh LIBRARY 4781a3cb97SRuslan Ermilov.Lb libc 4881a3cb97SRuslan Ermilov.Sh SYNOPSIS 4981a3cb97SRuslan Ermilov.In sys/types.h 5081a3cb97SRuslan Ermilov.In sys/socket.h 5181a3cb97SRuslan Ermilov.In netinet/in.h 5281a3cb97SRuslan Ermilov.In arpa/inet.h 5381a3cb97SRuslan Ermilov.Ft char * 5481a3cb97SRuslan Ermilov.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" 5581a3cb97SRuslan Ermilov.Ft int 5681a3cb97SRuslan Ermilov.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" 5781a3cb97SRuslan Ermilov.Sh DESCRIPTION 5881a3cb97SRuslan ErmilovThe 5981a3cb97SRuslan Ermilov.Fn inet_net_ntop 6081a3cb97SRuslan Ermilovfunction converts an Internet network number from network format (usually a 6181a3cb97SRuslan Ermilov.Vt "struct in_addr" 6281a3cb97SRuslan Ermilovor some other binary form, in network byte order) to CIDR presentation format 6381a3cb97SRuslan Ermilov(suitable for external display purposes). 642efeeba5SRuslan ErmilovThe 6581a3cb97SRuslan Ermilov.Fa bits 662efeeba5SRuslan Ermilovargument 6781a3cb97SRuslan Ermilovis the number of bits in 6881a3cb97SRuslan Ermilov.Fa src 6981a3cb97SRuslan Ermilovthat are the network number. 7081a3cb97SRuslan ErmilovIt returns 7181a3cb97SRuslan Ermilov.Dv NULL 7281a3cb97SRuslan Ermilovif a system error occurs (in which case, 7381a3cb97SRuslan Ermilov.Va errno 7481a3cb97SRuslan Ermilovwill have been set), or it returns a pointer to the destination string. 7581a3cb97SRuslan Ermilov.Pp 7681a3cb97SRuslan ErmilovThe 7781a3cb97SRuslan Ermilov.Fn inet_net_pton 7881a3cb97SRuslan Ermilovfunction converts a presentation format Internet network number (that is, 7981a3cb97SRuslan Ermilovprintable form as held in a character string) to network format (usually a 8081a3cb97SRuslan Ermilov.Vt "struct in_addr" 8181a3cb97SRuslan Ermilovor some other internal binary representation, in network byte order). 8281a3cb97SRuslan ErmilovIt returns the number of bits (either computed based on the class, or 8381a3cb97SRuslan Ermilovspecified with /CIDR), or \-1 if a failure occurred 8481a3cb97SRuslan Ermilov(in which case 8581a3cb97SRuslan Ermilov.Va errno 8681a3cb97SRuslan Ermilovwill have been set. 8781a3cb97SRuslan ErmilovIt will be set to 8881a3cb97SRuslan Ermilov.Er ENOENT 8981a3cb97SRuslan Ermilovif the Internet network number was not valid). 9081a3cb97SRuslan Ermilov.Pp 9112d96fe6SHajimu UMEMOTOThe currently supported values for 9281a3cb97SRuslan Ermilov.Fa af 9312d96fe6SHajimu UMEMOTOare 9412d96fe6SHajimu UMEMOTO.Dv AF_INET 9512d96fe6SHajimu UMEMOTOand 9612d96fe6SHajimu UMEMOTO.Dv AF_INET6 . 972efeeba5SRuslan ErmilovThe 9881a3cb97SRuslan Ermilov.Fa size 992efeeba5SRuslan Ermilovargument 10081a3cb97SRuslan Ermilovis the size of the result buffer 10181a3cb97SRuslan Ermilov.Fa dst . 10281a3cb97SRuslan Ermilov.Pp 10381a3cb97SRuslan Ermilov.Sh NETWORK NUMBERS (IP VERSION 4) 10481a3cb97SRuslan ErmilovInternet network numbers may be specified in one of the following forms: 10581a3cb97SRuslan Ermilov.Bd -literal -offset indent 10681a3cb97SRuslan Ermilova.b.c.d/bits 10781a3cb97SRuslan Ermilova.b.c.d 10881a3cb97SRuslan Ermilova.b.c 10981a3cb97SRuslan Ermilova.b 11081a3cb97SRuslan Ermilova 11181a3cb97SRuslan Ermilov.Ed 11281a3cb97SRuslan Ermilov.Pp 11381a3cb97SRuslan ErmilovWhen four parts are specified, each is interpreted 11481a3cb97SRuslan Ermilovas a byte of data and assigned, from left to right, 11581a3cb97SRuslan Ermilovto the four bytes of an Internet network number. 11681a3cb97SRuslan ErmilovNote 11781a3cb97SRuslan Ermilovthat when an Internet network number is viewed as a 32-bit 11881a3cb97SRuslan Ermilovinteger quantity on a system that uses little-endian 11981a3cb97SRuslan Ermilovbyte order (such as the 12081a3cb97SRuslan Ermilov.Tn Intel 386 , 486 , 12181a3cb97SRuslan Ermilovand 12281a3cb97SRuslan Ermilov.Tn Pentium 12381a3cb97SRuslan Ermilovprocessors) the bytes referred to above appear as 12481a3cb97SRuslan Ermilov.Dq Li d.c.b.a . 12581a3cb97SRuslan ErmilovThat is, little-endian bytes are ordered from right to left. 12681a3cb97SRuslan Ermilov.Pp 12781a3cb97SRuslan ErmilovWhen a three part number is specified, the last 12881a3cb97SRuslan Ermilovpart is interpreted as a 16-bit quantity and placed 12981a3cb97SRuslan Ermilovin the rightmost two bytes of the Internet network number. 13081a3cb97SRuslan ErmilovThis makes the three part number format convenient 13181a3cb97SRuslan Ermilovfor specifying Class B network numbers as 13281a3cb97SRuslan Ermilov.Dq Li 128.net.host . 13381a3cb97SRuslan Ermilov.Pp 13481a3cb97SRuslan ErmilovWhen a two part number is supplied, the last part 13581a3cb97SRuslan Ermilovis interpreted as a 24-bit quantity and placed in 13681a3cb97SRuslan Ermilovthe rightmost three bytes of the Internet network number. 13781a3cb97SRuslan ErmilovThis makes the two part number format convenient 13881a3cb97SRuslan Ermilovfor specifying Class A network numbers as 13981a3cb97SRuslan Ermilov.Dq Li net.host . 14081a3cb97SRuslan Ermilov.Pp 14181a3cb97SRuslan ErmilovWhen only one part is given, the value is stored 14281a3cb97SRuslan Ermilovdirectly in the Internet network number without any byte 14381a3cb97SRuslan Ermilovrearrangement. 14481a3cb97SRuslan Ermilov.Pp 14581a3cb97SRuslan ErmilovAll numbers supplied as 14681a3cb97SRuslan Ermilov.Dq parts 14781a3cb97SRuslan Ermilovin a 14881a3cb97SRuslan Ermilov.Ql \&. 14981a3cb97SRuslan Ermilovnotation 15081a3cb97SRuslan Ermilovmay be decimal, octal, or hexadecimal, as specified 15181a3cb97SRuslan Ermilovin the C language (i.e., a leading 0x or 0X implies 15281a3cb97SRuslan Ermilovhexadecimal; otherwise, a leading 0 implies octal; 15381a3cb97SRuslan Ermilovotherwise, the number is interpreted as decimal). 15412d96fe6SHajimu UMEMOTO.\" 15512d96fe6SHajimu UMEMOTO.\" .Sh NETWORK NUMBERS (IP VERSION 6) 15612d96fe6SHajimu UMEMOTO.\" XXX - document this! 15712d96fe6SHajimu UMEMOTO.\" 15881a3cb97SRuslan Ermilov.Sh SEE ALSO 15981a3cb97SRuslan Ermilov.Xr byteorder 3 , 16081a3cb97SRuslan Ermilov.Xr inet 3 , 16181a3cb97SRuslan Ermilov.Xr networks 5 16281a3cb97SRuslan Ermilov.Sh HISTORY 16381a3cb97SRuslan ErmilovThe 16481a3cb97SRuslan Ermilov.Fn inet_net_ntop 16581a3cb97SRuslan Ermilovand 16681a3cb97SRuslan Ermilov.Fn inet_net_pton 16781a3cb97SRuslan Ermilovfunctions appeared in BIND 4.9.4. 168