OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / lib / atosa.3
1 .TH IPSEC_ATOSA 3 "11 June 2001"
2 .\" RCSID $Id: atosa.3,v 1.9 2002/03/22 00:35:29 henry Exp $
3 .SH NAME
4 ipsec atosa, satoa \- convert IPsec Security Association IDs to and from ASCII
5 .SH SYNOPSIS
6 .B "#include <freeswan.h>
7 .sp
8 .B "const char *atosa(const char *src, size_t srclen,"
9 .ti +1c
10 .B "struct sa_id *sa);
11 .br
12 .B "size_t satoa(struct sa_id sa, int format,"
13 .ti +1c
14 .B "char *dst, size_t dstlen);"
15 .sp
16 .B "struct sa_id {"
17 .ti +1c
18 .B "struct in_addr dst;"
19 .ti +1c
20 .B "ipsec_spi_t spi;"
21 .ti +1c
22 .B "int proto;"
23 .br
24 .B "};"
25 .SH DESCRIPTION
26 These functions are obsolete; see
27 .IR ipsec_ttosa (3)
28 for their replacements.
29 .PP
30 .I Atosa
31 converts an ASCII Security Association (SA) specifier into an
32 .B sa_id
33 structure (containing
34 a destination-host address
35 in network byte order,
36 an SPI number in network byte order, and
37 a protocol code).
38 .I Satoa
39 does the reverse conversion, back to an ASCII SA specifier.
40 .PP
41 An SA is specified in ASCII with a mail-like syntax, e.g.
42 .BR esp507@1.2.3.4 .
43 An SA specifier contains
44 a protocol prefix (currently
45 .BR ah ,
46 .BR esp ,
47 or
48 .BR tun ),
49 an unsigned integer SPI number,
50 and an IP address.
51 The SPI number can be decimal or hexadecimal
52 (with
53 .B 0x
54 prefix), as accepted by
55 .IR ipsec_atoul (3).
56 The IP address can be any form accepted by
57 .IR ipsec_atoaddr (3),
58 e.g. dotted-decimal address or DNS name.
59 .PP
60 As a special case, the SA specifier
61 .B %passthrough
62 signifies the special SA used to indicate that packets should be
63 passed through unaltered.
64 (At present, this is a synonym for
65 .BR tun0x0@0.0.0.0 ,
66 but that is subject to change without notice.)
67 This form is known to both
68 .I atosa
69 and
70 .IR satoa ,
71 so the internal form of
72 .B %passthrough
73 is never visible.
74 .PP
75 The
76 .B <freeswan.h>
77 header file supplies the
78 .B sa_id
79 structure, as well as a data type
80 .B ipsec_spi_t
81 which is an unsigned 32-bit integer.
82 (There is no consistency between kernel and user on what such a type
83 is called, hence the header hides the differences.)
84 .PP
85 The protocol code uses the same numbers that IP does.
86 For user convenience, given the difficulty in acquiring the exact set of
87 protocol names used by the kernel,
88 .B <freeswan.h>
89 defines the names
90 .BR SA_ESP ,
91 .BR SA_AH ,
92 and
93 .B SA_IPIP
94 to have the same values as the kernel names
95 .BR IPPROTO_ESP ,
96 .BR IPPROTO_AH ,
97 and
98 .BR IPPROTO_IPIP .
99 .PP
100 The
101 .I srclen
102 parameter of
103 .I atosa
104 specifies the length of the ASCII string pointed to by
105 .IR src ;
106 it is an error for there to be anything else
107 (e.g., a terminating NUL) within that length.
108 As a convenience for cases where an entire NUL-terminated string is
109 to be converted,
110 a
111 .I srclen
112 value of
113 .B 0
114 is taken to mean
115 .BR strlen(src) .
116 .PP
117 The
118 .I dstlen
119 parameter of
120 .I satoa
121 specifies the size of the
122 .I dst
123 parameter;
124 under no circumstances are more than
125 .I dstlen
126 bytes written to
127 .IR dst .
128 A result which will not fit is truncated.
129 .I Dstlen
130 can be zero, in which case
131 .I dst
132 need not be valid and no result is written,
133 but the return value is unaffected;
134 in all other cases, the (possibly truncated) result is NUL-terminated.
135 The
136 .I freeswan.h
137 header file defines a constant,
138 .BR SATOA_BUF ,
139 which is the size of a buffer just large enough for worst-case results.
140 .PP
141 The
142 .I format
143 parameter of
144 .I satoa
145 specifies what format is to be used for the conversion.
146 The value
147 .B 0
148 (not the ASCII character
149 .BR '0' ,
150 but a zero value)
151 specifies a reasonable default
152 (currently
153 lowercase protocol prefix, lowercase hexadecimal SPI, dotted-decimal address).
154 The value
155 .B d
156 causes the SPI to be generated in decimal instead.
157 .PP
158 .I Atosa
159 returns
160 .B NULL
161 for success and
162 a pointer to a string-literal error message for failure;
163 see DIAGNOSTICS.
164 .I Satoa
165 returns
166 .B 0
167 for a failure, and otherwise
168 always returns the size of buffer which would 
169 be needed to
170 accommodate the full conversion result, including terminating NUL;
171 it is the caller's responsibility to check this against the size of
172 the provided buffer to determine whether truncation has occurred.
173 .SH SEE ALSO
174 ipsec_atoul(3), ipsec_atoaddr(3), inet(3)
175 .SH DIAGNOSTICS
176 Fatal errors in
177 .I atosa
178 are:
179 empty input;
180 input too small to be a legal SA specifier;
181 no
182 .B @
183 in input;
184 unknown protocol prefix;
185 conversion error in
186 .I atoul
187 or
188 .IR atoaddr .
189 .PP
190 Fatal errors in
191 .I satoa
192 are:
193 unknown format; unknown protocol code.
194 .SH HISTORY
195 Written for the FreeS/WAN project by Henry Spencer.
196 .SH BUGS
197 The
198 .B tun
199 protocol code is a FreeS/WANism which may eventually disappear.
200 .PP
201 The restriction of ASCII-to-binary error reports to literal strings
202 (so that callers don't need to worry about freeing them or copying them)
203 does limit the precision of error reporting.
204 .PP
205 The ASCII-to-binary error-reporting convention lends itself
206 to slightly obscure code,
207 because many readers will not think of NULL as signifying success.
208 A good way to make it clearer is to write something like:
209 .PP
210 .RS
211 .nf
212 .B "const char *error;"
213 .sp
214 .B "error = atoaddr( /* ... */ );"
215 .B "if (error != NULL) {"
216 .B "        /* something went wrong */"
217 .fi
218 .RE