]> git.ipfire.org Git - thirdparty/strongswan.git/blame - doc/manpage.d/ipsec_subnettot.3.html
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / doc / manpage.d / ipsec_subnettot.3.html
CommitLineData
997358a6
MW
1Content-type: text/html
2
3<HTML><HEAD><TITLE>Manpage of IPSEC_TTOADDR</TITLE>
4</HEAD><BODY>
5<H1>IPSEC_TTOADDR</H1>
6Section: C Library Functions (3)<BR>Updated: 28 Sept 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 ttoaddr, tnatoaddr, addrtot - convert Internet addresses to and from text
14<BR>
15
16ipsec ttosubnet, subnettot - convert subnet/mask text 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 *ttoaddr(const char *src, size_t srclen,</B>
24
25<BR>
26&nbsp;
27<B>int af, ip_address *addr);</B>
28
29<BR>
30
31<B>const char *tnatoaddr(const char *src, size_t srclen,</B>
32
33<BR>
34&nbsp;
35<B>int af, ip_address *addr);</B>
36
37<BR>
38
39<B>size_t addrtot(const ip_address *addr, int format,</B>
40
41<BR>
42&nbsp;
43<B>char *dst, size_t dstlen);</B>
44
45<P>
46<B>const char *ttosubnet(const char *src, size_t srclen,</B>
47
48<BR>
49&nbsp;
50<B>int af, ip_subnet *dst);</B>
51
52<BR>
53
54<B>size_t subnettot(const ip_subnet *sub, int format,</B>
55
56<BR>
57&nbsp;
58<B>char *dst, size_t dstlen);</B>
59
60<A NAME="lbAD">&nbsp;</A>
61<H2>DESCRIPTION</H2>
62
63<I>Ttoaddr</I>
64
65converts a text-string name or numeric address into a binary address
66(in network byte order).
67<I>Tnatoaddr</I>
68
69does the same conversion,
70but the only text forms it accepts are
71the ``official'' forms of
72numeric address (dotted-decimal for IPv4, colon-hex for IPv6).
73<I>Addrtot</I>
74
75does the reverse conversion, from binary address back to a text form.
76<I>Ttosubnet</I>
77
78and
79<I>subnettot</I>
80
81do likewise for the ``address/mask'' form used to write a
82specification of a subnet.
83<P>
84
85An IPv4 address is specified in text as a
86dotted-decimal address (e.g.
87<B>1.2.3.4</B>),
88
89an eight-digit network-order hexadecimal number with the usual C prefix (e.g.
90<B>0x01020304</B>,
91
92which is synonymous with
93<B>1.2.3.4</B>),
94
95an eight-digit host-order hexadecimal number with a
96<B>0h</B>
97
98prefix (e.g.
99<B>0h01020304</B>,
100
101which is synonymous with
102<B>1.2.3.4</B>
103
104on a big-endian host and
105<B>4.3.2.1</B>
106
107on a little-endian host),
108a DNS name to be looked up via
109<I><A HREF="gethostbyname.3.html">gethostbyname</A></I>(3),
110
111or an old-style network name to be looked up via
112<I><A HREF="getnetbyname.3.html">getnetbyname</A></I>(3).
113
114<P>
115
116A dotted-decimal address may be incomplete, in which case
117text-to-binary conversion implicitly appends
118as many instances of
119<B>.0</B>
120
121as necessary to bring it up to four components.
122The components of a dotted-decimal address are always taken as
123decimal, and leading zeros are ignored.
124For example,
125<B>10</B>
126
127is synonymous with
128<B>10.0.0.0</B>,
129
130and
131<B>128.009.000.032</B>
132
133is synonymous with
134<B>128.9.0.32</B>
135
136(the latter example is verbatim from RFC 1166).
137The result of applying
138<I>addrtot</I>
139
140to an IPv4 address is always complete and does not contain leading zeros.
141<P>
142
143Use of hexadecimal addresses is
144<B>strongly</B>
145
146<B>discouraged</B>;
147
148they are included only to save hassles when dealing with
149the handful of perverted programs which already print
150network addresses in hexadecimal.
151<P>
152
153An IPv6 address is specified in text with
154colon-hex notation (e.g.
155<B>0:56:78ab:22:33:44:55:66</B>),
156
157colon-hex with
158<B>::</B>
159
160abbreviating at most one subsequence of multiple zeros (e.g.
161<B>99:ab::54:068</B>,
162
163which is synonymous with
164<B>99:ab:0:0:0:0:54:68</B>),
165
166or a DNS name to be looked up via
167<I><A HREF="gethostbyname.3.html">gethostbyname</A></I>(3).
168
169The result of applying
170<I>addrtot</I>
171
172to an IPv6 address will use
173<B>::</B>
174
175abbreviation if possible,
176and will not contain leading zeros.
177<P>
178
179The letters in hexadecimal
180may be uppercase or lowercase or any mixture thereof.
181<P>
182
183DNS names may be complete (optionally terminated with a ``.'')
184or incomplete, and are looked up as specified by local system configuration
185(see
186<I><A HREF="resolver.5.html">resolver</A></I>(5)).
187
188The
189<I>h_addr</I>
190
191value returned by
192<I><A HREF="gethostbyname2.3.html">gethostbyname2</A></I>(3)
193
194is used,
195so with current DNS implementations,
196the result when the name corresponds to more than one address is
197difficult to predict.
198IPv4 name lookup resorts to
199<I><A HREF="getnetbyname.3.html">getnetbyname</A></I>(3)
200
201only if
202<I><A HREF="gethostbyname2.3.html">gethostbyname2</A></I>(3)
203
204fails.
205<P>
206
207A subnet specification is of the form <I>network</I><B>/</B><I>mask</I>.
208The
209<I>network</I>
210
211and
212<I>mask</I>
213
214can be any form acceptable to
215<I>ttoaddr</I>.
216
217In addition, and preferably, the
218<I>mask</I>
219
220can be a decimal integer (leading zeros ignored) giving a bit count,
221in which case
222it stands for a mask with that number of high bits on and all others off
223(e.g.,
224<B>24</B>
225
226in IPv4 means
227<B>255.255.255.0</B>).
228
229In any case, the mask must be contiguous
230(a sequence of high bits on and all remaining low bits off).
231As a special case, the subnet specification
232<B>%default</B>
233
234is a synonym for
235<B>0.0.0.0/0</B>
236
237or
238<B>::/0</B>
239
240in IPv4 or IPv6 respectively.
241<P>
242
243<I>Ttosubnet</I>
244
245ANDs the mask with the address before returning,
246so that any non-network bits in the address are turned off
247(e.g.,
248<B>10.1.2.3/24</B>
249
250is synonymous with
251<B>10.1.2.0/24</B>).
252
253<I>Subnettot</I>
254
255always generates the decimal-integer-bit-count
256form of the mask,
257with no leading zeros.
258<P>
259
260The
261<I>srclen</I>
262
263parameter of
264<I>ttoaddr</I>
265
266and
267<I>ttosubnet</I>
268
269specifies the length of the text string pointed to by
270<I>src</I>;
271
272it is an error for there to be anything else
273(e.g., a terminating NUL) within that length.
274As a convenience for cases where an entire NUL-terminated string is
275to be converted,
276a
277<I>srclen</I>
278
279value of
280<B>0</B>
281
282is taken to mean
283<B>strlen(src)</B>.
284
285<P>
286
287The
288<I>af</I>
289
290parameter of
291<I>ttoaddr</I>
292
293and
294<I>ttosubnet</I>
295
296specifies the address family of interest.
297It should be either
298<B>AF_INET</B>
299
300or
301<B>AF_INET6</B>.
302
303<P>
304
305The
306<I>dstlen</I>
307
308parameter of
309<I>addrtot</I>
310
311and
312<I>subnettot</I>
313
314specifies the size of the
315<I>dst</I>
316
317parameter;
318under no circumstances are more than
319<I>dstlen</I>
320
321bytes written to
322<I>dst</I>.
323
324A result which will not fit is truncated.
325<I>Dstlen</I>
326
327can be zero, in which case
328<I>dst</I>
329
330need not be valid and no result is written,
331but the return value is unaffected;
332in all other cases, the (possibly truncated) result is NUL-terminated.
333The
334<I>freeswan.h</I>
335
336header file defines constants,
337<B>ADDRTOT_BUF</B>
338
339and
340<B>SUBNETTOT_BUF</B>,
341
342which are the sizes of buffers just large enough for worst-case results.
343<P>
344
345The
346<I>format</I>
347
348parameter of
349<I>addrtot</I>
350
351and
352<I>subnettot</I>
353
354specifies what format is to be used for the conversion.
355The value
356<B>0</B>
357
358(not the character
359<B>'0'</B>,
360
361but a zero value)
362specifies a reasonable default,
363and is in fact the only format currently available in
364<I>subnettot</I>.
365
366<I>Addrtot</I>
367
368also accepts format values
369<B>'r'</B>
370
371(signifying a text form suitable for DNS reverse lookups,
372e.g.
373<B>4.3.2.1.IN-ADDR.ARPA.</B>
374
375for IPv4 and
376RFC 2874 format for IPv6),
377and
378<B>'R'</B>
379
380(signifying an alternate reverse-lookup form,
381an error for IPv4 and RFC 1886 format for IPv6).
382Reverse-lookup names always end with a ``.''.
383<P>
384
385The text-to-binary functions return NULL for success and
386a pointer to a string-literal error message for failure;
387see DIAGNOSTICS.
388The binary-to-text functions return
389<B>0</B>
390
391for a failure, and otherwise
392always return the size of buffer which would
393be needed to
394accommodate the full conversion result, including terminating NUL;
395it is the caller's responsibility to check this against the size of
396the provided buffer to determine whether truncation has occurred.
397<A NAME="lbAE">&nbsp;</A>
398<H2>SEE ALSO</H2>
399
400<A HREF="inet.3.html">inet</A>(3)
401<A NAME="lbAF">&nbsp;</A>
402<H2>DIAGNOSTICS</H2>
403
404Fatal errors in
405<I>ttoaddr</I>
406
407are:
408empty input;
409unknown address family;
410attempt to allocate temporary storage for a very long name failed;
411name lookup failed;
412syntax error in dotted-decimal or colon-hex form;
413dotted-decimal or colon-hex component too large.
414<P>
415
416Fatal errors in
417<I>ttosubnet</I>
418
419are:
420no
421<B>/</B>
422
423in
424<I>src</I>;
425
426<I>ttoaddr</I>
427
428error in conversion of
429<I>network</I>
430
431or
432<I>mask</I>;
433
434bit-count mask too big;
435mask non-contiguous.
436<P>
437
438Fatal errors in
439<I>addrtot</I>
440
441and
442<I>subnettot</I>
443
444are:
445unknown format.
446<A NAME="lbAG">&nbsp;</A>
447<H2>HISTORY</H2>
448
449Written for the FreeS/WAN project by Henry Spencer.
450<A NAME="lbAH">&nbsp;</A>
451<H2>BUGS</H2>
452
453The interpretation of incomplete dotted-decimal addresses
454(e.g.
455<B>10/24</B>
456
457means
458<B>10.0.0.0/24</B>)
459
460differs from that of some older conversion
461functions, e.g. those of
462<I><A HREF="inet.3.html">inet</A></I>(3).
463
464The behavior of the older functions has never been
465particularly consistent or particularly useful.
466<P>
467
468Ignoring leading zeros in dotted-decimal components and bit counts
469is arguably the most useful behavior in this application,
470but it might occasionally cause confusion with the historical use of leading
471zeros to denote octal numbers.
472<P>
473
474<I>Ttoaddr</I>
475
476does not support the mixed colon-hex-dotted-decimal
477convention used to embed an IPv4 address in an IPv6 address.
478<P>
479
480<I>Addrtot</I>
481
482always uses the
483<B>::</B>
484
485abbreviation (which can appear only once in an address) for the
486<I>first</I>
487
488sequence of multiple zeros in an IPv6 address.
489One can construct addresses (unlikely ones) in which this is suboptimal.
490<P>
491
492<I>Addrtot</I>
493
494<B>'r'</B>
495
496conversion of an IPv6 address uses lowercase hexadecimal,
497not the uppercase used in RFC 2874's examples.
498It takes careful reading of RFCs 2874, 2673, and 2234 to realize
499that lowercase is technically legitimate here,
500and there may be software which botches this
501and hence would have trouble with lowercase hex.
502<P>
503
504Possibly
505<I>subnettot</I>
506
507ought to recognize the
508<B>%default</B>
509
510case and generate that string as its output.
511Currently it doesn't.
512<P>
513
514It is barely possible that somebody, somewhere,
515might have a legitimate use for non-contiguous subnet masks.
516<P>
517
518<I><A HREF="Getnetbyname.3.html">Getnetbyname</A></I>(3)
519
520is a historical dreg.
521<P>
522
523<I>Tnatoaddr</I>
524
525probably should enforce completeness of dotted-decimal addresses.
526<P>
527
528The restriction of text-to-binary error reports to literal strings
529(so that callers don't need to worry about freeing them or copying them)
530does limit the precision of error reporting.
531<P>
532
533The text-to-binary error-reporting convention lends itself
534to slightly obscure code,
535because many readers will not think of NULL as signifying success.
536A good way to make it clearer is to write something like:
537<P>
538
539<DL COMPACT><DT><DD>
540<PRE>
541<B>const char *error;</B>
542
543<B>error = ttoaddr( /* ... */ );</B>
544<B>if (error != NULL) {</B>
545<B> /* something went wrong */</B>
546</PRE>
547
548</DL>
549
550<P>
551
552<HR>
553<A NAME="index">&nbsp;</A><H2>Index</H2>
554<DL>
555<DT><A HREF="#lbAB">NAME</A><DD>
556<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
557<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
558<DT><A HREF="#lbAE">SEE ALSO</A><DD>
559<DT><A HREF="#lbAF">DIAGNOSTICS</A><DD>
560<DT><A HREF="#lbAG">HISTORY</A><DD>
561<DT><A HREF="#lbAH">BUGS</A><DD>
562</DL>
563<HR>
564This document was created by
565<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
566using the manual pages.<BR>
567Time: 21:40:18 GMT, November 11, 2003
568</BODY>
569</HTML>