xref: /minix3/lib/libc/inet/inet_net.3 (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1*f14fb602SLionel Sambuc.\"	$NetBSD: inet_net.3,v 1.5 2012/07/20 20:48:59 wiz Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
42fe8fb19SBen Gras.\" All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" This code is derived from software contributed to The NetBSD Foundation
72fe8fb19SBen Gras.\" by Luke Mewburn.
82fe8fb19SBen Gras.\"
92fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
102fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
112fe8fb19SBen Gras.\" are met:
122fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
132fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
142fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
152fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
162fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
172fe8fb19SBen Gras.\"
182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
192fe8fb19SBen Gras.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
202fe8fb19SBen Gras.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
212fe8fb19SBen Gras.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
222fe8fb19SBen Gras.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
232fe8fb19SBen Gras.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
242fe8fb19SBen Gras.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
252fe8fb19SBen Gras.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
262fe8fb19SBen Gras.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
272fe8fb19SBen Gras.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
282fe8fb19SBen Gras.\" POSSIBILITY OF SUCH DAMAGE.
292fe8fb19SBen Gras.\"
30*f14fb602SLionel Sambuc.Dd July 20, 2012
312fe8fb19SBen Gras.Dt INET_NET 3
322fe8fb19SBen Gras.Os
332fe8fb19SBen Gras.Sh NAME
342fe8fb19SBen Gras.Nm inet_net_ntop ,
352fe8fb19SBen Gras.Nm inet_net_pton
362fe8fb19SBen Gras.Nd Internet network number manipulation routines
372fe8fb19SBen Gras.Sh LIBRARY
382fe8fb19SBen Gras.Lb libc
392fe8fb19SBen Gras.Sh SYNOPSIS
402fe8fb19SBen Gras.In sys/socket.h
412fe8fb19SBen Gras.In netinet/in.h
422fe8fb19SBen Gras.In arpa/inet.h
432fe8fb19SBen Gras.Ft char *
442fe8fb19SBen Gras.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size"
452fe8fb19SBen Gras.Ft int
462fe8fb19SBen Gras.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size"
472fe8fb19SBen Gras.Sh DESCRIPTION
482fe8fb19SBen GrasThe
492fe8fb19SBen Gras.Fn inet_net_ntop
502fe8fb19SBen Grasfunction converts an Internet network number from network format (usually a
51*f14fb602SLionel Sambuc.Vt struct in_addr
522fe8fb19SBen Grasor some other binary form, in network byte order) to CIDR presentation format
532fe8fb19SBen Gras(suitable for external display purposes).
54*f14fb602SLionel SambucThe
552fe8fb19SBen Gras.Fa bits
56*f14fb602SLionel Sambucargument is the number of bits in
572fe8fb19SBen Gras.Fa src
582fe8fb19SBen Grasthat are the network number.
59*f14fb602SLionel SambucIt returns
60*f14fb602SLionel Sambuc.Dv NULL
61*f14fb602SLionel Sambucif an error occurs (in which case
622fe8fb19SBen Gras.Va errno
632fe8fb19SBen Graswill have been set), or it returns a pointer to the destination string.
642fe8fb19SBen Gras.Pp
652fe8fb19SBen GrasThe
662fe8fb19SBen Gras.Fn inet_net_pton
672fe8fb19SBen Grasfunction converts a presentation format Internet network number (that is,
682fe8fb19SBen Grasprintable form as held in a character string) to network format (usually a
69*f14fb602SLionel Sambuc.Vt struct in_addr
702fe8fb19SBen Grasor some other internal binary representation, in network byte order).
712fe8fb19SBen GrasIt returns the number of bits (either computed based on the class, or
72*f14fb602SLionel Sambucspecified with /CIDR), or \-1 if a failure occurred
732fe8fb19SBen Gras(in which case
742fe8fb19SBen Gras.Va errno
75*f14fb602SLionel Sambucwill have been set).
762fe8fb19SBen Gras.Pp
772fe8fb19SBen GrasThe currently supported values for
782fe8fb19SBen Gras.Fa af
792fe8fb19SBen Grasare
802fe8fb19SBen Gras.Dv AF_INET
812fe8fb19SBen Grasand
822fe8fb19SBen Gras.Dv AF_INET6 .
83*f14fb602SLionel SambucThe
842fe8fb19SBen Gras.Fa size
85*f14fb602SLionel Sambucargument is the size of the result buffer
862fe8fb19SBen Gras.Fa dst .
872fe8fb19SBen Gras.Sh NETWORK NUMBERS (IP VERSION 4)
882fe8fb19SBen GrasInternet network numbers may be specified in one of the following forms:
892fe8fb19SBen Gras.Bd -literal -offset indent
902fe8fb19SBen Grasa.b.c.d/bits
912fe8fb19SBen Grasa.b.c.d
922fe8fb19SBen Grasa.b.c
932fe8fb19SBen Grasa.b
942fe8fb19SBen Grasa
952fe8fb19SBen Gras.Ed
962fe8fb19SBen Gras.Pp
972fe8fb19SBen GrasWhen four parts are specified, each is interpreted
982fe8fb19SBen Grasas a byte of data and assigned, from left to right,
99*f14fb602SLionel Sambucto the four bytes of an Internet network number.
100*f14fb602SLionel SambucNote that when an Internet network number is viewed as a 32-bit
1012fe8fb19SBen Grasinteger quantity on a system that uses little-endian
1022fe8fb19SBen Grasbyte order (such as the
103*f14fb602SLionel Sambuc.Tn Intel 386 , 486 ,
1042fe8fb19SBen Grasand
1052fe8fb19SBen Gras.Tn Pentium
1062fe8fb19SBen Grasprocessors) the bytes referred to above appear as
1072fe8fb19SBen Gras.Dq Li d.c.b.a .
1082fe8fb19SBen GrasThat is, little-endian bytes are ordered from right to left.
1092fe8fb19SBen Gras.Pp
1102fe8fb19SBen GrasWhen a three part number is specified, the last
1112fe8fb19SBen Graspart is interpreted as a 16-bit quantity and placed
112*f14fb602SLionel Sambucin the rightmost two bytes of the Internet network number.
1132fe8fb19SBen GrasThis makes the three part number format convenient
1142fe8fb19SBen Grasfor specifying Class B network numbers as
1152fe8fb19SBen Gras.Dq Li 128.net.host .
1162fe8fb19SBen Gras.Pp
1172fe8fb19SBen GrasWhen a two part number is supplied, the last part
1182fe8fb19SBen Grasis interpreted as a 24-bit quantity and placed in
1192fe8fb19SBen Grasthe rightmost three bytes of the Internet network number.
1202fe8fb19SBen GrasThis makes the two part number format convenient
1212fe8fb19SBen Grasfor specifying Class A network numbers as
1222fe8fb19SBen Gras.Dq Li net.host .
1232fe8fb19SBen Gras.Pp
1242fe8fb19SBen GrasWhen only one part is given, the value is stored
1252fe8fb19SBen Grasdirectly in the Internet network number without any byte
1262fe8fb19SBen Grasrearrangement.
1272fe8fb19SBen Gras.Pp
1282fe8fb19SBen GrasAll numbers supplied as
1292fe8fb19SBen Gras.Dq parts
1302fe8fb19SBen Grasin a
1312fe8fb19SBen Gras.Ql \&.
1322fe8fb19SBen Grasnotation
1332fe8fb19SBen Grasmay be decimal, octal, or hexadecimal, as specified
1342fe8fb19SBen Grasin the C language (i.e., a leading 0x or 0X implies
1352fe8fb19SBen Grashexadecimal; otherwise, a leading 0 implies octal;
1362fe8fb19SBen Grasotherwise, the number is interpreted as decimal).
1372fe8fb19SBen Gras.\"
1382fe8fb19SBen Gras.\" .Sh NETWORK NUMBERS (IP VERSION 6)
1392fe8fb19SBen Gras.\" XXX - document this!
1402fe8fb19SBen Gras.\"
141*f14fb602SLionel Sambuc.Sh ERRORS
142*f14fb602SLionel SambucThe
143*f14fb602SLionel Sambuc.Fn inet_net_ntop
144*f14fb602SLionel Sambucand
145*f14fb602SLionel Sambuc.Fn inet_net_pton
146*f14fb602SLionel Sambucfunctions may fail with
147*f14fb602SLionel Sambuc.Bl -tag -width Er
148*f14fb602SLionel Sambuc.It Bq Er EAFNOSUPPORT
149*f14fb602SLionel SambucThe value of
150*f14fb602SLionel Sambuc.Fa af
151*f14fb602SLionel Sambucwas not
152*f14fb602SLionel Sambuc.Dv AF_INET
153*f14fb602SLionel Sambucor
154*f14fb602SLionel Sambuc.Dv AF_INET6 .
155*f14fb602SLionel Sambuc.It Bq Er EMSGSIZE
156*f14fb602SLionel SambucThe conversion of
157*f14fb602SLionel Sambuc.Fa src
158*f14fb602SLionel Sambucoverflows
159*f14fb602SLionel Sambuc.Fa size
160*f14fb602SLionel Sambucof
161*f14fb602SLionel Sambuc.Fa dst .
162*f14fb602SLionel Sambuc.El
163*f14fb602SLionel Sambuc.Pp
164*f14fb602SLionel SambucThe
165*f14fb602SLionel Sambuc.Fn inet_net_ntop
166*f14fb602SLionel Sambucfunction may fail with
167*f14fb602SLionel Sambuc.Bl -tag -width Er
168*f14fb602SLionel Sambuc.It Bq Er EINVAL
169*f14fb602SLionel SambucThe
170*f14fb602SLionel Sambuc.Fa bits
171*f14fb602SLionel Sambucargument contains an invalid number of bits
172*f14fb602SLionel Sambucfor the requested address family.
173*f14fb602SLionel Sambuc.El
174*f14fb602SLionel Sambuc.Pp
175*f14fb602SLionel SambucThe
176*f14fb602SLionel Sambuc.Fn inet_net_pton
177*f14fb602SLionel Sambucfunction may fail with
178*f14fb602SLionel Sambuc.Bl -tag -width Er
179*f14fb602SLionel Sambuc.It Bq Er ENOENT
180*f14fb602SLionel SambucThe
181*f14fb602SLionel Sambuc.Fa src
182*f14fb602SLionel Sambucwas not a valid Internet network number.
183*f14fb602SLionel Sambuc.El
1842fe8fb19SBen Gras.Sh SEE ALSO
1852fe8fb19SBen Gras.Xr byteorder 3 ,
1862fe8fb19SBen Gras.Xr inet 3 ,
1872fe8fb19SBen Gras.Xr networks 5
1882fe8fb19SBen Gras.Sh HISTORY
1892fe8fb19SBen GrasThe
190*f14fb602SLionel Sambuc.Fn inet_net_ntop
1912fe8fb19SBen Grasand
192*f14fb602SLionel Sambuc.Fn inet_net_pton
1932fe8fb19SBen Grasfunctions appeared in BIND 4.9.4 and thence
1942fe8fb19SBen Gras.Nx 1.3 .
1952fe8fb19SBen GrasSupport for
1962fe8fb19SBen Gras.Dv AF_INET6
1972fe8fb19SBen Grasappeared in
1982fe8fb19SBen Gras.Nx 1.6 .
199