]> git.ipfire.org Git - thirdparty/strongswan.git/blame - doc/manpage.d/ipsec_subnettoa.3.html
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / doc / manpage.d / ipsec_subnettoa.3.html
CommitLineData
997358a6
MW
1Content-type: text/html
2
3<HTML><HEAD><TITLE>Manpage of IPSEC_ATOADDR</TITLE>
4</HEAD><BODY>
5<H1>IPSEC_ATOADDR</H1>
6Section: C Library Functions (3)<BR>Updated: 11 June 2001<BR><A HREF="#index">Index</A>
7<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>
8
9
10<A NAME="lbAB">&nbsp;</A>
11<H2>NAME</H2>
12
13ipsec atoaddr, addrtoa - convert Internet addresses to and from ASCII
14<BR>
15
16ipsec atosubnet, subnettoa - convert subnet/mask ASCII form to and from addresses
17<A NAME="lbAC">&nbsp;</A>
18<H2>SYNOPSIS</H2>
19
20<B>#include &lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>
21
22<P>
23<B>const char *atoaddr(const char *src, size_t srclen,</B>
24
25<BR>
26&nbsp;
27<B>struct in_addr *addr);</B>
28
29<BR>
30
31<B>size_t addrtoa(struct in_addr addr, int format,</B>
32
33<BR>
34&nbsp;
35<B>char *dst, size_t dstlen);</B>
36
37<P>
38<B>const char *atosubnet(const char *src, size_t srclen,</B>
39
40<BR>
41&nbsp;
42<B>struct in_addr *addr, struct in_addr *mask);</B>
43
44<BR>
45
46<B>size_t subnettoa(struct in_addr addr, struct in_addr mask,</B>
47
48<BR>
49&nbsp;
50<B>int format, char *dst, size_t dstlen);</B>
51
52<A NAME="lbAD">&nbsp;</A>
53<H2>DESCRIPTION</H2>
54
55These functions are obsolete; see
56<I><A HREF="ipsec_ttoaddr.3.html">ipsec_ttoaddr</A></I>(3)
57
58for their replacements.
59<P>
60
61<I>Atoaddr</I>
62
63converts an ASCII name or dotted-decimal address into a binary address
64(in network byte order).
65<I>Addrtoa</I>
66
67does the reverse conversion, back to an ASCII dotted-decimal address.
68<I>Atosubnet</I>
69
70and
71<I>subnettoa</I>
72
73do likewise for the ``address/mask'' ASCII form used to write a
74specification of a subnet.
75<P>
76
77An address is specified in ASCII as a
78dotted-decimal address (e.g.
79<B>1.2.3.4</B>),
80
81an eight-digit network-order hexadecimal number with the usual C prefix (e.g.
82<B>0x01020304</B>,
83
84which is synonymous with
85<B>1.2.3.4</B>),
86
87an eight-digit host-order hexadecimal number with a
88<B>0h</B>
89
90prefix (e.g.
91<B>0h01020304</B>,
92
93which is synonymous with
94<B>1.2.3.4</B>
95
96on a big-endian host and
97<B>4.3.2.1</B>
98
99on a little-endian host),
100a DNS name to be looked up via
101<I><A HREF="gethostbyname.3.html">gethostbyname</A></I>(3),
102
103or an old-style network name to be looked up via
104<I><A HREF="getnetbyname.3.html">getnetbyname</A></I>(3).
105
106<P>
107
108A dotted-decimal address may be incomplete, in which case
109ASCII-to-binary conversion implicitly appends
110as many instances of
111<B>.0</B>
112
113as necessary to bring it up to four components.
114The components of a dotted-decimal address are always taken as
115decimal, and leading zeros are ignored.
116For example,
117<B>10</B>
118
119is synonymous with
120<B>10.0.0.0</B>,
121
122and
123<B>128.009.000.032</B>
124
125is synonymous with
126<B>128.9.0.32</B>
127
128(the latter example is verbatim from RFC 1166).
129The result of
130<I>addrtoa</I>
131
132is always complete and does not contain leading zeros.
133<P>
134
135The letters in
136a hexadecimal address may be uppercase or lowercase or any mixture thereof.
137Use of hexadecimal addresses is
138<B>strongly</B>
139
140<B>discouraged</B>;
141
142they are included only to save hassles when dealing with
143the handful of perverted programs which already print
144network addresses in hexadecimal.
145<P>
146
147DNS names may be complete (optionally terminated with a ``.'')
148or incomplete, and are looked up as specified by local system configuration
149(see
150<I><A HREF="resolver.5.html">resolver</A></I>(5)).
151
152The
153<I>h_addr</I>
154
155value returned by
156<I><A HREF="gethostbyname.3.html">gethostbyname</A></I>(3)
157
158is used,
159so with current DNS implementations,
160the result when the name corresponds to more than one address is
161difficult to predict.
162Name lookup resorts to
163<I><A HREF="getnetbyname.3.html">getnetbyname</A></I>(3)
164
165only if
166<I><A HREF="gethostbyname.3.html">gethostbyname</A></I>(3)
167
168fails.
169<P>
170
171A subnet specification is of the form <I>network</I><B>/</B><I>mask</I>.
172The
173<I>network</I>
174
175and
176<I>mask</I>
177
178can be any form acceptable to
179<I>atoaddr</I>.
180
181In addition, the
182<I>mask</I>
183
184can be a decimal integer (leading zeros ignored) giving a bit count,
185in which case
186it stands for a mask with that number of high bits on and all others off
187(e.g.,
188<B>24</B>
189
190means
191<B>255.255.255.0</B>).
192
193In any case, the mask must be contiguous
194(a sequence of high bits on and all remaining low bits off).
195As a special case, the subnet specification
196<B>%default</B>
197
198is a synonym for
199<B>0.0.0.0/0</B>.
200
201<P>
202
203<I>Atosubnet</I>
204
205ANDs the mask with the address before returning,
206so that any non-network bits in the address are turned off
207(e.g.,
208<B>10.1.2.3/24</B>
209
210is synonymous with
211<B>10.1.2.0/24</B>).
212
213<I>Subnettoa</I>
214
215generates the decimal-integer-bit-count
216form of the mask,
217with no leading zeros,
218unless the mask is non-contiguous.
219<P>
220
221The
222<I>srclen</I>
223
224parameter of
225<I>atoaddr</I>
226
227and
228<I>atosubnet</I>
229
230specifies the length of the ASCII string pointed to by
231<I>src</I>;
232
233it is an error for there to be anything else
234(e.g., a terminating NUL) within that length.
235As a convenience for cases where an entire NUL-terminated string is
236to be converted,
237a
238<I>srclen</I>
239
240value of
241<B>0</B>
242
243is taken to mean
244<B>strlen(src)</B>.
245
246<P>
247
248The
249<I>dstlen</I>
250
251parameter of
252<I>addrtoa</I>
253
254and
255<I>subnettoa</I>
256
257specifies the size of the
258<I>dst</I>
259
260parameter;
261under no circumstances are more than
262<I>dstlen</I>
263
264bytes written to
265<I>dst</I>.
266
267A result which will not fit is truncated.
268<I>Dstlen</I>
269
270can be zero, in which case
271<I>dst</I>
272
273need not be valid and no result is written,
274but the return value is unaffected;
275in all other cases, the (possibly truncated) result is NUL-terminated.
276The
277<I>freeswan.h</I>
278
279header file defines constants,
280<B>ADDRTOA_BUF</B>
281
282and
283<B>SUBNETTOA_BUF</B>,
284
285which are the sizes of buffers just large enough for worst-case results.
286<P>
287
288The
289<I>format</I>
290
291parameter of
292<I>addrtoa</I>
293
294and
295<I>subnettoa</I>
296
297specifies what format is to be used for the conversion.
298The value
299<B>0</B>
300
301(not the ASCII character
302<B>'0'</B>,
303
304but a zero value)
305specifies a reasonable default,
306and is in fact the only format currently available.
307This parameter is a hedge against future needs.
308<P>
309
310The ASCII-to-binary functions return NULL for success and
311a pointer to a string-literal error message for failure;
312see DIAGNOSTICS.
313The binary-to-ASCII functions return
314<B>0</B>
315
316for a failure, and otherwise
317always return the size of buffer which would
318be needed to
319accommodate the full conversion result, including terminating NUL;
320it is the caller's responsibility to check this against the size of
321the provided buffer to determine whether truncation has occurred.
322<A NAME="lbAE">&nbsp;</A>
323<H2>SEE ALSO</H2>
324
325<A HREF="inet.3.html">inet</A>(3)
326<A NAME="lbAF">&nbsp;</A>
327<H2>DIAGNOSTICS</H2>
328
329Fatal errors in
330<I>atoaddr</I>
331
332are:
333empty input;
334attempt to allocate temporary storage for a very long name failed;
335name lookup failed;
336syntax error in dotted-decimal form;
337dotted-decimal component too large to fit in 8 bits.
338<P>
339
340Fatal errors in
341<I>atosubnet</I>
342
343are:
344no
345<B>/</B>
346
347in
348<I>src</I>;
349
350<I>atoaddr</I>
351
352error in conversion of
353<I>network</I>
354
355or
356<I>mask</I>;
357
358bit-count mask too big;
359mask non-contiguous.
360<P>
361
362Fatal errors in
363<I>addrtoa</I>
364
365and
366<I>subnettoa</I>
367
368are:
369unknown format.
370<A NAME="lbAG">&nbsp;</A>
371<H2>HISTORY</H2>
372
373Written for the FreeS/WAN project by Henry Spencer.
374<A NAME="lbAH">&nbsp;</A>
375<H2>BUGS</H2>
376
377The interpretation of incomplete dotted-decimal addresses
378(e.g.
379<B>10/24</B>
380
381means
382<B>10.0.0.0/24</B>)
383
384differs from that of some older conversion
385functions, e.g. those of
386<I><A HREF="inet.3.html">inet</A></I>(3).
387
388The behavior of the older functions has never been
389particularly consistent or particularly useful.
390<P>
391
392Ignoring leading zeros in dotted-decimal components and bit counts
393is arguably the most useful behavior in this application,
394but it might occasionally cause confusion with the historical use of leading
395zeros to denote octal numbers.
396<P>
397
398It is barely possible that somebody, somewhere,
399might have a legitimate use for non-contiguous subnet masks.
400<P>
401
402<I><A HREF="Getnetbyname.3.html">Getnetbyname</A></I>(3)
403
404is a historical dreg.
405<P>
406
407The restriction of ASCII-to-binary error reports to literal strings
408(so that callers don't need to worry about freeing them or copying them)
409does limit the precision of error reporting.
410<P>
411
412The ASCII-to-binary error-reporting convention lends itself
413to slightly obscure code,
414because many readers will not think of NULL as signifying success.
415A good way to make it clearer is to write something like:
416<P>
417
418<DL COMPACT><DT><DD>
419<PRE>
420<B>const char *error;</B>
421
422<B>error = atoaddr( /* ... */ );</B>
423<B>if (error != NULL) {</B>
424<B> /* something went wrong */</B>
425</PRE>
426
427</DL>
428
429<P>
430
431<HR>
432<A NAME="index">&nbsp;</A><H2>Index</H2>
433<DL>
434<DT><A HREF="#lbAB">NAME</A><DD>
435<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
436<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
437<DT><A HREF="#lbAE">SEE ALSO</A><DD>
438<DT><A HREF="#lbAF">DIAGNOSTICS</A><DD>
439<DT><A HREF="#lbAG">HISTORY</A><DD>
440<DT><A HREF="#lbAH">BUGS</A><DD>
441</DL>
442<HR>
443This document was created by
444<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
445using the manual pages.<BR>
446Time: 21:40:18 GMT, November 11, 2003
447</BODY>
448</HTML>