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. 17fbbd9655SWarner Losh.\" 3. Neither the name of The NetBSD Foundation nor the names of its 1881a3cb97SRuslan Ermilov.\" contributors may be used to endorse or promote products derived 1981a3cb97SRuslan Ermilov.\" from this software without specific prior written permission. 2081a3cb97SRuslan Ermilov.\" 2181a3cb97SRuslan Ermilov.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2281a3cb97SRuslan Ermilov.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2381a3cb97SRuslan Ermilov.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2481a3cb97SRuslan Ermilov.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2581a3cb97SRuslan Ermilov.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2681a3cb97SRuslan Ermilov.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2781a3cb97SRuslan Ermilov.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2881a3cb97SRuslan Ermilov.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2981a3cb97SRuslan Ermilov.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3081a3cb97SRuslan Ermilov.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3181a3cb97SRuslan Ermilov.\" POSSIBILITY OF SUCH DAMAGE. 3281a3cb97SRuslan Ermilov.\" 3381a3cb97SRuslan Ermilov.\" $FreeBSD$ 3481a3cb97SRuslan Ermilov.\" 35*12bd931dSMike Karels.Dd November 9, 2021 3681a3cb97SRuslan Ermilov.Dt INET_NET 3 3781a3cb97SRuslan Ermilov.Os 3881a3cb97SRuslan Ermilov.Sh NAME 3981a3cb97SRuslan Ermilov.Nm inet_net_ntop , 4081a3cb97SRuslan Ermilov.Nm inet_net_pton 4181a3cb97SRuslan Ermilov.Nd Internet network number manipulation routines 4281a3cb97SRuslan Ermilov.Sh LIBRARY 4381a3cb97SRuslan Ermilov.Lb libc 4481a3cb97SRuslan Ermilov.Sh SYNOPSIS 4581a3cb97SRuslan Ermilov.In sys/socket.h 4681a3cb97SRuslan Ermilov.In netinet/in.h 4781a3cb97SRuslan Ermilov.In arpa/inet.h 4881a3cb97SRuslan Ermilov.Ft char * 4981a3cb97SRuslan Ermilov.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" 5081a3cb97SRuslan Ermilov.Ft int 5181a3cb97SRuslan Ermilov.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" 5281a3cb97SRuslan Ermilov.Sh DESCRIPTION 5381a3cb97SRuslan ErmilovThe 5481a3cb97SRuslan Ermilov.Fn inet_net_ntop 5581a3cb97SRuslan Ermilovfunction converts an Internet network number from network format (usually a 5681a3cb97SRuslan Ermilov.Vt "struct in_addr" 5781a3cb97SRuslan Ermilovor some other binary form, in network byte order) to CIDR presentation format 5881a3cb97SRuslan Ermilov(suitable for external display purposes). 592efeeba5SRuslan ErmilovThe 6081a3cb97SRuslan Ermilov.Fa bits 612efeeba5SRuslan Ermilovargument 6281a3cb97SRuslan Ermilovis the number of bits in 6381a3cb97SRuslan Ermilov.Fa src 6481a3cb97SRuslan Ermilovthat are the network number. 6581a3cb97SRuslan ErmilovIt returns 6681a3cb97SRuslan Ermilov.Dv NULL 6781a3cb97SRuslan Ermilovif a system error occurs (in which case, 6881a3cb97SRuslan Ermilov.Va errno 6981a3cb97SRuslan Ermilovwill have been set), or it returns a pointer to the destination string. 7081a3cb97SRuslan Ermilov.Pp 7181a3cb97SRuslan ErmilovThe 7281a3cb97SRuslan Ermilov.Fn inet_net_pton 7381a3cb97SRuslan Ermilovfunction converts a presentation format Internet network number (that is, 7481a3cb97SRuslan Ermilovprintable form as held in a character string) to network format (usually a 7581a3cb97SRuslan Ermilov.Vt "struct in_addr" 7681a3cb97SRuslan Ermilovor some other internal binary representation, in network byte order). 7781a3cb97SRuslan ErmilovIt returns the number of bits (either computed based on the class, or 7881a3cb97SRuslan Ermilovspecified with /CIDR), or \-1 if a failure occurred 7981a3cb97SRuslan Ermilov(in which case 8081a3cb97SRuslan Ermilov.Va errno 8181a3cb97SRuslan Ermilovwill have been set. 8281a3cb97SRuslan ErmilovIt will be set to 8381a3cb97SRuslan Ermilov.Er ENOENT 8481a3cb97SRuslan Ermilovif the Internet network number was not valid). 8581a3cb97SRuslan Ermilov.Pp 8612d96fe6SHajimu UMEMOTOThe currently supported values for 8781a3cb97SRuslan Ermilov.Fa af 8812d96fe6SHajimu UMEMOTOare 8912d96fe6SHajimu UMEMOTO.Dv AF_INET 9012d96fe6SHajimu UMEMOTOand 9112d96fe6SHajimu UMEMOTO.Dv AF_INET6 . 922efeeba5SRuslan ErmilovThe 9381a3cb97SRuslan Ermilov.Fa size 942efeeba5SRuslan Ermilovargument 9581a3cb97SRuslan Ermilovis the size of the result buffer 9681a3cb97SRuslan Ermilov.Fa dst . 9781a3cb97SRuslan Ermilov.Sh NETWORK NUMBERS (IP VERSION 4) 9881a3cb97SRuslan ErmilovInternet network numbers may be specified in one of the following forms: 9981a3cb97SRuslan Ermilov.Bd -literal -offset indent 10081a3cb97SRuslan Ermilova.b.c.d/bits 10181a3cb97SRuslan Ermilova.b.c.d 10281a3cb97SRuslan Ermilova.b.c 10381a3cb97SRuslan Ermilova.b 10481a3cb97SRuslan Ermilova 10581a3cb97SRuslan Ermilov.Ed 10681a3cb97SRuslan Ermilov.Pp 10781a3cb97SRuslan ErmilovWhen four parts are specified, each is interpreted 10881a3cb97SRuslan Ermilovas a byte of data and assigned, from left to right, 10981a3cb97SRuslan Ermilovto the four bytes of an Internet network number. 11081a3cb97SRuslan ErmilovNote 11181a3cb97SRuslan Ermilovthat when an Internet network number is viewed as a 32-bit 11281a3cb97SRuslan Ermilovinteger quantity on a system that uses little-endian 11381a3cb97SRuslan Ermilovbyte order (such as the 11481a3cb97SRuslan Ermilov.Tn Intel 386 , 486 , 11581a3cb97SRuslan Ermilovand 11681a3cb97SRuslan Ermilov.Tn Pentium 11781a3cb97SRuslan Ermilovprocessors) the bytes referred to above appear as 11881a3cb97SRuslan Ermilov.Dq Li d.c.b.a . 11981a3cb97SRuslan ErmilovThat is, little-endian bytes are ordered from right to left. 12081a3cb97SRuslan Ermilov.Pp 12181a3cb97SRuslan ErmilovWhen a three part number is specified, the last 12281a3cb97SRuslan Ermilovpart is interpreted as a 16-bit quantity and placed 123*12bd931dSMike Karelsin the least significant two bytes of the Internet network number. 12481a3cb97SRuslan Ermilov.Pp 12581a3cb97SRuslan ErmilovWhen a two part number is supplied, the last part 12681a3cb97SRuslan Ermilovis interpreted as a 24-bit quantity and placed in 127*12bd931dSMike Karelsthe least significant three bytes of the Internet network number. 12881a3cb97SRuslan Ermilov.Pp 12981a3cb97SRuslan ErmilovWhen only one part is given, the value is stored 13081a3cb97SRuslan Ermilovdirectly in the Internet network number without any byte 13181a3cb97SRuslan Ermilovrearrangement. 13281a3cb97SRuslan Ermilov.Pp 13381a3cb97SRuslan ErmilovAll numbers supplied as 13481a3cb97SRuslan Ermilov.Dq parts 13581a3cb97SRuslan Ermilovin a 13681a3cb97SRuslan Ermilov.Ql \&. 13781a3cb97SRuslan Ermilovnotation 13881a3cb97SRuslan Ermilovmay be decimal, octal, or hexadecimal, as specified 13981a3cb97SRuslan Ermilovin the C language (i.e., a leading 0x or 0X implies 14081a3cb97SRuslan Ermilovhexadecimal; otherwise, a leading 0 implies octal; 14181a3cb97SRuslan Ermilovotherwise, the number is interpreted as decimal). 14212d96fe6SHajimu UMEMOTO.\" 14312d96fe6SHajimu UMEMOTO.\" .Sh NETWORK NUMBERS (IP VERSION 6) 14412d96fe6SHajimu UMEMOTO.\" XXX - document this! 14512d96fe6SHajimu UMEMOTO.\" 14681a3cb97SRuslan Ermilov.Sh SEE ALSO 14781a3cb97SRuslan Ermilov.Xr byteorder 3 , 14881a3cb97SRuslan Ermilov.Xr inet 3 , 14981a3cb97SRuslan Ermilov.Xr networks 5 15081a3cb97SRuslan Ermilov.Sh HISTORY 15181a3cb97SRuslan ErmilovThe 15281a3cb97SRuslan Ermilov.Fn inet_net_ntop 15381a3cb97SRuslan Ermilovand 15481a3cb97SRuslan Ermilov.Fn inet_net_pton 15581a3cb97SRuslan Ermilovfunctions appeared in BIND 4.9.4. 156