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