| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: inet_net.3,v 1.2 2008/04/30 13:10:50 martin Exp $ | | 1 | .\" $NetBSD: inet_net.3,v 1.3 2012/07/20 13:40:58 ginsbach Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 1997 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 1997 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | | 6 | .\" This code is derived from software contributed to The NetBSD Foundation |
7 | .\" by Luke Mewburn. | | 7 | .\" by Luke Mewburn. |
8 | .\" | | 8 | .\" |
9 | .\" Redistribution and use in source and binary forms, with or without | | 9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | | 10 | .\" modification, are permitted provided that the following conditions |
11 | .\" are met: | | 11 | .\" are met: |
12 | .\" 1. Redistributions of source code must retain the above copyright | | 12 | .\" 1. Redistributions of source code must retain the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer. | | 13 | .\" notice, this list of conditions and the following disclaimer. |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| @@ -38,117 +38,121 @@ | | | @@ -38,117 +38,121 @@ |
38 | .Lb libc | | 38 | .Lb libc |
39 | .Sh SYNOPSIS | | 39 | .Sh SYNOPSIS |
40 | .In sys/socket.h | | 40 | .In sys/socket.h |
41 | .In netinet/in.h | | 41 | .In netinet/in.h |
42 | .In arpa/inet.h | | 42 | .In arpa/inet.h |
43 | .Ft char * | | 43 | .Ft char * |
44 | .Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" | | 44 | .Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" |
45 | .Ft int | | 45 | .Ft int |
46 | .Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" | | 46 | .Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" |
47 | .Sh DESCRIPTION | | 47 | .Sh DESCRIPTION |
48 | The | | 48 | The |
49 | .Fn inet_net_ntop | | 49 | .Fn inet_net_ntop |
50 | function converts an Internet network number from network format (usually a | | 50 | function converts an Internet network number from network format (usually a |
51 | .Ft struct in_addr | | 51 | .Vt struct in_addr |
52 | or some other binary form, in network byte order) to CIDR presentation format | | 52 | or some other binary form, in network byte order) to CIDR presentation format |
53 | (suitable for external display purposes). | | 53 | (suitable for external display purposes). |
| | | 54 | The |
54 | .Fa bits | | 55 | .Fa bits |
55 | is the number of bits in | | 56 | argument is the number of bits in |
56 | .Fa src | | 57 | .Fa src |
57 | that are the network number. | | 58 | that are the network number. |
58 | It returns NULL if a system error occurs (in which case, | | 59 | It returns |
| | | 60 | .Dv NULL |
| | | 61 | if a system error occurs (in which case, |
59 | .Va errno | | 62 | .Va errno |
60 | will have been set), or it returns a pointer to the destination string. | | 63 | will have been set), or it returns a pointer to the destination string. |
61 | .Pp | | 64 | .Pp |
62 | The | | 65 | The |
63 | .Fn inet_net_pton | | 66 | .Fn inet_net_pton |
64 | function converts a presentation format Internet network number (that is, | | 67 | function converts a presentation format Internet network number (that is, |
65 | printable form as held in a character string) to network format (usually a | | 68 | printable form as held in a character string) to network format (usually a |
66 | .Ft struct in_addr | | 69 | .Vt struct in_addr |
67 | or some other internal binary representation, in network byte order). | | 70 | or some other internal binary representation, in network byte order). |
68 | It returns the number of bits (either computed based on the class, or | | 71 | It returns the number of bits (either computed based on the class, or |
69 | specified with /CIDR), or -1 if a failure occurred | | 72 | specified with /CIDR), or \-1 if a failure occurred |
70 | (in which case | | 73 | (in which case |
71 | .Va errno | | 74 | .Va errno |
72 | will have been set. | | 75 | will have been set. |
73 | It will be set to | | 76 | It will be set to |
74 | .Er ENOENT | | 77 | .Er ENOENT |
75 | if the Internet network number was not valid). | | 78 | if the Internet network number was not valid). |
76 | .Pp | | 79 | .Pp |
77 | The currently supported values for | | 80 | The currently supported values for |
78 | .Fa af | | 81 | .Fa af |
79 | are | | 82 | are |
80 | .Dv AF_INET | | 83 | .Dv AF_INET |
81 | and | | 84 | and |
82 | .Dv AF_INET6 . | | 85 | .Dv AF_INET6 . |
| | | 86 | The |
83 | .Fa size | | 87 | .Fa size |
84 | is the size of the result buffer | | 88 | argument is the size of the result buffer |
85 | .Fa dst . | | 89 | .Fa dst . |
86 | .Sh NETWORK NUMBERS (IP VERSION 4) | | 90 | .Sh NETWORK NUMBERS (IP VERSION 4) |
87 | Internet network numbers may be specified in one of the following forms: | | 91 | Internet network numbers may be specified in one of the following forms: |
88 | .Bd -literal -offset indent | | 92 | .Bd -literal -offset indent |
89 | a.b.c.d/bits | | 93 | a.b.c.d/bits |
90 | a.b.c.d | | 94 | a.b.c.d |
91 | a.b.c | | 95 | a.b.c |
92 | a.b | | 96 | a.b |
93 | a | | 97 | a |
94 | .Ed | | 98 | .Ed |
95 | .Pp | | 99 | .Pp |
96 | When four parts are specified, each is interpreted | | 100 | When four parts are specified, each is interpreted |
97 | as a byte of data and assigned, from left to right, | | 101 | as a byte of data and assigned, from left to right, |
98 | to the four bytes of an Internet network number. Note | | 102 | to the four bytes of an Internet network number. |
99 | that when an Internet network number is viewed as a 32-bit | | 103 | Note that when an Internet network number is viewed as a 32-bit |
100 | integer quantity on a system that uses little-endian | | 104 | integer quantity on a system that uses little-endian |
101 | byte order (such as the | | 105 | byte order (such as the |
102 | .Tn Intel 386, 486 | | 106 | .Tn Intel 386 , 486 , |
103 | and | | 107 | and |
104 | .Tn Pentium | | 108 | .Tn Pentium |
105 | processors) the bytes referred to above appear as | | 109 | processors) the bytes referred to above appear as |
106 | .Dq Li d.c.b.a . | | 110 | .Dq Li d.c.b.a . |
107 | That is, little-endian bytes are ordered from right to left. | | 111 | That is, little-endian bytes are ordered from right to left. |
108 | .Pp | | 112 | .Pp |
109 | When a three part number is specified, the last | | 113 | When a three part number is specified, the last |
110 | part is interpreted as a 16-bit quantity and placed | | 114 | part is interpreted as a 16-bit quantity and placed |
111 | in the right-most two bytes of the Internet network number. | | 115 | in the rightmost two bytes of the Internet network number. |
112 | This makes the three part number format convenient | | 116 | This makes the three part number format convenient |
113 | for specifying Class B network numbers as | | 117 | for specifying Class B network numbers as |
114 | .Dq Li 128.net.host . | | 118 | .Dq Li 128.net.host . |
115 | .Pp | | 119 | .Pp |
116 | When a two part number is supplied, the last part | | 120 | When a two part number is supplied, the last part |
117 | is interpreted as a 24-bit quantity and placed in | | 121 | is interpreted as a 24-bit quantity and placed in |
118 | the right most three bytes of the Internet network number. | | 122 | the rightmost three bytes of the Internet network number. |
119 | This makes the two part number format convenient | | 123 | This makes the two part number format convenient |
120 | for specifying Class A network numbers as | | 124 | for specifying Class A network numbers as |
121 | .Dq Li net.host . | | 125 | .Dq Li net.host . |
122 | .Pp | | 126 | .Pp |
123 | When only one part is given, the value is stored | | 127 | When only one part is given, the value is stored |
124 | directly in the Internet network number without any byte | | 128 | directly in the Internet network number without any byte |
125 | rearrangement. | | 129 | rearrangement. |
126 | .Pp | | 130 | .Pp |
127 | All numbers supplied as | | 131 | All numbers supplied as |
128 | .Dq parts | | 132 | .Dq parts |
129 | in a | | 133 | in a |
130 | .Ql \&. | | 134 | .Ql \&. |
131 | notation | | 135 | notation |
132 | may be decimal, octal, or hexadecimal, as specified | | 136 | may be decimal, octal, or hexadecimal, as specified |
133 | in the C language (i.e., a leading 0x or 0X implies | | 137 | in the C language (i.e., a leading 0x or 0X implies |
134 | hexadecimal; otherwise, a leading 0 implies octal; | | 138 | hexadecimal; otherwise, a leading 0 implies octal; |
135 | otherwise, the number is interpreted as decimal). | | 139 | otherwise, the number is interpreted as decimal). |
136 | .\" | | 140 | .\" |
137 | .\" .Sh NETWORK NUMBERS (IP VERSION 6) | | 141 | .\" .Sh NETWORK NUMBERS (IP VERSION 6) |
138 | .\" XXX - document this! | | 142 | .\" XXX - document this! |
139 | .\" | | 143 | .\" |
140 | .Sh SEE ALSO | | 144 | .Sh SEE ALSO |
141 | .Xr byteorder 3 , | | 145 | .Xr byteorder 3 , |
142 | .Xr inet 3 , | | 146 | .Xr inet 3 , |
143 | .Xr networks 5 | | 147 | .Xr networks 5 |
144 | .Sh HISTORY | | 148 | .Sh HISTORY |
145 | The | | 149 | The |
146 | .Nm inet_net_ntop | | 150 | .Fn inet_net_ntop |
147 | and | | 151 | and |
148 | .Nm inet_net_pton | | 152 | .Fn inet_net_pton |
149 | functions appeared in BIND 4.9.4 and thence | | 153 | functions appeared in BIND 4.9.4 and thence |
150 | .Nx 1.3 . | | 154 | .Nx 1.3 . |
151 | Support for | | 155 | Support for |
152 | .Dv AF_INET6 | | 156 | .Dv AF_INET6 |
153 | appeared in | | 157 | appeared in |
154 | .Nx 1.6 . | | 158 | .Nx 1.6 . |