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