xref: /freebsd/lib/libc/net/inet_net.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.\"
33*12bd931dSMike Karels.Dd November 9, 2021
3481a3cb97SRuslan Ermilov.Dt INET_NET 3
3581a3cb97SRuslan Ermilov.Os
3681a3cb97SRuslan Ermilov.Sh NAME
3781a3cb97SRuslan Ermilov.Nm inet_net_ntop ,
3881a3cb97SRuslan Ermilov.Nm inet_net_pton
3981a3cb97SRuslan Ermilov.Nd Internet network number manipulation routines
4081a3cb97SRuslan Ermilov.Sh LIBRARY
4181a3cb97SRuslan Ermilov.Lb libc
4281a3cb97SRuslan Ermilov.Sh SYNOPSIS
4381a3cb97SRuslan Ermilov.In sys/socket.h
4481a3cb97SRuslan Ermilov.In netinet/in.h
4581a3cb97SRuslan Ermilov.In arpa/inet.h
4681a3cb97SRuslan Ermilov.Ft char *
4781a3cb97SRuslan Ermilov.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size"
4881a3cb97SRuslan Ermilov.Ft int
4981a3cb97SRuslan Ermilov.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size"
5081a3cb97SRuslan Ermilov.Sh DESCRIPTION
5181a3cb97SRuslan ErmilovThe
5281a3cb97SRuslan Ermilov.Fn inet_net_ntop
5381a3cb97SRuslan Ermilovfunction converts an Internet network number from network format (usually a
5481a3cb97SRuslan Ermilov.Vt "struct in_addr"
5581a3cb97SRuslan Ermilovor some other binary form, in network byte order) to CIDR presentation format
5681a3cb97SRuslan Ermilov(suitable for external display purposes).
572efeeba5SRuslan ErmilovThe
5881a3cb97SRuslan Ermilov.Fa bits
592efeeba5SRuslan Ermilovargument
6081a3cb97SRuslan Ermilovis the number of bits in
6181a3cb97SRuslan Ermilov.Fa src
6281a3cb97SRuslan Ermilovthat are the network number.
6381a3cb97SRuslan ErmilovIt returns
6481a3cb97SRuslan Ermilov.Dv NULL
6581a3cb97SRuslan Ermilovif a system error occurs (in which case,
6681a3cb97SRuslan Ermilov.Va errno
6781a3cb97SRuslan Ermilovwill have been set), or it returns a pointer to the destination string.
6881a3cb97SRuslan Ermilov.Pp
6981a3cb97SRuslan ErmilovThe
7081a3cb97SRuslan Ermilov.Fn inet_net_pton
7181a3cb97SRuslan Ermilovfunction converts a presentation format Internet network number (that is,
7281a3cb97SRuslan Ermilovprintable form as held in a character string) to network format (usually a
7381a3cb97SRuslan Ermilov.Vt "struct in_addr"
7481a3cb97SRuslan Ermilovor some other internal binary representation, in network byte order).
7581a3cb97SRuslan ErmilovIt returns the number of bits (either computed based on the class, or
7681a3cb97SRuslan Ermilovspecified with /CIDR), or \-1 if a failure occurred
7781a3cb97SRuslan Ermilov(in which case
7881a3cb97SRuslan Ermilov.Va errno
7981a3cb97SRuslan Ermilovwill have been set.
8081a3cb97SRuslan ErmilovIt will be set to
8181a3cb97SRuslan Ermilov.Er ENOENT
8281a3cb97SRuslan Ermilovif the Internet network number was not valid).
8381a3cb97SRuslan Ermilov.Pp
8412d96fe6SHajimu UMEMOTOThe currently supported values for
8581a3cb97SRuslan Ermilov.Fa af
8612d96fe6SHajimu UMEMOTOare
8712d96fe6SHajimu UMEMOTO.Dv AF_INET
8812d96fe6SHajimu UMEMOTOand
8912d96fe6SHajimu UMEMOTO.Dv AF_INET6 .
902efeeba5SRuslan ErmilovThe
9181a3cb97SRuslan Ermilov.Fa size
922efeeba5SRuslan Ermilovargument
9381a3cb97SRuslan Ermilovis the size of the result buffer
9481a3cb97SRuslan Ermilov.Fa dst .
9581a3cb97SRuslan Ermilov.Sh NETWORK NUMBERS (IP VERSION 4)
9681a3cb97SRuslan ErmilovInternet network numbers may be specified in one of the following forms:
9781a3cb97SRuslan Ermilov.Bd -literal -offset indent
9881a3cb97SRuslan Ermilova.b.c.d/bits
9981a3cb97SRuslan Ermilova.b.c.d
10081a3cb97SRuslan Ermilova.b.c
10181a3cb97SRuslan Ermilova.b
10281a3cb97SRuslan Ermilova
10381a3cb97SRuslan Ermilov.Ed
10481a3cb97SRuslan Ermilov.Pp
10581a3cb97SRuslan ErmilovWhen four parts are specified, each is interpreted
10681a3cb97SRuslan Ermilovas a byte of data and assigned, from left to right,
10781a3cb97SRuslan Ermilovto the four bytes of an Internet network number.
10881a3cb97SRuslan ErmilovNote
10981a3cb97SRuslan Ermilovthat when an Internet network number is viewed as a 32-bit
11081a3cb97SRuslan Ermilovinteger quantity on a system that uses little-endian
11181a3cb97SRuslan Ermilovbyte order (such as the
11281a3cb97SRuslan Ermilov.Tn Intel 386 , 486 ,
11381a3cb97SRuslan Ermilovand
11481a3cb97SRuslan Ermilov.Tn Pentium
11581a3cb97SRuslan Ermilovprocessors) the bytes referred to above appear as
11681a3cb97SRuslan Ermilov.Dq Li d.c.b.a .
11781a3cb97SRuslan ErmilovThat is, little-endian bytes are ordered from right to left.
11881a3cb97SRuslan Ermilov.Pp
11981a3cb97SRuslan ErmilovWhen a three part number is specified, the last
12081a3cb97SRuslan Ermilovpart is interpreted as a 16-bit quantity and placed
121*12bd931dSMike Karelsin the least significant two bytes of the Internet network number.
12281a3cb97SRuslan Ermilov.Pp
12381a3cb97SRuslan ErmilovWhen a two part number is supplied, the last part
12481a3cb97SRuslan Ermilovis interpreted as a 24-bit quantity and placed in
125*12bd931dSMike Karelsthe least significant three bytes of the Internet network number.
12681a3cb97SRuslan Ermilov.Pp
12781a3cb97SRuslan ErmilovWhen only one part is given, the value is stored
12881a3cb97SRuslan Ermilovdirectly in the Internet network number without any byte
12981a3cb97SRuslan Ermilovrearrangement.
13081a3cb97SRuslan Ermilov.Pp
13181a3cb97SRuslan ErmilovAll numbers supplied as
13281a3cb97SRuslan Ermilov.Dq parts
13381a3cb97SRuslan Ermilovin a
13481a3cb97SRuslan Ermilov.Ql \&.
13581a3cb97SRuslan Ermilovnotation
13681a3cb97SRuslan Ermilovmay be decimal, octal, or hexadecimal, as specified
13781a3cb97SRuslan Ermilovin the C language (i.e., a leading 0x or 0X implies
13881a3cb97SRuslan Ermilovhexadecimal; otherwise, a leading 0 implies octal;
13981a3cb97SRuslan Ermilovotherwise, the number is interpreted as decimal).
14012d96fe6SHajimu UMEMOTO.\"
14112d96fe6SHajimu UMEMOTO.\" .Sh NETWORK NUMBERS (IP VERSION 6)
14212d96fe6SHajimu UMEMOTO.\" XXX - document this!
14312d96fe6SHajimu UMEMOTO.\"
14481a3cb97SRuslan Ermilov.Sh SEE ALSO
14581a3cb97SRuslan Ermilov.Xr byteorder 3 ,
14681a3cb97SRuslan Ermilov.Xr inet 3 ,
14781a3cb97SRuslan Ermilov.Xr networks 5
14881a3cb97SRuslan Ermilov.Sh HISTORY
14981a3cb97SRuslan ErmilovThe
15081a3cb97SRuslan Ermilov.Fn inet_net_ntop
15181a3cb97SRuslan Ermilovand
15281a3cb97SRuslan Ermilov.Fn inet_net_pton
15381a3cb97SRuslan Ermilovfunctions appeared in BIND 4.9.4.
154