diff options
Diffstat (limited to 'src/lib/libc/net/inet_net.3')
| -rw-r--r-- | src/lib/libc/net/inet_net.3 | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/src/lib/libc/net/inet_net.3 b/src/lib/libc/net/inet_net.3 new file mode 100644 index 0000000000..648d82c780 --- /dev/null +++ b/src/lib/libc/net/inet_net.3 | |||
| @@ -0,0 +1,176 @@ | |||
| 1 | .\" $OpenBSD: inet_net.3,v 1.14 2008/06/26 05:42:05 ray Exp $ | ||
| 2 | .\" $NetBSD: inet_net.3,v 1.1 1997/06/18 02:25:27 lukem Exp $ | ||
| 3 | .\" | ||
| 4 | .\" Copyright (c) 1997 The NetBSD Foundation, Inc. | ||
| 5 | .\" All rights reserved. | ||
| 6 | .\" | ||
| 7 | .\" This code is derived from software contributed to The NetBSD Foundation | ||
| 8 | .\" by Luke Mewburn. | ||
| 9 | .\" | ||
| 10 | .\" Redistribution and use in source and binary forms, with or without | ||
| 11 | .\" modification, are permitted provided that the following conditions | ||
| 12 | .\" are met: | ||
| 13 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 14 | .\" notice, this list of conditions and the following disclaimer. | ||
| 15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 17 | .\" documentation and/or other materials provided with the distribution. | ||
| 18 | .\" | ||
| 19 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 20 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 21 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE | ||
| 23 | .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 24 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 25 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 26 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 27 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 28 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | .\" POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | .\" | ||
| 31 | .Dd $Mdocdate: June 26 2008 $ | ||
| 32 | .Dt INET_NET 3 | ||
| 33 | .Os | ||
| 34 | .Sh NAME | ||
| 35 | .Nm inet_net_ntop , | ||
| 36 | .Nm inet_net_pton | ||
| 37 | .Nd Internet network number manipulation routines | ||
| 38 | .Sh SYNOPSIS | ||
| 39 | .Fd #include <sys/types.h> | ||
| 40 | .Fd #include <sys/socket.h> | ||
| 41 | .Fd #include <netinet/in.h> | ||
| 42 | .Fd #include <arpa/inet.h> | ||
| 43 | .Ft char * | ||
| 44 | .Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" | ||
| 45 | .Ft int | ||
| 46 | .Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" | ||
| 47 | .Sh DESCRIPTION | ||
| 48 | The | ||
| 49 | .Fn inet_net_ntop | ||
| 50 | function converts an Internet network number from network format (usually a | ||
| 51 | .Li struct in_addr | ||
| 52 | or some other binary form, in network byte order) to CIDR presentation format | ||
| 53 | (suitable for external display purposes). | ||
| 54 | .Fa bits | ||
| 55 | is the number of bits in | ||
| 56 | .Fa src | ||
| 57 | that are the network number. | ||
| 58 | It returns | ||
| 59 | .Dv NULL | ||
| 60 | if a system error occurs (in which case, | ||
| 61 | .Va errno | ||
| 62 | will have been set), or it returns a pointer to the destination string. | ||
| 63 | .Pp | ||
| 64 | The | ||
| 65 | .Fn inet_net_pton | ||
| 66 | function converts a presentation format Internet network number (that is, | ||
| 67 | printable form as held in a character string) to network format (usually a | ||
| 68 | .Li struct in_addr | ||
| 69 | or some other internal binary representation, in network byte order). | ||
| 70 | It returns the number of bits (either computed based on the class, or | ||
| 71 | specified with /CIDR), or \-1 if a failure occurred | ||
| 72 | (in which case | ||
| 73 | .Va errno | ||
| 74 | will have been set. | ||
| 75 | It will be set to | ||
| 76 | .Er ENOENT | ||
| 77 | if the Internet network number was not valid). | ||
| 78 | .Pp | ||
| 79 | Caution: | ||
| 80 | The | ||
| 81 | .Fa dst | ||
| 82 | field should be zeroed before calling | ||
| 83 | .Fn inet_net_pton | ||
| 84 | as the function will only fill the number of bytes necessary to | ||
| 85 | encode the network number in network byte order. | ||
| 86 | .Pp | ||
| 87 | The only value for | ||
| 88 | .Fa af | ||
| 89 | currently supported is | ||
| 90 | .Dv AF_INET . | ||
| 91 | .Fa size | ||
| 92 | is the size of the result buffer | ||
| 93 | .Fa dst . | ||
| 94 | .Sh NETWORK NUMBERS (IP VERSION 4) | ||
| 95 | The external representation of Internet network numbers may be specified in | ||
| 96 | one of the following forms: | ||
| 97 | .Bd -literal -offset indent | ||
| 98 | a | ||
| 99 | a.b | ||
| 100 | a.b.c | ||
| 101 | a.b.c.d | ||
| 102 | .Ed | ||
| 103 | .Pp | ||
| 104 | Any of the above four forms may have | ||
| 105 | .Dq Li /bits | ||
| 106 | appended where | ||
| 107 | .Dq Li bits | ||
| 108 | is in the range | ||
| 109 | .Li 0-32 | ||
| 110 | and is used to explicitly specify the number of bits in the network address. | ||
| 111 | When | ||
| 112 | .Dq Li /bits | ||
| 113 | is not specified the number of bits in the network address is calculated | ||
| 114 | as the larger of the number of bits in the class to which the address | ||
| 115 | belongs and the number of bits provided rounded up modulo 8. | ||
| 116 | Examples: | ||
| 117 | .Pp | ||
| 118 | .Bl -tag -width 10.1.2.3/24 -offset indent -compact | ||
| 119 | .It Li 10 | ||
| 120 | an 8-bit network number (class A), value | ||
| 121 | .Li 10.0.0.0 . | ||
| 122 | .It Li 192 | ||
| 123 | a 24-bit network number (class C), value | ||
| 124 | .Li 192.0.0.0 . | ||
| 125 | .It Li 10.10 | ||
| 126 | a 16-bit network number, value | ||
| 127 | .Li 10.10.0.0 . | ||
| 128 | .It Li 10.1.2 | ||
| 129 | a 24-bit network number, value | ||
| 130 | .Li 10.1.2.0 . | ||
| 131 | .It Li 10.1.2.3 | ||
| 132 | a 32-bit network number, value | ||
| 133 | .Li 10.1.2.3 . | ||
| 134 | .It Li 10.1.2.3/24 | ||
| 135 | a 24-bit network number (explicit), value | ||
| 136 | .Li 10.1.2.3 . | ||
| 137 | .El | ||
| 138 | .Pp | ||
| 139 | Note that when the number of bits is specified using | ||
| 140 | .Dq Li /bits | ||
| 141 | notation, the value of the address still includes all bits supplied | ||
| 142 | in the external representation, even those bits which are the host | ||
| 143 | part of an Internet address. | ||
| 144 | Also, unlike | ||
| 145 | .Xr inet_pton 3 | ||
| 146 | where the external representation is assumed to be a host address, the | ||
| 147 | external representation for | ||
| 148 | .Fn inet_net_pton | ||
| 149 | is assumed to be a network address. | ||
| 150 | Thus | ||
| 151 | .Dq Li 10.1 | ||
| 152 | is assumed to be | ||
| 153 | .Dq Li 10.1.0.0 | ||
| 154 | not | ||
| 155 | .Dq Li 10.0.0.1 | ||
| 156 | .Pp | ||
| 157 | All numbers supplied as | ||
| 158 | .Dq parts | ||
| 159 | in a | ||
| 160 | .Ql \&. | ||
| 161 | notation | ||
| 162 | may be decimal, octal, or hexadecimal, as specified | ||
| 163 | in the C language (i.e., a leading 0x or 0X implies | ||
| 164 | hexadecimal; otherwise, a leading 0 implies octal; | ||
| 165 | otherwise, the number is interpreted as decimal). | ||
| 166 | .Sh SEE ALSO | ||
| 167 | .Xr byteorder 3 , | ||
| 168 | .Xr inet 3 , | ||
| 169 | .Xr inet_pton 3 , | ||
| 170 | .Xr networks 5 | ||
| 171 | .Sh HISTORY | ||
| 172 | The | ||
| 173 | .Nm inet_net_ntop | ||
| 174 | and | ||
| 175 | .Nm inet_net_pton | ||
| 176 | functions first appeared in BIND 4.9.4. | ||
