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