xref: /netbsd-src/external/bsd/libbind/dist/doc/inet_cidr.3 (revision 5bbd2a12505d72a8177929a37b5cee489d0a1cfd)
1*5bbd2a12Schristos.\"	$NetBSD: inet_cidr.3,v 1.1.1.2 2012/09/09 16:07:46 christos Exp $
2b5677b36Schristos.\"
3b5677b36Schristos.\" Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
4b5677b36Schristos.\"
5b5677b36Schristos.\" Permission to use, copy, modify, and/or distribute this software for any
6b5677b36Schristos.\" purpose with or without fee is hereby granted, provided that the above
7b5677b36Schristos.\" copyright notice and this permission notice appear in all copies.
8b5677b36Schristos.\"
9b5677b36Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10b5677b36Schristos.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11b5677b36Schristos.\" AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12b5677b36Schristos.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13b5677b36Schristos.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14b5677b36Schristos.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15b5677b36Schristos.\" PERFORMANCE OF THIS SOFTWARE.
16b5677b36Schristos.\"
17b5677b36Schristos.\" Id: inet_cidr.3,v 1.3 2009/01/22 23:49:23 tbox Exp
18b5677b36Schristos.\"
19b5677b36Schristos.Dd October 19, 1998
20b5677b36Schristos.Dt INET_CIDR @LIB_NETWORK_EXT_U@
21b5677b36Schristos.Os BSD 4
22b5677b36Schristos.Sh NAME
23b5677b36Schristos.Nm inet_cidr_ntop ,
24b5677b36Schristos.Nm inet_cidr_pton
25b5677b36Schristos.Nd network translation routines
26b5677b36Schristos.Sh SYNOPSIS
27b5677b36Schristos.Fd #include <sys/types.h>
28b5677b36Schristos.Fd #include <sys/socket.h>
29b5677b36Schristos.Fd #include <netinet/in.h>
30b5677b36Schristos.Fd #include <arpa/inet.h>
31b5677b36Schristos.Fn inet_cidr_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size"
32b5677b36Schristos.Fn inet_cidr_pton "int af" "const char *src" "void *dst" "int *bits"
33b5677b36Schristos.Sh DESCRIPTION
34b5677b36SchristosThese routines are used for converting addresses to and from network and
35b5677b36Schristospresentation forms with CIDR (Classless Inter-Domain Routing) representation,
36b5677b36Schristosembedded net mask.
37b5677b36Schristos.Pp
38b5677b36Schristos.Bd -literal
39b5677b36Schristos		130.155.16.1/20
40b5677b36Schristos.Ed
41b5677b36Schristos.\"		::ffff:130.155.16.1/116
42b5677b36Schristos.Pp
43b5677b36Schristos.Fn inet_cidr_ntop
44b5677b36Schristosconverts an address from network to presentation format.
45b5677b36Schristos.Pp
46b5677b36Schristos.Ft af
47b5677b36Schristosdescribes the type of address that is being passed in
48b5677b36Schristos.Ft src .
49b5677b36Schristos.\"Currently defined types are AF_INET and AF_INET6.
50b5677b36SchristosCurrently only AF_INET is supported.
51b5677b36Schristos.Pp
52b5677b36Schristos.Ft src
53b5677b36Schristosis an address in network byte order, its length is determined from
54b5677b36Schristos.Ft af .
55b5677b36Schristos.Pp
56b5677b36Schristos.Ft bits
57b5677b36Schristosspecifies the number of bits in the netmask unless it is -1 in which case
58b5677b36Schristosthe CIDR representation is omitted.
59b5677b36Schristos.Pp
60b5677b36Schristos.Ft dst
61b5677b36Schristosis a caller supplied buffer of at least
62b5677b36Schristos.Ft size
63b5677b36Schristosbytes.
64b5677b36Schristos.Pp
65b5677b36Schristos.Fn inet_cidr_ntop
66b5677b36Schristosreturns
67b5677b36Schristos.Ft dst
68b5677b36Schristoson success or NULL.
69b5677b36SchristosCheck errno for reason.
70b5677b36Schristos.Pp
71b5677b36Schristos.Fn inet_cidr_pton
72b5677b36Schristosconverts and address from presentation format, with optional CIDR
73b5677b36Schristosreperesentation, to network format.
74b5677b36SchristosThe resulting address is zero filled if there were insufficint bits in
75b5677b36Schristos.Ft src .
76b5677b36Schristos.Pp
77b5677b36Schristos.Ft af
78b5677b36Schristosdescribes the type of address that is being passed in via
79b5677b36Schristos.Ft src
80b5677b36Schristosand determines the size of
81b5677b36Schristos.Ft dst .
82b5677b36Schristos.Pp
83b5677b36Schristos.Ft src
84b5677b36Schristosis an address in presentation format.
85b5677b36Schristos.Pp
86b5677b36Schristos.Ft bits
87b5677b36Schristosreturns the number of bits in the netmask or -1 if a CIDR representation was
88b5677b36Schristosnot supplied.
89b5677b36Schristos.Pp
90b5677b36Schristos.Fn inet_cidr_pton
91b5677b36Schristosreturns 0 on succces or -1 on error.
92b5677b36SchristosCheck errno for reason.
93b5677b36SchristosENOENT indicates an invalid netmask.
94b5677b36Schristos.Sh SEE ALSO
95b5677b36Schristos.Xr intro 2
96